akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    ll n=s.length(),ans=0,ans1=0,i,j,s1=0,s2=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='?')
            s[i]='D';

    }

    for(i=0;i<n;i++)
    cout<<s[i];
    cout<<endl;
}


Measured memory_bytes: 3720
a=[]
b=[]
z=[]
def insertion_sort():
    for i in range(len(a)-1):
        j=i+1
        while i >=0:
            if a[j]<a[i]:
                a[i],a[j]=a[j],a[i]
                i-=1
                j-=1
            else:
                break
                
n, k= map(int, input().split())
p=map(int, input().split())
for i in p:
    a.append(i)
insertion_sort()

for i in range(k):
    z.append(i)
        
for i in z:
    b.append(a[i])

print(sum(b))

Measured memory_bytes: 9256
#include <iostream>

using namespace std;

int main() {
    int n; cin >> n;
    int diffs {0};
    for (int i = 1; i <= n; ++i) {
        int a; cin >> a;
        if (i != a) {
            diffs++;
        }
    }
    if (diffs == 0 || diffs == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

Measured memory_bytes: 3136
a, b = map(int, input().split())                                                                               

ans = 0 
def f(n):
    if n % 2 == 1:
        num_pairs = (n + 1) // 2
        return num_pairs % 2 
    else:
        num_pairs = (n + 1) // 2
        return (num_pairs % 2) ^ n 

print(f(a-1) ^ f(b))

Measured memory_bytes: 2940
#include <iostream>
#define MAXN 100001

using namespace std;

int height[MAXN];

int getCost(int a, int b){
	return abs(height[a]-height[b]);
}

int main(){

	int stones;
	cin >> stones;

	for (int s=0;s<stones;s++){
		cin >> height[s];
	}

	int dp[stones];
	dp[0]=0;
	dp[1]=getCost(1,0);

	for (int s=2;s<stones;s++){
		
		dp[s] = min(getCost(s,s-1) + dp[s-1], getCost(s,s-2) + dp[s-2]);
	}

	cout << dp[stones-1] << endl;

	return 0;
}

Measured memory_bytes: 4324
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort()
sw = 0
for i in range(len(A_list)-1):
  if A_list[i] == A_list[i+1]:
    sw = 1
    break
if sw == 0:
  print('YES')
else:
  print('NO')




Measured memory_bytes: 26676
# fall 7, stand 8...
# !/ankit_SM/bin/env python

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    tinn=1; #tinn=int(input())
    for tin in range(tinn):
        a=list(map(int,input().split()))
        print(a.index(0)+1)



# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
    main()

Measured memory_bytes: 65440
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

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

    priority_queue<int> q;
    rep(i, n)
    {
        int a;
        cin >> a;
        q.push(a);
    }

    int ans = 0;
    while (!q.empty())
    {
        int tmp = q.top();
        int count = 0;
        while ((!q.empty()) && q.top() == tmp)
        {
            q.pop();
            count++;
        }
        if (tmp <= count)
        {
            ans += count - tmp;
        }
        else
        {
            ans += count;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 892
N = int(input())
a = list(map(int,input().split()))
tmp = []
for i in range(N):
    if a[i]%2 == 0:
        tmp.append(a[i])
if tmp == []:
    print(0)
else:
    ans = 0
    for i in range(len(tmp)):
        num = tmp[i]
        count = 0
        while num%2 == 0:
            num = num/2
            count += 1
        ans += count
    print(ans)

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

int main(){
  int a[3];
  int tmp;
  cin >>a[0]>>a[1]>>a[2];
    for (int i=0; i<2; ++i) {
    for (int j=i+1; j<3; ++j) {
      if (a[i] > a[j]) {
        tmp =  a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  cout <<a[2]*10+a[1]+a[0]<<endl;
  return 0;
}

  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 29; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int& a, int b) { if (a < b) { a = b; return true; } else return false; }

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

	if ((a == b || b == c || a == c) && !(a == b && b == c)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define MOD 1000000007
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

template <class X>
class SegmentTree {
    int n;
    vector<X> dat;
    X identity;

    X query_sub(int a, int b, int i, int l, int r) {
        if (r <= a || b <= l) return identity;
        if (a <= l && r <= b)
            return dat[i];
        else {
            X vl = query_sub(a, b, i * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, i * 2 + 2, (l + r) / 2, r);
            return op(vl, vr);
        }
    }

    X get_identity(){
        return 0;
    }
    X op(X x, X y){
        return max(x, y);
    }
public:
    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;

        identity = get_identity();
        dat = vector<X>(2 * n - 1, identity);

    }
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // [a, b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X at(int i) { return dat[i + n - 1]; }
};

int main(){
    int N;
    cin >> N;
    vector<long long> h(N), a(N);
    REP(i, N) cin >> h[i];
    REP(i, N) cin >> a[i];

    SegmentTree<long long> st(N+1);
    for(int i=0; i<N; i++){
        long long mx = st.query(0, h[i]);
        st.update(h[i], mx+a[i]);
    }
    cout << st.query(0, N+1) << endl;
    return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int H,W;
    cin >> H >> W;
    int sy,sx;
    cin >> sy >> sx;
    int gy,gx;
    cin >> gy >> gx;
    sy--;
    sx--;
    gy--;
    gx--;
    char s[H][W];
    REP(i,H){
        REP(j,W){
            cin >> s[i][j];
        }
    }

    int dist[H][W];
    REP(i,H){
        REP(j,W){
            dist[i][j] = H*W*2;
        }
    }
    deque<pair<int,int>> que;
    int dy[] = {-1,0,1,0};
    int dx[] = {0,-1,0,1};

    dist[sy][sx] = 0;
    que.push_back({sy,sx});

    while(!que.empty()){
        auto p = que.front();
        que.pop_front();

        int y = p.first,x = p.second;

        for(int dir=0; dir<4; dir++){
            int ny = y + dy[dir],nx = x + dx[dir];

            if(ny < 0 || nx < 0 || ny >= H || nx >= W || '#' == s[ny][nx])continue;
            if(chmin(dist[ny][nx],dist[y][x]))que.push_front({ny,nx});
        }
        for(int yy=-2; yy<3; yy++){
            for(int xx=-2; xx<3; xx++){
                int ny = y + yy,nx = x + xx;

                if(ny < 0 || nx < 0 || ny >= H || nx >= W || '#' == s[ny][nx])continue;
                if(chmin(dist[ny][nx],dist[y][x]+1))que.push_back({ny,nx});
            }
        }
    }
    if(dist[gy][gx] == H*W*2){
        cout << -1 << endl;
    }else{
        cout << dist[gy][gx] << endl;
    }
}

Measured memory_bytes: 8492
n_str = input()
n = int(n_str)
n_length = len(n_str)
sum1 = 0
for i in range(n_length):
    n2 = int(n_str[i])
    sum1 = sum1 + n2

if n % sum1 == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

void solve()
{
	int a, b;
	bool init = true;
	while(cin >> a >> b, a || b)
	{
		if(!init)
		{
			cout << endl;
		}
		init = false;
		bool ok = false;
		for(int i = a; i <= b; ++i)
		{
			if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
			{
				cout << i << endl;
				ok = true;
			}
		}

		if(!ok)
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
N=int(input())
S=[]
for _ in range(N):
  S.append(input())
  
import collections

c=collections.Counter(S)
vl=list(c.values())
# 最大要素数
mv=max(vl) 

ans=[]
cc=list(c.items()) # 辞書を[key, value]のリストにする
cc.sort(key=lambda x:x[1], reverse=True) # valueで降順ソート
# 辞書リスト内のkey, valueを調べる
for k, v in cc:
  if v==mv: # valueが要素数最大のやつ
    ans.append(k)
  else:
    break
ans.sort()
[print(a) for a in ans]

Measured memory_bytes: 50224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define int long long

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

struct UnionFind {
    vector<int> par;
    UnionFind(int n) {
        par.resize(n, -1);
    }
    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (same(x, y)) return;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -par[find(x)];
    }
};

int N, M;
int A[100005], B[100005];
vector<pi> G;

signed main() {
    cin >> N >> M;
    REP(i, M) {
        cin >> A[i], cin >> B[i];
        A[i]--; B[i]--;
        G.pb(mp(A[i], B[i]));
    }
    UnionFind uf(N);

    vi ans;
    int now = N*(N-1)/2;
    REP(i, M) {
        ans.pb(now);
        auto e = G[M-1-i];
        int u = e.first, v = e.second;
        if (uf.same(u, v)) continue;

        now -= uf.size(u) * uf.size(v);
        uf.unite(u, v);
    }
    reverse(ans.begin(), ans.end());
    REP(i, M) cout << ans[i] << endl;

    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

const ll mod = 1000000007;

int main(void)
{
	ll x;
	cin >> x;
	ll d = x * 100;
	if (d % 108 == 0) {
		cout << d / 108 << endl;
		return 0;
	}
	ll s = (d / 108) + 1;
	if (s * 108 / 100 != x) {
		cout << ":(" << endl;
		return 0;
	}
	cout << s << endl;
	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int sum = a + b + c ;
  int average = sum / 2;
  
  if ( sum % 2 == 1 ){
    cout << "No";
  }
  else{
    if ( (average == a || average == b) || average == c ){
      cout << "Yes" ;
    }
    else {
      cout << "No" ;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,i,n,c=0;
	char s[20];

	scanf("%d%d%s",&a,&b,s);

	n=strlen(s);
	for(i=0;i<n;i++)
		if(s[i]=='-')
			c++;
	if(s[a]!='-'||c!=1){
		printf("No");
		return 0;
	}
	printf("Yes");
	return 0;
}

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

int main () {
	int n1,n2,n3,a=0,b=0;
	while (scanf("%d,%d,%d",&n1,&n2,&n3)!=EOF) {
		if((n1*n1+n2*n2)==(n3*n3))a++;
		else if(n1==n2)b++;
	}
	printf("%d\n%d\n",a,b);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(S[i] == T[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 
char c[20];
int main()
{
	int N;
	cin>>N;
	int ac=0,wa=0,tle=0,re=0;
	while(N--)
	{
		scanf("%s",c);
		if(strcmp(c,"AC")==0)ac++;
		else if(strcmp(c,"WA")==0)wa++;
		else if(strcmp(c,"TLE")==0)tle++;
		else re++;
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ac,wa,tle,re);
	return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;

long long n,a,b,c,d;

int main()
{
	cin>>n>>a>>b>>c>>d;
	for (int i=0;i<n;i++)
	{
		long long sum=a+c*i-c*(n-i-1);
		if (sum<=b && sum+(d-c)*i>=b)
		{
			cout<<"YES";
			return 0;
		}
		if (sum>=b && sum-(d-c)*(n-i-1)<=b)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a, b, x, ans;
	cin >> x >> a >> b;
	ans = a + b;
	if (a >= b) cout << "delicious"<<endl;
	else if (b-a <= x)  cout << "safe"<<endl;
	else cout << "dangerous"<<endl;

	
	return (0);
}

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

int main(){

  while(1){
    int n,p;
    cin  >> n >> p;
    if(n == 0 && p == 0) break;
    int stone[60]={}, i = 0, x = p;
    while(1){
      if(stone[i] == p){
	cout << i <<endl;
	break;
      }
      if(x == 0){
	x = stone[i];
	stone[i] = 0;
      }
      else{
	stone[i]++;
	x--;
      }
      i++;
      if(i == n) i = 0;
    }


  }

  return 0;
}

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

int A, B;

int main()
{
    cin >> A >> B;
    vector<vector<char>> iro(50, vector<char>(100, '.'));
    for (int i = 0; i < B - 1; i++)
    {
        iro[(i / 50) * 2][(i % 50) * 2] = '#';
    }

    for (int i = 25; i < 50; i++)
    {
        iro[i] = vector<char>(100, '#');
    }

    for (int i = 0; i < A - 1; i++)
    {
        iro[49 - (i / 50) * 2][(i % 50) * 2] = '.';
    }

    cout << "50 100\n";
    for (auto row : iro)
    {
        for (auto c : row)
            cout << c;
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 384
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b
n,k=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append(struct(a,b))
l=sorted(l,key=lambda x:x.a)
s=0
for i in l:
  s+=i.b
  if k<=s:
    print(i.a)
    exit()

Measured memory_bytes: 29168
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		int z = sc.nextInt();
		int w = sc.nextInt();
		
		int a[] = new int[n+1];
		
		a[0] = w;
		for(int i = 0 ; i < n ; i ++){
			a[i+1] = sc.nextInt();
		}	
		
		for(int i = 0 ; i < n ; i++){
			a[i] = Math.abs(a[i] - a[n]);
		}
		
		System.out.println(Math.max(a[0],a[n-1]));
	}
}


Measured memory_bytes: 25572
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define read	freopen("input.txt", "r", stdin)
#define write	freopen("output.txt", "w", stdout)
#define mx      5e9

using namespace std;
ll dp[110][100009];
int main()
{
	// read;
	// write;

    int n, W, x, y;
    cin>>n>>W;

    vector< pii >v;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        v.push_back(pii(x,y));
    }
    sort(v.begin(), v.end());
    for(int j=v[0].f;j<=W;j++)
        dp[0][j] = v[0].s;
    for(int i=1;i<n;i++){
        for(int j=0;j<v[i].f;j++){
            dp[i][j] = dp[i-1][j];
            // printf("%4lld", dp[i][j]);
        }

        for(int j=v[i].f;j<=W;j++){
            dp[i][j] = max(dp[i-1][j-v[i].f]+v[i].s, dp[i-1][j]);
            // printf("%4lld", dp[i][j]);
        }
        // printf("\n");
    }
    cout<<dp[n-1][W];

}
    



Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N];

		long sum_a = 0;
		int minus_count = 0;
		long min_abs = Long.MAX_VALUE;
		boolean zero = false;
		for(int i=0;i<N;i++) {
			A[i] = sc.nextLong();
			sum_a += Math.abs(A[i]);
			if(A[i] == 0) {
				zero = true;
			}else if(A[i] < 0) {
				minus_count++;
			}

			if(Math.abs(A[i]) < min_abs) {
				min_abs = Math.abs(A[i]);
			}
		}

		if(zero) {
			System.out.println(sum_a);
		}else if(minus_count % 2 == 0) {
			System.out.println(sum_a);
		}else {
			System.out.println(sum_a - 2*min_abs);
		}
	}
}

Measured memory_bytes: 50280
from operator import itemgetter
N = int(input())
ans = []
for i in range(N):
  s,p = input().split()
  ans.append([s,int(p),int(i+1)])
ans = sorted(ans)
ans_list = []
tmp = [ans[0]]
for i in range(1,N):
  if ans[i][0] == ans[i-1][0]:
    tmp.append(ans[i])
  else:
    tmp = sorted(tmp, key=itemgetter(1),reverse=True)
    for j in range(len(tmp)):
      ans_list.append(tmp[j])
    tmp = []
    tmp.append(ans[i])
tmp = sorted(tmp, key=itemgetter(1),reverse=True)
for j in range(len(tmp)):
  ans_list.append(tmp[j])
for i in range(N):
  print(ans_list[i][2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust"<<'\n';
	else cout<<"win"<<'\n';
    return 0;
}



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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll R;
  scanf("%lld",&R);
  ll G;
  scanf("%lld",&G);
  cout << G*2-R << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,MOD=1e9+7;
int num,to[N<<1],la[N<<1],he[N],dp[N][2];
int read()
{
	int 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<<1)+(x<<3)+(ch&15),ch=getchar();
	return x*f;
}
void addedge(int x,int y){to[++num]=y;la[num]=he[x];he[x]=num;}
void dfs(int u,int f)
{
	int flag=1;
	for (register int i=he[u];i;i=la[i])
	{
		int v=to[i];if (v==f) continue;
		dfs(v,u);
		if (flag) dp[u][0]=dp[v][1],dp[u][1]=(dp[v][0]+dp[v][1])%MOD,flag=0;
		else dp[u][0]=1ll*dp[v][1]*dp[u][0]%MOD,dp[u][1]=(1ll*dp[v][0]*dp[u][1]+1ll*dp[v][1]*dp[u][1])%MOD;
	}
	if (flag) dp[u][0]=dp[u][1]=1;
}
int main()
{
	int n=read();
	for (register int i=1;i<=n-1;++i) {int x=read(),y=read();addedge(x,y);addedge(y,x);}
	dfs(1,0);
	int ans=(dp[1][0]+dp[1][1])%MOD;
	printf("%d\n",ans);
	return 0;
}

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

int main() {

    int v[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;

    cin >> k;

    cout << v[k - 1] << endl;
    return 0;

}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int taka = (a+d-1)/d;
  int aoki = (c+b-1)/b;
  if(taka>=aoki) cout<< "Yes" <<endl;
  else cout<< "No" <<endl;
}


Measured memory_bytes: 3552
import collections as col
n = int(input())
li = list(map(int,input().split()))

c = col.Counter(li)
#print(list(c.items()))
c = sorted(list(c.items()),key = lambda x:-x[0])
tmp1 = 0
tmp2 = 0
for i in range(n):
  if c[i][1] >= 2:
    if tmp1 != 0:
      tmp2 = c[i][0]
      #print("i1")
      break
    elif c[i][1] < 4:
      tmp1 = c[i][0]
      #print("i2")
    else:
      tmp1 = c[i][0]
      tmp2 = c[i][0]
      #print("i3")
      break
else:
  print(0)
  exit()
print(tmp1*tmp2)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int N;
  cin >> N;
  vector<int> dam(N);
  long long sum1 = 0;
  long long sum2 = 0;
  for(int i = 0; i < N; i++){
    cin >> dam.at(i);
    if(i % 2 == 0){
      sum1 += dam.at(i);
    } else{
      sum2 += dam.at(i);
    }
  }
  vector<int> mountain(N);
  mountain.at(0) = sum1 - sum2;
  for(int i = 1; i < N; i++){
    mountain.at(i) = 2 * dam.at(i-1) - mountain.at(i-1);
  }

  for(int i = 0; i < N; i++){
    cout << mountain.at(i) << " ";
  }
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1e9;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)


int main(){
    long N,K;
    cin >> N >> K;
    
    long ans = 0;
    for(long b=K+1;b<=N;++b){
        long Q = N/b;
        long P = N%b;
        ans += Q*max(0l,b-K)+max(P-K+1,0l);
    }
    if(K == 0) ans = N*N;

    cout << ans << endl;
}

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

int bubbleSort(int A[],int N){
	int sw=0;
	bool flag=1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=N-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				flag=1;
				sw++;
			}
		}
	}
	return sw;
}

int main(){
	int A[100],N,sw;
	cin>>N;
	for(int i=0;i<N;i++) cin>>A[i];
	
	sw=bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i)cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	cout<<sw<<endl;
	
	return 0;
}

Measured memory_bytes: 3032
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,d1,d2;
  cin>>n>>d1>>d2;
  vector<int> SQRT(4*n*n+1,-1);
  for(int i=0;i<=2*n;i++){
    SQRT[i*i]=i;
  }
  vector<vector<int> > alive(2*n, vector<int>(2*n, 1));
  for(int rot=0;rot<2;rot++){
    int d=(rot==0?d1:d2);
    vector<vector<int> > was(2*n, vector<int>(2*n, 0));
    for(int i=0;i<2*n;i++){
      for(int j=0;j<2*n;j++){
        if(was[i][j]||!alive[i][j])continue;
        vector<P> que(1, P(i,j));
        was[i][j]=1;
        for(int b=0;b<(int)que.size();b++){
          int x=que[b].first;
          int y=que[b].second;
          for(int xx=0;xx<2*n;xx++){
            int dy=d-(x-xx)*(x-xx);
            if(dy>=0&&dy<=4*n*n&&SQRT[dy]!=-1){
              dy=SQRT[dy];
              int yy=y-dy;
              if(yy>=0&&yy<2*n&&was[xx][yy]==0&&alive[xx][yy]){
                que.emplace_back(xx, yy);
                was[xx][yy]=3-was[x][y];
              }
              if(dy != 0){
                yy = y + dy;
                if(yy>=0&&yy<2*n&&was[xx][yy]==0&&alive[xx][yy]){
                  que.emplace_back(xx, yy);
                  was[xx][yy]=3-was[x][y];
                }
              }
            }
          }
        }
        vector<int> cc(3, 0);
        for(auto &p : que){
          cc[was[p.first][p.second]]++;
        }
        int best = (cc[1] > cc[2] ? 1 : 2);
        for(auto &p : que){
          if(was[p.first][p.second] != best){
            alive[p.first][p.second] = 0;
          }
        }
      }
    }
  }
  int cc=n*n;
  FOR(i,0,2*n){
    FOR(j,0,2*n){
      if(alive[i][j]){
        cc--;
        cout << i << " " << j << endl;
        if(cc==0) return 0;
      }
    }
  }
}

Measured memory_bytes: 9592
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  int H;
  int A;

  cin >> H >> A;

  cout << H / A + min(H % A, 1);

  return 0;
}


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

int main() {
  int N,k;
  k = 1;
  cin >>N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i=0; i<N-1; i++){
    if(vec.at(i)!=vec.at(i+1)){
      k=k+1;
    }
  }
  cout <<k <<endl;
}


Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

ll lcm(ll x, ll y) {
	while (y) {
		x %= y;
		swap(x, y);
	}
	return x;
}

int main() {
	ll A, B;
	cin >> A >> B;
	ll C = lcm(A, B);
	cout << A / C * B << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1154&lang=jp
int main() {
    char map_data[9999];
    int x_b;
    int y_b;
    int x_a;
    int y_a;
    int width = 0;
    int height = 0;
    int map[999][9];
    int flag = 0;
    int count = 0;
    while(1){
        for(int i = 0;i < 9999;i++){
            map_data[i] = '*';
        }
        for(int i = 0;i < 9;i++){
            for(int ii = 0;ii < 999;ii++){
                map[ii][i] = 2;
            }
        }
        scanf("%s", map_data);
        scanf("%d %d %d %d", &x_b, &y_b, &x_a, &y_a);
        if(map_data[0] == '#'){
            break;
        }
        for(int i = 0;i < 9999;i++){
            if(map_data[i] == '/' && flag == 0){
                //printf("1 %d,%d,%d,%c\n",i,width,height,map_data[i]);
                height++;
                width = 0;
                flag = 1;
            }
            if(map_data[i] == 'b' && flag == 0){
                //printf("2 %d,%d,%d,%c\n",i,width,height,map_data[i]);
                map[width][height] = 1;
                width++;
                flag = 1;
            }
            if((map_data[i] == ' ' || map_data[i] == '*') && flag == 0){
                //printf("3 %d,%d,%d,%c\n",i,width,height,map_data[i]);
                height++;
                flag = 1;
                break;
            }
            else{
                if(flag == 0){
                    for(int ii = 0;ii < (int)map_data[i] - 48; ii++){
                        //printf("4 %d,%d,%d,%c,%d\n",i,width,height,map_data[i],(int)map_data[i]);
                        map[width][height] = 0;
                        width++;
                    }
                    flag = 1;
                }
            }
            flag = 0;
        }
        flag = 0;
        map[y_b - 1][x_b - 1] = 0;   
        map[y_a - 1][x_a - 1] = 1;   
        for(int i = 0;i < height;i++){
            for(int ii = 0;ii < width; ii++){
                if(map[ii][i] == 1){
                    if(count != 0){
                        printf("%d",count);
                        count = 0;
                    }
                    printf("b");
                }
                if(map[ii][i] == 0){
                    count++;
                }
            }
            if(count != 0){
                printf("%d",count);
                count = 0;
            }
            if(i + 1 < height){
                printf("/");
            }
        }
        width = 0;
        height = 0;
        count = 0;
        flag = 0;
        printf("\n");
    }  
    return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
int n,m,b[MAX],ans,c[MAX];
int main()
{
	cin>>n>>m;
	b[0]=true;
	for (int i=0;i<n;i++) c[i]=1;
	for (int i=0,v,u;i<m;i++) 
	{
		cin>>v>>u,v--,u--;
		c[v]--,c[u]++;
		if (b[v]) b[u]=1;
		if (c[v]==0) b[v]=0;
	}
	for (int i=0;i<n;i++) ans+=b[i] && c[i];
	cout<<ans;

}

Measured memory_bytes: 1024
program one_dimensional_worlds_tale
  implicit none
  integer :: n, m, a, b, x(100) = 0, y(100) = 0
  read(*,*) n, m, a, b
  read(*,*) x(1:n)
  read(*,*) y(1:m)
  if (max(maxval(x(1:n)),a) < min(minval(y(1:m)),b)) write(*,'(a)',advance='no') "No "
  write(*,'(a)') "War"
end program one_dimensional_worlds_tale

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] arr = br.readLine().split("");
        long zeroCount = Arrays.stream(arr).filter(num -> "0".equals(num)).count();
        long oneCount = arr.length - zeroCount;
        out.println(Math.min(zeroCount, oneCount) * 2);
        out.close();
    }
}


Measured memory_bytes: 32596
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main(){
  int N, M;cin>>N>>M;
  vi num_match={0,2,5,5,4,5,6,3,7,6};
  vi A;
  for (int i=0;i<M;++i){
    int a;cin>>a;A.push_back(a);
  }

  vi uselist(8,-1);

  for (int m=2;m<=7;++m){
    for (int i=0;i<M;++i){
      if(num_match[A[i]]==m){uselist[m]=max(uselist[m], A[i]);}
    }
  }


  //n本のマッチ棒を使って最大数を作った時の桁数をdp[n][0]に格納し、
  //pが使われる個数をdp[n][p]に格納する。
  vvi dp(N+10);
  //initialization
  for (int i=0;i<N+10;++i){
    for (int j=0;j<10;++j){
      dp[i].push_back(-1);
    }
  }
  
  for (int j=0;j<10;++j){dp[0][j]=0;}

  for (int n=0;n<=N;++n){
    for (int m=2;m<=7;++m){
      if (uselist[m]==-1){continue;}
      //uselist[m]=1の時は、pとして9thに格納したい
      int p=10-uselist[m];
      dp[n][0]++;
      dp[n][p]++;
      dp[n+m]=max(dp[n], dp[n+m]);
      dp[n][0]--;
      dp[n][p]--;
    }
  }

  for (int i=9;i>=1;--i){
    //数字として大きい方から出力したい。それは、番号が若い方。
    int T=dp[N][10-i];
    for (int j=0;j<T;++j){
      cout << i;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1280
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K, Q = MAP()
A = [INT() for _ in range(Q)]
cnt = [0]*N

for n in A:
  cnt[n-1] += 1
  
for i in range(N):
  print("Yes" if K + cnt[i] -Q > 0 else "No")

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

int N, Q;
int p[100010];
char q[100010];
int v[100010];
int mark[100010];
vector<int> ch[100010];

int par[100010];
int find(int x) {
  return par[x] == x ? x : par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x); y = find(y);
  if (x == y) return;
  if (mark[y]) swap(x, y);
  assert(mark[y] == 0);
  par[y] = x;
}

void init() {
  for (int i = 0; i < 100010; i++) {
    ch[i].clear();
    mark[i] = 0;
    par[i] = i;
  }
  p[0] = -1;
  mark[0] = 1;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> N >> Q, N) {
    init();
    for (int i = 1; i < N; i++) {
      cin >> p[i];
      p[i]--;
      ch[p[i]].emplace_back(i);
    }
    for (int i = 0; i < Q; i++) {
      cin >> q[i] >> v[i];
      v[i]--;
      if (q[i] == 'M') mark[v[i]]++;
    }
    stack<int> st;
    st.emplace(0);
    while (!st.empty()) {
      int v = st.top();
      st.pop();
      for (int nv : ch[v]) {
        st.emplace(nv);
      }
      if (mark[v]) continue;
      if (p[v] >= 0) unite(p[v], v);
    }

    ll ans = 0;
    for (int i = Q-1; i >= 0; i--) {
      if (q[i] == 'M') {
        mark[v[i]]--;
        if (mark[v[i]] == 0) unite(p[v[i]], v[i]);
      } else {
        ans += find(v[i]) + 1;
      }
    }
    cout << ans << endl;
  }  

  return 0;
}


Measured memory_bytes: 10944
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=505;
const int d=4000;

int n,m,x,y,a[N][N];

int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	if (n%x==0&&m%y==0) {puts("No");return 0;}
	puts("Yes");
	for (int i=x;i<=n;i+=x)
		for (int j=y;j<=m;j+=y)
			a[i][j]=-x*y*d+d-1;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++) printf("%d ",!a[i][j]?d:a[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2560
import java.util.HashSet;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		HashSet hasCandy = new HashSet();

		for (int j = 0; j < K; j++){
			int d = scan.nextInt();
			for (int i = 0; i < d; i++){
				int A= scan.nextInt();
				hasCandy.add(A);
			}
		}

		System.out.println(N - hasCandy.size());
	}
}

Measured memory_bytes: 46208
# coding:utf-8

import math
import re

def main(params):
    n,k = params[0].split()
    print int(n) - int(k) + 1
    return int(n) - int(k) + 1

if __name__ == "__main__":
    cnt = 1 # TODO: edit here
    params = []
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)



Measured memory_bytes: 2568
def main():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    ans = "War"

    for z in range(X + 1, Y + 1):
        if max(x) < z <= min(y):
            ans = "No War"
            break

    print(ans)

main()


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(){
 int a,b,c,x;
   cin >> a >> b >> c >> x;
 int res=0;
  
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
     int tot=500*i+100*j;
     if(x>=tot && (x-tot)%50==0 && (x-tot)/50<=c) res++;
     } 
     } 
  
  cout << res << endl;
  }

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;

