akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int l[2000][2000], r[2000][2000], up[2000][2000], down[2000][2000];
char a[2000][2000];

int main () {
    int h, w, temp = 0, res = 0;
    cin >> h >> w;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j];
    for (int i = 0; i < h; i++) {
        temp = 0;
        for (int j = 0; j < w; j++) l[i][j] = (a[i][j] == '#') ? temp = 0 : ++temp;
    }
    for (int i = 0; i < h; i++) {
        temp = 0;
        for (int j = w-1; j >= 0; j--) r[i][j] = (a[i][j] == '#') ? temp = 0 : ++temp;
    }
    for (int i = 0; i < w; i++) {
        temp = 0;
        for (int j = 0; j < h; j++) up[j][i] = (a[j][i] == '#') ? temp = 0 : ++temp;
    }
    for (int i = 0; i < w; i++) {
        temp = 0;
        for (int j = h-1; j >= 0; j--) down[j][i] = (a[j][i] == '#') ? temp = 0 : ++temp;
    }
    for (int i = 0; i < h; i++) {
        temp = 0;
        for (int j = 0; j < w; j++) if (a[i][j] != '#') res = max(res, l[i][j] + r[i][j] + up[i][j] + down[i][j] - 3);
    }
    cout << res << endl;
    return 0;
}

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

namespace ConsoleApp5
{

    class Program
    {

        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int count = 0;
            int res = 0;
            S = S + "%";
            for(int i=0; ; i++)
            {
                if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
                {
                    count++;
                }
                else
                {
                    if(count > res)
                    {
                        res = count;
                    }
                    count = 0;
                    if(S[i] == '%')
                    {
                        break;
                    }
                }

            }
            Console.WriteLine(res);



        }
    }
}


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