int n;
vector<int> a,b;

int main(){
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(i%2==1)a.push_back(x);
		else b.push_back(x);
	}
	if(n%2==0){
		for(i=b.size()-1;i>=0;i--){
			printf("%d ",b[i]);
		}
		for(i=0;i<a.size();i++){
			printf("%d ",a[i]);
		}
	}
	else{
		for(i=a.size()-1;i>=0;i--){
			printf("%d ",a[i]);
		}
		for(i=0;i<b.size();i++){
			printf("%d ",b[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
class Trees{
  vector<int> par;
  vector<int> rank;
  public:
  int root(int i){
    int rt;
    if(par[i]==i){rt=i;rank[i]=1;}
    else{rt=root(par[i]);par[i]=rt;rank[i]=2;}
    return rt;
  }
  void unite(int i,int j){
    int rki=rank[i];int rkj=rank[j];
    if(rki<rkj){par[root(i)]=root(j);rank[i]++;}
    else{par[root(j)]=root(i);rank[j]++;}
  }
  bool same(int i,int j){
    return root(i)==root(j);
  }
  Trees(int n){
    for(int i=0;i<n;i++) {par.push_back(i);rank.push_back(1);};
  }
  bool solve(long N){
    bool r=1;
    for(long i=1;i<N;i++)r&=same(0,i);
    return r;
  }
};
int main(){
  long N,M;cin>>N>>M;
  Trees tree(N+M);//人と言語
  for(long i=0;i<N;i++){
    long k;cin>>k;
    for(long j=0;j<k;j++){
      long l;cin>>l;tree.unite(i,N+l-1);
    }
  }
  cout<<(tree.solve(N)?"YES":"NO");
}

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

int main() {
    int n, m;
    int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
    int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
    while (cin >> m >> n, n || m) {
        vector<vector<int>> v(n, vector<int>(m));
        for (auto& i : v) for (auto& j : i) cin >> j;

        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (v[i][j] == 0) continue;
                count++;
                queue<pair<int,int>> que;
                que.push(make_pair(i, j));

                while (que.size()) {
                    auto p = que.front();
                    que.pop();
                    int x = p.first;
                    int y = p.second;

                    if (v[x][y] == 0) continue;

                    v[x][y] = 0;

                    for (int k = 0; k < 8; k++) {
                        int nx = x + dx[k];
                        int ny = y + dy[k];

                        if (0 <= nx && nx < n && 0 <= ny && ny < m && v[nx][ny] == 1) {
                            que.push(make_pair(nx, ny));
                        }
                    }
                }
            }
        }

        cout << count << endl;
    }

    return 0;
}



Measured memory_bytes: 3048
n = int(input())
hs = list(map(int, input().split()))
count = 0
for i in range(n):
    if i == 0:
        count += 1
        continue
    ok = True
    for j in range(i):
        if hs[j] > hs[i]:
            ok = False
            break
    if ok:
        count += 1
print(count)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
const int N=2e5+11,M=N<<2,oo=~0u>>2;
int n,m,mn[M],z[M],t[M],g[M];
int ql,qr,qx;
void pu(int x){
	z[x]=z[x*2];
	t[x]=t[x*2+1];
	mn[x]=min(mn[x*2],mn[x*2+1]);
}
void build(int x,int l,int r){
	if(l==r){
		z[x]=l;
		t[x]=l;
		return;
	}
	int m=l+r>>1;
	build(x*2,l,m);
	build(x*2+1,m+1,r);
	pu(x);
}
void pt(int x,int w,int r){
	g[x]=w;
	t[x]=w;
	z[x]=w;
	if(w<=m)mn[x]=w-r;
	else mn[x]=oo;
}
void upd(int x,int l,int r){
	if(z[x]>qr||t[x]<ql)return;
	if(z[x]>=ql&&t[x]<=qr){
		pt(x,qr+1,r);
		return;
	}
	int m=l+r>>1;
	if(g[x]){
		pt(x*2,g[x],m);
		pt(x*2+1,g[x],r);
		g[x]=0;
	}
	upd(x*2,l,m);
	upd(x*2+1,m+1,r);
	pu(x);
}
int main(){
	cin>>n>>m;
	int i;
	build(1,1,m);
	int p=1;
	for(i=1;i<=n;++i){
		cin>>ql>>qr;
		upd(1,1,m);
		if(mn[1]>m)puts("-1");
		else printf("%d\n",mn[1]+i);
	}
}

Measured memory_bytes: 11952
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1000000;
int N;
string L;
ll dp[2][MAX_N];


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

  cin >> L;
  N = len(L);

  if (L[0] == '1') {
    dp[0][0] = 2;
    dp[1][0] = 1;
  } else {
    dp[0][0] = 1;
    dp[1][0] = 0;
  }

  for (int i = 1; i < N; ++i) {
    if (L[i] == '1') {
      dp[0][i] = mod(dp[0][i-1]*2, MOD);
      dp[1][i] = mod(dp[1][i-1]*3 + dp[0][i-1], MOD);
    } else {
      dp[0][i] = dp[0][i-1];
      dp[1][i] = mod(dp[1][i-1]*3, MOD);
    }
  }

  ll ans = mod(dp[0][N-1] + dp[1][N-1], MOD);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5312
#include <stdio.h>

int main(void){
	int x,a,b,c,d;
	d=0;

	scanf("%d %d %d",&a,&b,&c);

	for(x=a;x<=b;x++){
		if(c%x == 0){
			d++;
		}
	}
	printf("%d\n",d);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int a, b;
	cin >> a >> b;

	cout << max(max(a + b, a-b), a*b);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	int N;
	int dp[100010][3];
	int a[100010], b[100010], c[100010];
	cin >> N;
	for (int i = 0; i < 3; ++i) {
		dp[0][i] = 0;
	}
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 0; i < N; ++i) {
		dp[i + 1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
		dp[i + 1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i]);
		dp[i + 1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
	}
	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X,N;
    cin>>X>>N;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);
    //upperside
    int mindif=120;
    int flag=0;
    for(int i=X;i<X+110;i++){
        flag=0;
        for(int j=0;j<N;j++){
            if(i==A[j]) flag=1;
        }
        if(flag !=1){
            mindif=i;
            break;
        }
    }
  
    int mindifa=200;
    flag=0;
    for(int i=X;i>=X-150;i--){
        flag=0;
        for(int j=0;j<N;j++){
            if(i==A[j]) flag=1;
        }
        
        if(flag !=1) {
            mindifa=i;
            break;
        }
    }
    

    if (abs(mindifa-X)<=abs(mindif-X)){
        mindif=mindifa;
    }
      
    
    
    if(N==0){
        cout<<X<<endl;
        return 0;
    }
    
    
    
    cout<<mindif<<endl;
    
    return 0;
}

 


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
long long i,t[100010];
long long tot,n,m,ap[100010],k,k2,ans[100010];
pair<long long,long long>v[100010];
long long gaseste(long long x)
{
    if(x!=t[x])t[x]=gaseste(t[x]);
    return t[x];
}
void uneste(long long x,long long y)
{
    long long tx,ty;
    tx=gaseste(x);
    ty=gaseste(y);
    if(tx<ty)
    {
        t[ty]=tx;
        ap[tx]+=ap[ty];
        ap[ty]=0;
        gaseste(ty);
    }
    else
    {
        t[tx]=ty;
        ap[ty]+=ap[tx];
        ap[tx]=0;
        gaseste(tx);
    }
}
int main()
{
   // ifstream cin ("a.in");
   // ofstream cout ("a.out");
    cin>>n>>m;
    for(i=1; i<=n; ++i)t[i]=i,ap[i]=1;
    tot=n*(n-1)/2;
    ans[m]=tot;
    for(i=1; i<=m; ++i)
        cin>>v[i].first>>v[i].second;
    for(i=m; i>=2; --i)
    {
        k=k2=0;
        if(gaseste(v[i].first)!=gaseste(v[i].second))
        {
            k=ap[gaseste(v[i].first)];
            k2=ap[gaseste(v[i].second)];
            uneste(v[i].first,v[i].second);
        }
        if(ans[i]>=k*k2)ans[i-1]=ans[i]-k*k2;
        else ans[i-1]=0;
        if(ans[i-1]==0)break;
    }
    for(i=1; i<=m; ++i)
        cout<<ans[i]<<'\n';
    return 0;
}


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

int gcd(ll a, ll b) {
    if (a%b==0) {
        return b;
    } else {
        return (gcd(b, a%b));
    }
}

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

    ll cand1, cand2;
    cand1 = n%k;
    cand2 = k-n%k;

    if (cand1 < cand2) {
        cout << cand1 << endl;
    } else {
        cout << cand2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256