int main(){
    ll n,k,a,b;
    set<ll> set;
    umap<ll,ll> map;
    cin>>n>>k;
    rep(l,n){
        scanf("%lld %lld",&a,&b);
        if(set.count(a)){
            map[a]+=b;
        }else{
            set.insert(a);
            map[a]=b;
        }
    }
    ll hikaku=0,ans;
    for(auto value:set){
        hikaku+=map[value];
        if(k<=hikaku){
            ans=value;
            break;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
	string abc = "XYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string a;
	cin >> a;
	for (int i = 0; i < a.size(); i++) {
		for (int j = 28; j >= 0 ; j--) {
			if (a[i] == abc[j]) {
				cout << abc[j-3];
				break;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1184
import heapq

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

Bri = [[] for _ in range(N+1)]
for a, b in AB:
    Bri[a].append(b)

q = []
ans = 0
for j in range(1, N+1):
    if q:
        if q[0] == j:
            q = []
            ans += 1
    for p in Bri[j]:
        heapq.heappush(q, p)
print(ans)

Measured memory_bytes: 34964
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;
    }
}
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    ll n;
    cin>>n;

    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }

    n/=2;
    ll ans=0;
    ll p5=5;
    while(p5<=n){
        ans+=n/p5;
        p5*=5;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);

	for(int i=0;i < n;i ++)
	{
		cin >> a[i];
	}
	
	sort(a.begin(),a.end());

	int ans = 0;
	for(int i=0;i < n-1;i ++)
	{
		ans += a[i+1] - a[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x, i;
    cin>>x;
    while(1) {
    	ll temp = x++;
    	ll flag = 1;
    	for(i=2; i*i <= temp; i++) {
    		if(temp%i == 0) {
    			flag = 0;
    		}
    	}
    	if(x == 2) {
    		cout<<2<<endl;
    		break;
    	}
    	if(flag) {
    		cout<<temp<<endl;
    		break;
    	}
    }
}

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

int main(){
    int H,W;
  	cin >> H >> W;
	vector<vector<char>> pix(H, vector<char>(W));
  
	for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++)
        	cin >> pix.at(i).at(j);
    }
    for(int i = 0; i < W+2; i++)
		cout << "#";
  	cout << endl;
    for(int i = 0; i < H; i++){
      cout << "#";
      for(int j = 0; j < W; j++)
        	cout << pix.at(i).at(j);
      cout << "#" << endl;
    }
    for(int i = 0; i < W+2; i++)
		cout << "#";
  	cout << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(void){
  int n,m;
  cin >> n >> m;
  int a[n],total = 0;
  rep(i,n){
    cin >> a[i];
    total += a[i];
  }
  sort(a,a+n);

  if(a[n-m]*4*m < total) cout << "No" << endl;
  else{
    cout << "Yes" << 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 n = sc.nextInt();
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		String[] as = a.split("");
		String[] bs = b.split("");
		String[] cs = c.split("");
		int count = 0;
		for(int i=0; i<n; i++) {
			if(as[i].equals(bs[i]) && bs[i].equals(cs[i]) && as[i].equals(cs[i])) {
				continue;
			}else if(!as[i].equals(bs[i]) && !bs[i].equals(cs[i]) && !as[i].equals(cs[i])) {
				count += 2;
			}else {
				count += 1;
			}
		}
		System.out.println(count);
	}
}


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

#define FastRead  ios_base::sync_with_stdio(0);cin.tie(0);
#define endl      "\n"
#define INF       1<<30

typedef long long ll;

ll mark[4][4];

int main()
{
    FastRead

    ll a[4][4];

    bool flag=true;

    map<ll,pair<int,int>>mp;

    for(ll i=1; i<=3; i++)
    {
        for(ll j=1; j<=3; j++)
        {
            cin>>a[i][j];
            mp[a[i][j]]= {i,j};
        }
    }

    ll n;

    cin>>n;

    for(ll i=0; i<n; i++)
    {
        ll temp;
        cin>>temp;
        if(mp[temp].first and mp[temp].second)
            mark[mp[temp].first][mp[temp].second]=1;
    }


    for(ll i=1; i<=3; i++)
    {
        if(mark[i][1]==1 and mark[i][2]==1 and mark[i][3]==1)
        {
            cout<<"Yes";
            return 0;
        }
    }

    for(ll i=1; i<=3; i++)
    {
        if(mark[1][i]==1 and mark[2][i]==1 and mark[3][i]==1)
        {
            cout<<"Yes";
            return 0;
        }
    }

    if(mark[1][1]==1 and mark[2][2]==1 and mark[3][3]==1)
    {
        cout<<"Yes";
        return 0;
    }

    if(mark[1][3] and mark[2][2] and mark[3][1])
    {
        cout<<"Yes";
        return 0;
    }

    cout<<"No";

}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
    int x=0,mx=0;
    int n;
    scanf("%d",&n);
    getchar();//读取换行符
    for(int i=1;i<=n;i++){
        if(getchar()=='I') x++;
        else x--;
        if(mx<x) mx=x;
    }
    printf("%d",mx);
    return 0;
}



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

const int MAX = 1000100;
const int INF = 1<<29;

int main() {
    vector<int> dp(MAX, INF), odddp(MAX, INF);
    dp[0] = odddp[0] = 0;
    for (int i = 1;; ++i) {
        int num = i * (i+1) * (i+2) / 6;
        if (num >= MAX) break;
        for (int j = num; j < MAX; ++j) {
            dp[j] = min(dp[j], dp[j-num]+1);
            if (num & 1) odddp[j] = min(odddp[j], odddp[j-num]+1);
        }
    }
    int n;
    while (cin >> n) {
        if (n == 0) break;
        cout << dp[n] << " " << odddp[n] << endl;
    }
}


Measured memory_bytes: 10484
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;cin >> s;
  int n = s.size();
  int ans = n;
  for(int i=0;i<n-1;i++){
    if (s[i] != s[i+1]) {
      ans = min(ans,max(i+1,n-i-1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
def main():
    info = input()
    info = info.split()
    
    number = info[0]
    add_cim = int(info[1])
    
    replace_number = "".join(list(reversed(number)))
    check_number = 0
    for num in range(len(replace_number)):
        check_number = check_number + int(replace_number[num])*(10**num)
    
    result_num = ""
    while True:
        if check_number < add_cim:
            result_num = result_num + str(check_number % add_cim) 
            break
        else:
            result_num = result_num + str(check_number % add_cim)
            check_number = int(check_number / add_cim)
    
    print(len(str(result_num)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
class BinarySearchTree:
    def __init__(self):
        self.root = None
    def show_keys(self):
        in_order_from(self.root)
        print('')
        pre_order_from(self.root)
        print('')
    def insert(self, key):
        node = Node(key)
        insert(self, node)
    def find(self, key):
        if find_from(self.root, key):
            print('yes')
        else:
            print('no')
    def delete_key(self, key):
        node = find_from(self.root, key)
        delete_node(self, node)

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(T, z):
    y = None
    x = T.root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y == None:
        T.root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def delete_node(T, node):
    if node.left and node.right:
        x = node.right
        while x.left:
            x = x.left
        node.key = x.key
        delete_node(T, x)
    elif node.left or node.right:
        child = node.left or node.right
        if node is T.root:
            T.root = child
            child.parent = None
        else:
            if node.parent.left is node:
                node.parent.left = child
                child.parent = node.parent
            else:
                node.parent.right = child
                child.parent = node.parent
    else:
        if node.parent.left is node:
            node.parent.left = None
        else:
            node.parent.right = None

def in_order_from(node):
    if node:
        in_order_from(node.left)
        print(' {0}'.format(node.key), end = '')
        in_order_from(node.right)

def pre_order_from(node):
    if node:
        print(' {0}'.format(node.key), end = '')
        pre_order_from(node.left)
        pre_order_from(node.right)

def find_from(node, k):
    while node:
        if node.key == k:
            return node
        if k < node.key:
            node = node.left
        else:
            node = node.right


import sys

t = BinarySearchTree()

m = sys.stdin.readline()

for i in sys.stdin.readlines():
    if i[0] == 'i':
        t.insert(int(i[7:]))
    elif i[0] == 'f':
        t.find(int(i[5:]))
    elif i[0] == 'd':
        t.delete_key(int(i[7:]))
    else:
        t.show_keys()

Measured memory_bytes: 162052
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <random>
#include <iomanip>
#include <limits>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 998244353;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m,a,b,c,d,ans=0,num,ddx,ddy;

ll  fact[400000];
ll rfact[400000];


ll mpow(ll x, ll y, ll m) {
    x %= m;
    ll result = 1;
    while (y > 0) {
        if (y & 1) result = (result * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return result;
}

unsigned long long int minverse(unsigned long long int x, unsigned long long int m) {
    return mpow(x, m-2, m);
}

void c3_init(ll m){
    fact[0]  = rfact[0] = 1;
    for(ll xxxx=1; xxxx<400000; xxxx++){
        fact[xxxx] = (fact[xxxx-1]*xxxx)%m;
        rfact[xxxx] = minverse(fact[xxxx],m);
    }
}
ll c3(ll n, ll abc, ll m){
    return (((fact[n] * rfact[abc])%m) * rfact[n-abc])%m;
}

ll gcd(ll m,ll n){
	if(m==n || n==0){
		return m;
	}else {
		if(m%n>n/2){
			gcd(n,abs(m%n-n));
		}else{
			gcd(n,m%n);
		}
	}
}

int main(){
	cin>>n>>a>>b>>k;
	if(a<b){
		swap(a,b);
	}
	if(k%gcd(a,b)!=0){
		p(0);
		return 0;
	}
	c3_init(mod);
	for(i=0;i<=n;i++){
		if(i>n)break;
		if((k-a*i)%b==0 && k-a*i>=0 && (k-a*i)/b<=n){
			
			ans += ((c3(n,i,mod)%mod)*(c3(n,(k-a*i)/b,mod)%mod))%mod;
			ans = ans%mod;
		}
	}
				//kasa,i-kasa,(k-a*i)/b-kasa
	p(ans);
	return 0;
}

Measured memory_bytes: 11136
a,b=list(map(int,input().split()))
l=list(map(int,input().split()))
maxll=0
for i in range(b-1):
    if maxll<l[i+1]-l[i]:
        maxll=l[i+1]-l[i]
if maxll<l[0]+a-l[b-1]:
    maxll=l[0]+a-l[b-1]
print(a-maxll)


Measured memory_bytes: 77388
def solve():
    N, X = map(int, input().split())
    L = [int(i) for i in input().split()]
    bound = 0
    count = 1
    for Li in L:
        bound += Li
        if bound <= X:
            count += 1
        else:
            break
    print(count)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N;


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

  cin >> N;

  REP(h, 1, 3501) REP(w, 1, 3501) {
    ll x = (ll)h*w*N;
    ll y = 4*h*w - h*N - w*N;
    if (y <= 0 || x%y != 0) continue;
    cout << h << " " << x/y << " " << w << endl;
    return 0;
  }

  return 0;
}


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


void solve(long long A, long long B){
    int s=0;
    (A-2*B >0) ? s=A-2*B: s=0;
    cout<<s<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::cout<<std::fixed<<std::setprecision(10);//誤差小数10桁まで
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){
	long long int a, b, r, x, temp;
	while (scanf("%lld%lld", &a, &b) != EOF){
		x = a*b;
		if (b > a){
			temp = a;
			a = b;
			b = temp;
		}
		r = a%b;
		while (r != 0){
			a = b;
			b = r;
			r = a%b;
		}
		printf("%lld %lld\n", b, x/b);
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
 
int main(){
    int j,s_length = 0;
    char s[101],p[101];
    scanf("%s",s);
    scanf("%s",p);
 
    for(int i = 0; s[i] != '\0';i++) s_length++;
 
    for(int left = 0;s[left] != '\0';left++){
        for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
        if(p[j] == '\0'){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2700
#include <stdio.h>
int main ( ) {
	int flag = 0;
	double n , max = 0 , min;
	while ( scanf("%lf",&n) != EOF ) {
		if ( max < n ) max = n;
		else if ( flag == 0 ) {
			min = n;
			flag++;
		}
		if ( min > n ) min = n;
	}
	printf("%.1f\n",max-min);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2e5 + 20;
int a[MAXN], b[MAXN];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	rep (i, 0, n - 1) cin >> a[i];
	while (m--) {
		fill(b, b + n, 0);
		rep (i, 0, n - 1) {
			++b[max(0, i - a[i])];
			--b[min(n, i + a[i] + 1)];
		}
		rep (i, 1, n) b[i] += b[i - 1];
		rep (i, 0, n - 1) a[i] = b[i];
		bool flag = true;
		rep (i, 0, n - 1) {
			flag &= a[i] == n;
		}
		if (flag) break;
	}
	rep (i, 0, n - 1) {
		cout << a[i] << ' ';
	}	cout << endl;
	return 0;
}

Measured memory_bytes: 5196
var n,ans,x,fx:qword;
var i:longint;
function lcm(a,b:qword):qword;
var t,ans:qword;
begin
  if a<b then begin t:=a;a:=b;b:=t;end;
  ans:=a;
  while ans mod b>0 do inc(ans,a);
  exit(ans);
end;
begin
  read(n);read(fx);if n=1 then begin writeln(fx);exit;end;
  for i:=2 to n do
  begin
    read(x);if i=2 then ans:=lcm(fx,x) else ans:=lcm(ans,x);
  end;
  writeln(ans);
end.

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int n, m;
	scanf("%d %d", &n, &m);

	int M[m];
	for (int i = 0; i < m; ++i) {
		scanf("%d", &M[i]);
	}

	int T[n + 1];
	for (int i = 1; i <= n; ++i)
		T[i] = 50000;

	T[0] = 0;
	for (int i = 0; i < m; ++i) {
		for (int j = M[i]; j <= n; ++j) {
			T[j] = min(T[j], T[j - M[i]] + 1);
		}
	}

	cout << T[n] << endl;

	return 0;
}

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

const double pi=acos(-1);
typedef long long ll;
const int maxn=1e6+10;
ll f[200050];
int main()
{
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll h;
    cin >> h;
    ll ans=1;
    while(h){
        h/=2;
        ans*=2;
    }
    ans=ans-1;
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    val n = in.next.head
    val tree = in.map(_.drop(2).map(_ - 1)).toList
    val res = List.fill(n)(Array.fill(2)(0))
    def solve(start: Int, id: Int): Int =
        if (res(id)(0) != 0) {
            start - 1
        } else {
            res(id)(0) = start
            res(id)(1) = tree(id).foldLeft(start)((_d, _id) => solve(_d + 1, _id)) + 1
            res(id)(1)
        }

    var d = 1
    for (i <- 0 until n if res(i)(0) == 0) {
        d = solve(d, i) + 1
    }
    res.zipWithIndex.foreach{case (x, i) => println(i + 1 + " " + x.mkString(" "))}
}

Measured memory_bytes: 44296
n = int(input())
a = list(map(int,input().split()))
x = 0
cnt = 1

for i in range(1,n):
    temp = a[i] - a[i-1]
    if x == 0:
        x = temp
    elif x * temp<0:
        cnt += 1
        x =0      

print(cnt)

Measured memory_bytes: 62704
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int mojisu=sc.nextInt();
		String[] muki=new String[mojisu];
		String moji=sc.next();
		for(int i=0; i<mojisu; i++) {
			muki[i]=moji.charAt(i)+"";
		}

		int[] wlist=new int[mojisu];
		int[] elist=new int[mojisu];

		for(int i=0; i<mojisu; i++) {
			if(muki[i].equals("W")) {		//→
				wlist[i]=wlist[Math.max(0, i-1)]+1;
				elist[i]=elist[Math.max(0, i-1)];
			}

			else if(muki[i].equals("E")) {	//←
				elist[i]=elist[Math.max(0, i-1)]+1;
				wlist[i]=wlist[Math.max(0, i-1)];
			}
		}
		for(int i=0; i<mojisu; i++) {
			//System.out.println("elist["+i+"]="+elist[i]+" wlist["+i+"]="+wlist[i]);
		}
		int min=114514810;
		int cnt=0;

		cnt=elist[mojisu-1]-elist[1];
		if(cnt<min) { min=cnt;}
		//System.out.println(min);
		for(int j=1; j<mojisu-1; j++) {
			cnt=wlist[Math.max(0, j-1)]+(elist[mojisu-1]-elist[j]);
			//System.out.println(cnt);
			if(cnt<min) {
				min=cnt;
			}
		}
		cnt=wlist[mojisu-2];
		if(cnt<min) { min=cnt;}

		System.out.println(min);


		/*int cnt=0;
		int min=114514810;
		//リーダーよりも前ならW→E　　後ろなら　E→Wにする
		for(int i=0; i<mojisu; i++) {
			cnt=0;
			for(int j=0; j<mojisu; j++) {
				if(j<i) {
					if(muki[j].equals("W")) {
						cnt++;
					}
				}
				else if(j>i) {
					if(muki[j].equals("E")) {
						cnt++;
					}
				}
			}
			if(min>cnt) {
				min=cnt;
			}
		}
		System.out.println(min);*/
	}
}//乾燥できず　5くらいで　TLEをもらう

Measured memory_bytes: 56424
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#define maxn 1005
using namespace std;
typedef long long  LL;
map<string,int>mp;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
        map<string,int>::iterator it;
        int sum=0;
        for(it=mp.begin();it!=mp.end();++it)
        {
            int t=it->second;
            if(t%2==1)
                sum++;
        }
        cout<<sum<<endl;

}


Measured memory_bytes: 8064
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }



//---------- 1000000007 ----------
const int MOD = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(MOD - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint m_comb(mint n, mint r)
{
	int i;
	mint p = 1;
	for (i = 1; i <= r.x; i++)
	{
		p *= n - i + 1;
		p /= i;
	}
	return p;
}
mint m_comb_with_rep(mint n, mint r)
{
	return m_comb(n + r - 1, r);
}
mint m_perm(mint n, mint r)
{
	mint a = 1;
	for (int i = n.x; i > n.x - r.x; i--)
	{
		a *= i;
	}
	return a;
}



signed main()
{
	string L;
	cin >> L;

	mint a = 1;
	mint b = 2;
	for (int i = 1; i < L.length(); i++)
	{
		mint aa, bb;
		if (L[i] == '1')
		{
			aa = a + a + a + b;
			bb = b + b;
		}
		else
		{
			aa = a + a + a;
			bb = b;
		}
		a = aa;
		b = bb;
	}
	cout << (a + b) << endl;
}



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

/**
 *    author:  knshnb
 *    created: Thu Mar 19 19:46:18 JST 2020
 **/

const vector<pair<int, int>> DIRECTIONS = {
    {1, 0}, {0, 1},  {-1, 0},  {0, -1},  // 4方向
};

signed main() {
    Int H, W;
    cin >> H >> W;
    vector<string> t(H);
    REP(i, H) cin >> t[i];
    REP(i, H) {
        REP(j, W) {
            if (t[i][j] != '#') continue;
            bool ok = false;
            for (auto& dir : DIRECTIONS) {
                Int i2 = i + dir.first;
                Int j2 = j + dir.second;
                if (0 <= i2 && i2 < H && 0 <= j2 && j2 < W && t[i2][j2] == '#') {
                    ok = true;
                }
            }
            if (!ok) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
import random
import time

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(d):
    tl.append(random.randint(1,26))
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]

def decr(tl,cl):
    dec=0
    for i in range(26):
        last=[a for a, x in enumerate(tl) if x==i+1]
        if last==list():
            dec+=(d*(d+1)/2)*cl[i]
        else:
            for v in range(len(last)):
                if v!=len(last)-1:    
                    dec+=cl[i]*(last[v+1]-last[v]-1)*(last[v+1]-last[v])/2
                else:
                    dec+=cl[i]*(d-last[v]-1)*(d-last[v])/2
            dec+=cl[i]*(last[0])*(last[0]+1)/2
    return(int(dec))

oldscore=sat
oldans=oldscore-decr(tl,cl)
oldtl=[int(x) for x in tl]
t2=time.time()
while t2-t1<1.85:
    if round(t2)%2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        tl[d2-1]=q2
        tl[d1-1]=q1
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        tl[da-1]=q
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
    r=0
    if newans<oldans:
        if 2.7**((newans-oldans)/(1.85-(t2-t1)))<random.random():
            r=1
    if r==1:
        tl=[int(x) for x in oldtl]
    else:
        oldans=newans
        oldtl=[int(x) for x in tl]
        oldscore=newscore
    t2=time.time()
for i in range(d):
    print(tl[i])
        

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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n, t, a;
    cin >> n >> t >> a;
    double min_diff = 100000;
    int ans = 0;
    for (size_t i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        double temp = t - h * 0.006;
        if (abs(a - temp) < min_diff)
        {
            ans = i;
            min_diff = abs(a - temp);
        }
    }
    cout << ans + 1 << endl;

    return 0;
}

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

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

    int N, X;
    cin >> N >> X;
    int m[N];
    for(int i = 0; i < N; ++i){
        cin >> m[i];
    }
    sort(m, m + N);

    int counter = 0;
    for(int i = 0; i < N; ++i){
        if(X >= m[i]){
            X -= m[i];
            ++counter;
        }
    }

    while(X >= m[0]){
        X -= m[0];
        ++counter;
    }

    cout << counter << "\n";

    return 0;
}


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

int main(){
  ll n,m; cin >> n >> m;
  vector<ll> h(n); rep(i,n) cin >> h[i];

  vector<bool> flag(n,true);

  rep(i,m) {
    int a,b; cin >> a >> b;
    a--;
    b--;

    if(h[a] > h[b]) flag[b] = false;
    else if(h[a] < h[b]) flag[a] = false;
    else{
      flag[a] = false;
      flag[b] = false;
    }
  }

  ll count = 0;
  

  rep(i,n) {
    if(flag[i]){
      count++;
    }
  }

  cout << count << endl;
}



Measured memory_bytes: 4052
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	ll N;

	cin >> N;

	vector<ll> H(N);

	fi(N) {
		cin >> H[i];
	}

	bool f = true;

	fi(N - 1) {
		if (H[i+1] >= H[i]+1) {
			H[i+1]--;
		}
	}

	fi(N - 1) {
		if (H[i] > H[i + 1]) {
			f = false;
		}
	}

	if (f == true) {
		ce("Yes")
	}
	else {
		ce("No")
	}

}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back
#define EPS 1e-9

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);


const int MAX_n = 50;
int n,l[MAX_n];
int k;

signed main(){

    cin >> n;
    cin >> k;
    priority_queue<int> que;
    for(int i = 0;i < n;i++){
        cin >> l[i];
        que.push(l[i]);
    }

    int ans=0;
    for(int i = 0;i < k;i++){
        ans+=que.top();que.pop();
    }

    cout<< ans<< endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e17;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i,n+1) cin >> a[i];
    vector<ll> l(n+1, 1), r(n+1, INF);
    l[n] = a[n];
    r[n] = a[n];
    for(int i = n; i >= 0; --i){
        chmax(l[i], 1LL);
        chmin(r[i], (i <= 40 ? (1LL << i) : INF));
        if(l[i] > r[i]){
            cout << -1 << endl;
            return 0;
        }
        if(i > 0){
            chmax(l[i-1], (l[i]+1)/2 + a[i-1]);
            chmin(r[i-1], r[i] + a[i-1]);
        }
    }
    if(l[0] > 1 || r[0] < 1){
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0, num = 1;
    rep(i,n+1){
        if(l[i] > num || num > r[i]){
            cout << -1 << endl;
            return 0;
        }
        ans += num;
        num -= a[i];
        if(num < 0){
            cout << -1 << endl;
            return 0;
        }
        if(i < n){
            if(num*2 < l[i+1] || num > r[i+1]){
                cout << -1 << endl;
                return 0;
            }
            num = min(num*2, r[i+1]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,W; ll wt[N],val[N]; map< pair<ll,ll>,ll> mp;
ll maxval(ll i,ll w){
	if(i==n+1){
		return 0;
	}
	if(mp.find({i,w})!=mp.end()){
		return mp[{i,w}];
	}

	if(wt[i]<=w){
		ll a,b;
		a=maxval(i+1,w-wt[i])+val[i];
		b=maxval(i+1,w);
		return mp[{i,w}]=max(a,b);
	}
	else return mp[{i,w}]=maxval(i+1,w);
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n>>W;
	for(i=1;i<=n;i++){
		cin>>wt[i]>>val[i];
	}
	
	ll an=maxval(1,W);
	cout<<an;
	return 0;
}

Measured memory_bytes: 8320
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n;
int a[200005];
bool flag = true;

int main() {

	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}

	sort(a, a + n);

	rep(i, n - 1) {
		if (a[i] == a[i + 1]) flag = false;
	}

	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 1024
sankaNum, scoreMax, ansCnt = map(int, input().split())

score = [scoreMax-ansCnt]*sankaNum

for _ in range(ansCnt):
    score[int(input()) - 1] +=  1

for m in range(sankaNum):

    if  score[m] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 6664
import collections
from collections import Counter
n = int(input())
s = []
ans = []
for i in range(n):
    S = input()
    s.append(S)
count = collections.Counter(s)
values, counts = zip(*count.most_common())
counts2 = list(counts).sort(reverse = True)
ans.append(values[0])
for j in range(1,len(counts)):
    if counts[0] == counts[j]:
        ans.append(values[j])
    else:
        break
ans.sort()
for k in ans:
    print(k)

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

typedef long long ll;
typedef unsigned long long ull;
template<typename T> T readIn() {
	T x(0), f(1);
	char ch = getchar();
	while (ch < '0' || ch >'9') {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
int A, B, C, D, E, F;

int main()
{
	A = readIn<int>(), B = readIn<int>(), C = readIn<int>(), D = readIn<int>(), E = readIn<int>(), F = readIn<int>();
	int ans1 = 0, ans2 = 0; double temp = 0.0;
	for (int i = 0; A * 100 * i <= F; ++i) {
		for (int j = 0; 100 * B * j + 100 * A * i <= F; ++j) {
			if (i + j == 0) continue;
			int sum = 100 * A * i + 100 * B * j;
			int lim = min(sum / 100 * E, F - sum);
			for (int k = 0; k * C <= lim; ++k) {
				int l = (lim - k * C) / D;
				int sugar = l * D + k * C;
				if ((double)sugar / sum > temp) {
					temp = (double)sugar / sum;
					ans1 = sum + sugar, ans2 = sugar;				}
			}
		}
	}
	if (temp == 0) printf("%d %d\n", A * 100, 0);
	else printf("%d %d\n", ans1, ans2);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> a(100000), b(100000);
    for (int i = 0; i < n; i++)
    {
        int s;
        cin >> s;
        if (i % 2 == 0)
        {
            a[s - 1].first++;
            a[s - 1].second = s - 1;
        }
        if (i % 2 != 0)
        {
            b[s - 1].first++;
            b[s - 1].second = s - 1;
        }
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    if (a[0].second == b[0].second)
    {
        if (a[0].first + b[1].first < a[1].first + b[0].first)
            cout << (n - a[1].first - b[0].first) << endl;
        else
        {
            cout << (n - a[0].first - b[1].first) << endl;
        }
    }
    else
    {
        cout << n - a[0].first - b[0].first << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

struct UnionFind{
    vector<int> d;
    UnionFind(int n=0):d(n,-1){}
    int root(int x){
        if(d[x]<0)return x;
        return d[x]=root(d[x]);
    }
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return root(x)==root(y);}
    int usize(int x){return -d[root(x)];}
};

int main(){
    int h,w;cin >>h>>w;
    int n=h*w;
    UnionFind uni(n);
    vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >>s[i];
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(i-1>=0 and s[i][j]!=s[i-1][j]){
                uni.unite(w*i+j,w*(i-1)+j);
            }
            if(j>=1 and s[i][j]!=s[i][j-1]){
                uni.unite(w*i+j,w*i+(j-1));
            }
        }
    }
    V black(n,0);
    for (int i = 0; i < n; ++i) {
        if(s[i/w][i%w]=='#')black[uni.root(i)]++;
    }
    ll ans=0;
    vector<bool>used(n,false);
    for (int i = 0; i < n; ++i) {
        if(used[uni.root(i)])continue;
        ll u=uni.usize(i);
        ll b=black[uni.root(i)];
        ans+=(b*(u-b));
        used[uni.root(i)]=true;
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn = 100000 + 100, Mod = 1e9 + 7;
int N;
LL A, B;
LL S[Maxn];
int Sum1[Maxn], Sum2[Maxn];
int Cnt1, Cnt2, Vis1[Maxn * 10], Vis2[Maxn * 10];

inline int lowbit (int x) {return x & (-x);}

inline void Update1 (int x, LL d)
{
	++x;
	while (x <= (N + 1))
	{
		(Sum1[x] += d) %= Mod;
		Vis1[++Cnt1] = x;
		x += lowbit(x);
	}
}

inline void Update2 (int x, int d)
{
	++x;
	while (x <= (N + 1))
	{
		(Sum2[x] += d) %= Mod;
		Vis2[++Cnt2] = x;
		x += lowbit(x);
	}
}

inline int Query1 (int x)
{
	int Ans = 0;
	++x;
	while (x)
	{
		(Ans += Sum1[x]) %= Mod;
		x -= lowbit(x);
	}
	return Ans;
}

inline int Query2 (int x)
{
	int Ans = 0;
	++x;
	while (x)
	{
		(Ans += Sum2[x]) %= Mod;
		x -= lowbit(x);
	}
	return Ans;
}

int main()
{
#ifdef hk_cnyali
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
	scanf("%d%lld%lld", &N, &A, &B);
	for (int i = 1; i <= N; ++i) scanf("%lld", &S[i]);
	S[0] = -0x3f3f3f3f3f3f3f3f;
	Update1(0, 1);
	Update2(0, 1);
	for (int i = 1; i < N; ++i)
	{
		int l = 0, r = i, Ans1 = 0, Ans2 = 0;
		while (l <= r)
		{
			int mid = (l + r) >> 1;
			if (S[mid] <= S[i + 1] - B) l = mid + 1, Ans1 = mid;
			else r = mid - 1;
		}
		l = 0, r = i;
		while (l <= r)
		{
			int mid = (l + r) >> 1;
			if (S[mid] <= S[i + 1] - A) l = mid + 1, Ans2 = mid;
			else r = mid - 1;
		}
		//cout<<i + 1<<" "<<Ans1<<" "<<Ans2<<endl;
		int SUM1 = Query1(Ans1);
		int SUM2 = Query2(Ans2);
		if (S[i + 1] - S[i] < A)
			while (Cnt1)
				Sum1[Vis1[Cnt1--]] = 0;
			//memset(Sum1, 0, sizeof(Sum1));
		if (S[i + 1] - S[i] < B)
			while (Cnt2)
				Sum2[Vis2[Cnt2--]] = 0;
			//memset(Sum2, 0, sizeof(Sum2));
		Update2(i, SUM1);
		Update1(i, SUM2);
		//Ans += Query1(i + 1) + Query2(i + 1);
	}
	printf("%d\n", (Query1(N) + Query2(N)) % Mod);
	return 0;
}
/*

#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000 + 10;
int N, A, B;
int S[Maxn];
int Dp1[Maxn][Maxn], Dp2[Maxn][Maxn];
int main()
{
#ifdef hk_cnyali
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
	scanf("%d%d%d", &N, &A, &B);
	for (int i = 1; i <= N; ++i) scanf("%d", &S[i]);
	S[0] = -0x3f3f3f3f3f;
	Dp1[1][0] = 1;
	Dp2[1][0] = 1;
	for (int i = 1; i < N; ++i)
	{
		if (S[i + 1] - S[i] >= A)
			for (int j = 0; j <= i; ++j)
				Dp1[i + 1][j] += Dp1[i][j];
		if (S[i + 1] - S[i] >= B)
			for (int j = 0; j <= i; ++j)
				Dp2[i + 1][j] += Dp2[i][j];
		for (int j = 0; j <= i; ++j)
			if (S[i + 1] - S[j] >= B)
				Dp2[i + 1][i] += Dp1[i][j];
		for (int j = 0; j <= i; ++j)
			if (S[i + 1] - S[j] >= A)
				Dp1[i + 1][i] += Dp2[i][j];
	}
	int Ans = 0;
	for (int i = 0; i < N; ++i)
		Ans += Dp1[N][i] + Dp2[N][i];
	cout<<Ans<<endl;
	return 0;
}
*/

Measured memory_bytes: 9600
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<input.length(); i++) {
            if(i % 2 == 0) {
                sb.append(input.charAt(i));
            }
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 27852
from collections import deque
k = int(input())
q=deque([1,2,3,4,5,6,7,8,9])
for i in range(k-1):
    x = q.popleft()
    y = x%10 #1桁目
    if y != 0:
        q.append(10*x+y-1)
    q.append(10*x+y)
    if y != 9:
        q.append(10*x+y+1)
ans = q.popleft()
print(ans)

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		long a =sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		
		if(c-a<0) {
			System.out.println((a-c)+" "+b);
			System.exit(0);
		}
		else if(c-a-b==0) {
			System.out.println(0+" "+0);
			System.exit(0);
		}
		
		c=c-a;
		if(c-b>=0) {
			System.out.println(0+" "+0);
			System.exit(0);
		
		}
		else {
			System.out.println(0+" "+(b-c));
		}
	}

}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a[3];

int main() {
	inc(i, 3) { cin >> a[i]; }
	
	sort(a, a + 3);
	
	cout << a[0] + a[1] + a[2] * 10 << endl;
	
	return 0;
}


Measured memory_bytes: 256