akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
   //    #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
/*        
        int par[100100],ranks[100100],kosuu[100100];     

void shoki(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		ranks[i]=0;
		kosuu[i]=1;
	}
}

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

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

void unite(int x,int y){
 x=root(x);
 y=root(y);
 if(x==y) return;
	if(ranks[x]<ranks[y]){
		par[x]=y;
		kosuu[y]+=kosuu[x];
	}
 else {
	par[y]=x;
 	kosuu[x]+=kosuu[y];
	if(ranks[x]==ranks[y]) ranks[x]=ranks[x]+1;
 }
}

int kazu(int x){
	return kosuu[root(x)];
}
*/


signed main(){
int n,m;
	
	cin>>n;
	int a[120];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum +=a[i];
	}
	
	int d=sum/n;
	int ans=inf;
	for(int i=d-3; i<=d+3;i++){
		int u=0;
		for(int j=0;j<n;j++){
			u += (a[j]-i)*(a[j]-i);
			
			
		}
		if(u<ans) ans=u;
		
	}
cout<<ans<<endl;
	
	return 0;
        }


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = (N + K - 3) / (K - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3976
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	if(n <= k){
		ans += x * n;
	}else{
		ans += x * k;
		ans += y * (n - k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
inline int Abs(int x){return x<0?-x:x;}
int main(){
	int a,b,v,w,t;
	scanf("%d%d%d%d%d",&a,&v,&b,&w,&t);
	puts(v<=w||1ll*(v-w)*t<1ll*Abs(a-b)?"NO":"YES");
	return 0;
}

Measured memory_bytes: 1664
n, X = gets.split.map &:to_i

x = gets.split.map &:to_i

diff = []

x.each_cons(2){ |a, b|
	diff << b - a
}

diff << (X - x[0]).abs

gcd = diff[0]

(1...diff.size).each{ |i|
	gcd = gcd.gcd(diff[i])
}

puts gcd

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

public class Main
{

	static int[] dp,a;
	static int n;

		
	public static void main(String[] args)throws IOException{

			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			
			n=Integer.parseInt(br.readLine());
			dp=new int[n];a=new int[n];
			String[] s=br.readLine().split(" ");

			for(int i=0;i<n;i++)
				a[i]=Integer.parseInt(s[i]);

			dp[0]=0;
			dp[1]=Math.abs(a[0]-a[1]);

			for(int i=2;i<n;i++)
				dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
			
			System.out.println(dp[n-1]);

			

	}
	
}







Measured memory_bytes: 35544
#include<bits/stdc++.h> 
using namespace std;                          
#pragma GCC optimize("O3")
typedef long long ll;
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define vec(i, a)  for( auto i=a.begin();i != a.end(); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in  freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sixfive in out 
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
const ll MOD = 1e9 + 7;
ll n_bits(ll n ) { ll x= __builtin_popcount(n) ;return x ;}
int main()
{    
    #ifndef ONLINE_JUDGE
    sixfive
    #endif
    fast
    ll t=1;
    //cin>>t;
    while(t--)
    {    
        int k;
        string s,ans="";
        cin>>k>>s;
        int l=s.length();
        if(l<=k)
          return cout<<s,0;
        else
        {
          for(int i=0;i<k;i++)
          {
            ans+=s[i];
          }
          ans+="...";
          cout<<ans;
        }

    }
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
A = [int(i) for i in input().split()]

s = [0]*61
for a in range(n):
    for i in range(61):
        if(A[a]>>i&1)==1:
            s[i+1] += 1
ans = 0
for i in range(60):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i)*s[i+1]*(n-s[i+1])
ans = ans % (10**9+7)
print(int(ans))
# print(s)


Measured memory_bytes: 122808
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			String s = sc.next();
			int b = sc.nextInt();
			if(s.equals("?")) break;
			else if(s.equals("+")) System.out.println(a+b);
			else if(s.equals("-")) System.out.println(a-b);
			else if(s.equals("*")) System.out.println(a*b);
			else if(s.equals("/")) System.out.println(a/b);
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (ll i=(b)-1; i>=a;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<vector<T> >& vec) {
    REP(i,vec.size()) {
        if(i) os << endl;
        os << vec[i];
    }
    return os;
}

struct Point {
    int x, y;
};

typedef vector<vector<P>> Matrix;

int W, H;
Matrix A;
vector<P> Human;

Matrix dot(const Matrix& a, const Matrix& b) {
    Matrix res(H, vector<P>(W, {-1, -1}));
    REP(y, H) REP(x, W) {
        P p = a[y][x];
        res[y][x] = b[p.second][p.first];
    }
    return res;
}
vector<P> dot(const vector<P>& human, const Matrix& conv) {
    vector<P> res;
    EACH(h, human) {
        res.pb(conv[h.second][h.first]);
    }
    return res;
}
Matrix E(int w, int h) {
    Matrix res(h, vector<P>(w, {-1, -1}));
    REP(y, h) REP(x, w) {
        res[y][x] = {x, y};
    }
    return res;
}
Matrix power(Matrix X, int n) {
    Matrix res = E(W, H);
    for (ll i = 1; i <= n; i <<= 1) {
        if (i & n) res = dot(res, X);
        X = dot(X, X);
    }
    return res;
}

bool is_conflict(int step) {
    vector<P> after = dot(Human, power(A, step));
    set<P> s;
    EACH(p, after) s.insert(p);
    return s.size() != after.size();
}
bool is_dup(vector<P> after) {
    int ps = after.size();
    sort(ALL(after));
    after.erase(unique(ALL(after)), after.end());
    return after.size() != ps;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> H >> W >> n;
    A.assign(H, vector<P>(W, {-1, -1}));
    REP(y, H) REP(x, W) {
        int ny, nx; cin >> ny >> nx;
        A[y][x] = {nx, ny};
    }
    REP(i, n) {
        int y, x; cin >> y >> x;
        Human.pb({x, y});
    }
    ll l = 0, r = W*H;
    if (!is_conflict(r)) {
        cout << -1 << endl;
    }
    else {
        int lg = 0;
        for (ll i = 1; i <= W*H; i <<= 1, ++lg);
        vector<Matrix> powX;
        powX.pb(A);
        REP(i, lg) {
            powX.pb(dot(powX[i], powX[i]));
        }
        Matrix X = E(W, H);
        ll ans = 0;
        RREP(i, lg) {
            Matrix nX = dot(X, powX[i]);
            if ( !is_dup(dot(Human, nX)) ) {
                ans += (1<<i);
                X = nX;
            }
        }
        ++ans;
        cout << ans << endl;
        // REP(t, 30) {
        //     int m = (l + r) / 2;
        //     if (is_conflict(m)) {
        //         r = m;
        //     }
        //     else {
        //         l = m;
        //     }
        // }
        // cout << r << endl;
    }
}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a<=8 && b<=8) {
			System.out.println("Yay!");
		}else {
			System.out.print(":(");
		}

	}

}


Measured memory_bytes: 19924
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if N == 0:
    if A[0] != 1:
        print(-1)
        exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()



ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)

Measured memory_bytes: 668980
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = (h2 - h1) * 60 + (m2 - m1) - k;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  ll N,i=1;cin>>N;
  string ans="";
  if(N==0){
    print(0)
    return 0;
  }
  while(N!=0){
    // print(N<<" "<<i)
    if(N%((ll)((powl(2LL,i))))!=0){
      ans='1'+ans;
      N=N-powl((-2LL),i-1);
    }
    else {
      ans='0'+ans;
    }
    i++;
  }

  print(ans)
}


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

int n;


int a[200005];
int b[200005];
long long s[200005];


int main()
{
    scanf("%d",&n);

    for(int i = 0; i < n; i++)
        {
            scanf("%d",b + i);
            int c = b[i];
            s[c] += a[c];
            a[c]++;
        }

    long long sum = 0;

    for(int i = 1; i <= n; i++)
        sum += s[i];

    for(int i = 0; i < n; i++)
    {
        cout << sum - (a[b[i]] - 1) << endl;
    }
}


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

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

void solve(const string &str) {
  int start = -1, end = -1;
  for (int i = 0; i < str.size(); ++i) {
    if (i > 0 && str[i] == str[i-1]) {
      cout << i << " " << i+1 << endl;
      return;
    }
    if (i > 1 && str[i] == str[i-2]) {
      cout << i-1 << " " << i+1 << endl;
      return;
    }
  }
  cout << -1 << " " << -1 << endl;
}

int main() {
  string str;
  while (cin >> str) {
    solve(str);
  }
}







Measured memory_bytes: 512
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def bs(L, x):
	i, jump = 0, len(L)-1
	while jump >= 1:
		while i + jump < len(L) and L[i+jump] <= x:
			i += jump
		jump //= 2
	return i


def main():
	x, n = rli()
	P = list(rli())
	P.sort()
	forbidden = set(P)
	if x not in forbidden:
		print(x)
		return
	# c = bs(P, x)
	for diff in range(0, 101):
		a, b = x - diff, x + diff
		if a not in forbidden:
			print(a)
			return
		if b not in forbidden:
			print(b)
			return
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 65424
Scanf.scanf "%d %d %d" (fun n c k ->
    let t = Array.init n (fun _ -> Scanf.scanf " %d" (fun t -> t )) in
    Array.sort compare t;
    
    let rec loop i cur pop buses =
        if i = n then (if pop > 0 then buses + 1 else buses) else
            let tt = t.(i) in
            if tt <= cur + k then (
                if pop < c then loop (i + 1) cur (pop + 1) buses else
                                loop (i + 1) tt  1 (buses + 1)
            ) else (
                let buses = if pop > 0 then buses + 1 else buses in
                loop (i + 1) tt 1 buses
            )
    in
    loop 0 0 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6628
#include "bits/stdc++.h"

using namespace std;

int main() {
	int n;
	cin >> n;
	int b[100];
	for (int i = 0; i < n - 1; i++)
		cin >> b[i];

	int ans = b[0] + b[n - 2];
	for (int i = 1; i < n - 1; i++)
	{
		ans += min(b[i - 1], b[i]);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int W,H,x,y,r,a;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H)
    printf("Yes\n");

  if(x-r<0||y-r<0||x+r>W||y+r>H)
    printf("No\n");
    
  
  return 0;
}

Measured memory_bytes: 2668
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

numlist = [a,b,c,d,e]

sumtime = 0
maxAMARI = 10

for i, v in enumerate(numlist):
  if maxAMARI >= (v-1) % 10:
    maxAMARI = (v-1) % 10
    ind = i
  
ans = 0
for i ,v in enumerate(numlist):
  if i != ind:
    ans += math.ceil(v/10)*10
  else:
    ans += v
print(ans)

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

using namespace std;

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef complex<ld> point;
typedef vector<int> vi;

inline void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 1e9 + 7;
constexpr int N = 1e5 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

int n, m;
vi adj[N];

ll ans;
int cnt[N];
bitset<N> st;
void dfs(int v, int par = 0) {
  st[v] = !st[par];
  if (st[v])
    cnt[v]++;
  else
    cnt[v]--;
  for (auto e : adj[v])
    if (e ^ par) {
      dfs(e, v);
      cnt[v] += cnt[e];
    }
  ans += abs(cnt[v]);
}

int par[N];
int getPar(int v) { return par[v] ? (par[v] = getPar(par[v])) : v; }
inline bool merge(int u, int v) {
  u = getPar(u);
  v = getPar(v);
  if (v == u) return false;
  par[v] = u;
  return true;
}

vi vec;
bool dfs2(int v, int u, int par = 0) {
  if (v == u) {
    vec.pb(cnt[v]);
    return true;
  }
  for (auto e : adj[v])
    if (e ^ par && dfs2(e, u, v)) {
      vec.pb(cnt[v]);
      return true;
    }
  return false;
}

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

#ifndef LOCAL
  // fileIO("superposition");
#endif

  cin >> n >> m;

  if (n & 1) return cout << -1 << endl, 0;

  if (m == n - 1) {
    rep(i, 0, m) {
      int u, v;
      cin >> u >> v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
    dfs(1);
    if (cnt[1]) ans = -1;
    cout << ans << endl;
    return 0;
  }

  int v_, u_;

  rep(i, 0, m) {
    int u, v;
    cin >> u >> v;
    if (merge(u, v)) {
      adj[u].pb(v);
      adj[v].pb(u);
    } else
      u_ = u, v_ = v;
  }

  dfs(v_);

  if (st[v_] == st[u_]) {
    int must = cnt[v_];
    ans = 0;
    memset(cnt, 0, sizeof(cnt));
    cnt[v_] -= must / 2;
    cnt[u_] -= must / 2;
    dfs(v_);
    cout << ans + abs(must / 2) << endl;
    return 0;
  }

  if (cnt[v_]) return cout << -1 << endl, 0;

  dfs2(v_, u_);

  vec.pop_back();
  sort(all(vec));
  int must = vec[vec.size() / 2];

  memset(cnt, 0, sizeof(cnt));
  cnt[u_] -= must;
  cnt[v_] += must;

  ans = 0;
  dfs(v_);

  cout << ans + abs(must) << endl;

  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    if (s[0] == 'S') cout << "Cloudy" << endl;
    if (s[0] == 'C') cout << "Rainy" << endl;
    if (s[0] == 'R') cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define MOD 1000000007
using namespace std;
 
 
 
 
int main(){
  int x, y;
  cin >> x >> y;
  cout << max(x+y,max(x-y,x*y)) << endl;
}
  

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

pattern = ["."] * N
for i in range(M):
  s,c = input().split()
  s = int(s)
  if pattern[s - 1] not in (".",c):
    print(-1)
    exit(0)
  pattern[s - 1] = c

import re

comp = re.compile("^" + "".join(pattern) + "$")

for i in range(1001):
  res = comp.match(str(i))
  if res:
    print(i)
    break
else:
  print(-1)


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	string S;
	cin >> S;

	if (S == "SUN") {
		cout << 7 << endl;
	}
	if (S == "MON") {
		cout << 6 << endl;
	}
	if (S == "TUE") {
		cout << 5 << endl;
	}
	if (S == "WED") {
		cout << 4 << endl;
	}
	if (S == "THU") {
		cout << 3 << endl;
	}
	if (S == "FRI") {
		cout << 2 << endl;
	}
	if (S == "SAT") {
		cout << 1 << endl;
	}

	return 0;
}

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

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

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

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int x, y;cin>>x>>y;
  rep(i, x+1){
    if(y == 2*i+4*(x-i) ){cout<<"Yes"<<endl; return 0;}
  }
  cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

using ll = long long;

using namespace std;
// #include "debug.h"
#define debug(...) 42

const int mod = 998244353;

void solve() {
   int n;
   cin >> n;
   vector <int> d(n), cnt(n);
   for(int i = 0; i < n; i++) {
      cin >> d[i];
      cnt[d[i]]++;
   }
   bool ok = true;
   ok &= d[0] == 0;
   ok &= cnt[0] == 1;

   if(!ok) {
      cout << 0 << endl;
      return;
   }
   int m = *max_element(d.begin(), d.end());

   ll ans = 1;
   for(int i = 1; i <= m; i++) {
      if(cnt[i] == 0) {
         cout << 0 << endl;
         return;
      }
      for(int j = 0; j < cnt[i]; j++) {
         ans = (ans * 1LL * cnt[i - 1]) % mod;
      }
   }

   cout << ans << endl;
} 

signed main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   }
   return 0;
}


Measured memory_bytes: 3936
#include<stdio.h>

int main(){
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a*b >= a+b && a*b>=a-b){
		printf("%d\n",a*b);
	}
	else if(a+b >= a*b && a+b>=a-b){
		printf("%d\n",a+b);
	}
	else printf("%d\n",a-b);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

void solve(){
  int K,S;
  cin>>K>>S;
  int count=0;
  rep(i,K+1){
    if (S-i>2*K)continue;
    if (S-i<0)break;
    rep(j,K+1){
      if (S-(i+j)>K)continue;
      else if  (S-(i+j)<0)break;
      else{
        count++;
      }
    }
  }
  cout<<count;
}

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n + 1, vector<int>(26, 0));
    string s;
    cin >> s;
    for(int i = s.length() - 1; i >= 0; --i)
    {
        ++a[0][s[i] - 'a'];
    }
    for(int i = 1; i < n; ++i)
    {
        cin >> s;
        for(int j = 0; j < s.length(); ++j)
        {
            a[i][s[j] - 'a'] = min(a[i][s[j] - 'a'] + 1, a[i - 1][s[j] - 'a']);
        }
    }
    for(int i = 0; i < 26; ++i)
    {
        for(int j = a[n - 1][i]; j; --j)
        {
            printf("%c", 'a' + i);
        }
    }
    printf("\n");
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll n, m; cin >> n >> m;
	if (n > m) swap(n, m);

	if (n == 1) {
		if (m == 1) {
			cout << 1 << endl;
		} else {
			cout << max(m - 2, 0ll) << endl;
		}
	} else {
		cout << max(n - 2, 0ll) * max(m - 2, 0ll) << endl;
	}
	
	return 0;
	vector<vi> v(n + 2, vi(m + 2, 0));
	rep(i, 1, n + 1) rep(j, 1, m + 1) {
		for (int k : {-1, 0, 1}) for (int l : {-1, 0, 1}) v[i + k][j + l] ^= 1;
	}

	rep(i, 1, n + 1) {
		rep(j, 1, m + 1) cout << v[i][j] << " ";
		cout << endl;
	}
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s, l = min(H, W), max(H, W)

ans = 10**6
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    for i in range(1, l):
        area1 = s*i
        area2 = s//2 * (l - i)
        area3 = area2 if s % 2 == 0 else (s//2 + 1) * (l - i)
        ans = min(ans, max(area1, area2, area3) - min(area1, area2, area3))
    for i in range(1, s):
        area1 = l*i
        area2 = l//2 * (s - i)
        area3 = area2 if l % 2 == 0 else (l//2 + 1) * (s - i)
        ans = min(ans, max(area1, area2, area3) - min(area1, area2, area3))
    ans = min(ans, H, W)
    print(ans)

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

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

  if (b - a < 2 * k)
  {
    for (int i = a; i <= b; i++)
    {
      cout << i << endl;
    }
  }
  else
  {
    for (int i = a; i < a + k; i++)
    {
      cout << i << endl;
    }
    for (int i = b - k + 1; i <= b; i++)
    {
      cout << i << endl;
    }
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 10;
const int inf  = 0x7fffffff;
int n, k, h[maxn];
int main(){
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i ++){
        scanf("%d", &h[i]);
    }
    sort(h, h + n);//从小到大排
    int cnt = inf;
    for(int i = n - 1; i >= k - 1; i--){
        cnt = min(h[i] - h[i - k + 1], cnt);
    }
    printf("%d", cnt);




return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define u unsigned
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define in(i,arr) for(auto &i:arr)cin>>i;
#define out(i,arr) for(auto &i:arr)cout<<i<<" "
#define all(x) (x).begin(), (x).end()   // sort(all(v)) instead sort(v.begin(),v.end())
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb empalce_back
ll powe(ll base, ll to)
{   ll ans=1;
    while(to>0) {
        if (to & 1)
            ans *= base, to--;
        else base *= base, to /= 2;
    }
    return ans;
}
ll gcd(ll a,ll b){return (b==0)?a:gcd(b,a%b);}
bool prime(ll n){if(n==1)return 0;for(ll i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
bool check(vi v,int n)
{
    if(v.size()<2)return false;
    for(int i=0;i<v.size();i++)
    {
        if((v[i]+v[i+1]+1)==n)return true;
    }
    return false;
}


int main() {
    fast;
    int t = 1;
    //cin >> t;
    while (t--) {
       int n;
       cin>>n;
       if(n&1)cout<<0;
       else cout<<1;
    }

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define hell        163577857
#define vi          vector<int>
// #define int         long long int
const long long INF = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
typedef long long ll;
typedef pair<int, int> pairs;
vector<int>v[200005];
map<int, int>mp;
vector<int>p;
int pr;
void dfs(int x) {
  if (mp[x] != 0) {
    pr = x;
    return;
  }
  mp[x]++;
  p.push_back(x);
  for (auto it : v[x]) {
    dfs(it);
  }
}
int main () {
  ll n, k, count = 0, x;
  cin >> n >> k;
  k++;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    v[i].push_back(x);
  }
  dfs(1);
  vector<int>per;
  bool flag = false;
  for (int i = 0; i < p.size(); i++) {

    if (p[i] == pr)flag = true;
    if (flag)per.push_back(p[i]);
    else {
      count++;
    }
  }
  if (k <= count) {
    cout << p[k - 1] << endl;
  }
  else {
    k -= count;
    x = k % ((int)per.size());
    if (x == 0) {
      cout << per[per.size() - 1];
    }
    else {
      cout << per[x - 1] << endl;
    }
  }
}


Measured memory_bytes: 42620
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0,flag=1; cin>>n;
    string s; cin>>s;
    vector<int>left(n),right(n);
    for(int i=0;i<n;++i)
	if(s[i]=='<') ++cnt;
    if(s[0]=='>') right[0]=cnt;
    else right[0]=cnt-1;
    left[0]=0;
    for(int i=1;i<n;++i){
	left[i]=left[i-1]; right[i]=right[i-1];
	if(s[i]=='<') --right[i];
	if(s[i-1]=='>') ++left[i];
	if(left[i]-right[i]==0) flag=0;
    }
    if(flag) cout<<n<<endl;
    else{
	int cntl=0,cntr=0;
	for(int i=0;i<n;++i){
	    if(s[i]=='>') break;
	    ++cntl;
	}
	for(int i=n-1;i>=0;--i){
	    if(s[i]=='<') break;
	    ++cntr;
	}
	cout<<n-min(cntl,cntr)<<endl;
    }
    return 0;
}


Measured memory_bytes: 4004
#include <iostream>

using namespace std;

long long abso(long long n)
{
    if(n<0){return -n;}
    else{return n;}
}

bool able(long long a,long long v,long long b,long long w,long long t)
{
    long long relativeV = v-w, distance = abso(b-a);
    if(relativeV*t >= distance){
        return true;
    }
    else{
        return false;
    }
}
int main()
{
    long long a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(able(a,v,b,w,t)){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int dx=tx-sx,dy=ty-sy;
    //path 1
    cout<<string(dy,'U')<<string(dx,'R');
    //path 2
    cout<<string(dy,'D')<<string(dx,'L');
    //path 3
    cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
    //path 4 
    cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
    
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

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

int main(){
	ios::sync_with_stdio(false);

	int H,W; cin>>H>>W;
	vector<vector<char>> C(H,vector<char>(W));
	rep(i,H)rep(j,W) cin>>C[i][j];

	for(int i=0; i<2*H; i++){
		for(int j=0; j<W; j++){
			cout << C[i/2][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3680
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	ll n,x,a[100010],ans=0;
	cin>>n>>x;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n){
		if(x>=a[i]){
			if(i==n-1){
				if(x==a[i])ans++;
			}else{
				x-=a[i];
				ans++;
			}
		}else{
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,c,q=0,z=1e9+7;
  cin >>N;
  vector<int> C(N,0);
  for(int i=0; i<N; i++){cin >>c, C[i]=c;}
  if(N==1) q=C[0]*2%z;
  else{
    sort(C.begin(), C.end());
    for(int i=0; i<N; i++){q+=(N+1-i)*C[i], q%=z;}
    for(int i=0; i<2*N-2; i++){q*=2, q%=z;}
  }
  cout <<q <<endl;
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    h1, m1, h2, m2, k = geta(int)

    diff = (h2 - h1) * 60 + m2 - m1 - k

    print(diff if diff > 0 else 0)


if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for(ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007 
#define MAXR 100000

ll N, Q;
vector<vector<ll>> G(200010);
vector<ll> cost(200010, 0);
vector<bool> visited(200010, false);

void dfs(ll i, ll prev_i) {
    if (visited[i]) return;
    visited[i] = true;  
    cost[i] += cost[prev_i];    
    for(auto next_i : G[i]) dfs(next_i, i);
}

signed main() {
    cin >> N >> Q;
    FOR(i, 1, N - 1) {
        ll a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(j, Q) {
        ll p, x; cin >> p >> x;
        cost[p] += x;
    }
    dfs(1, 0);
    FOR(i, 1, N) cout << cost[i] << " ";
    cout << endl;
}

Measured memory_bytes: 21120
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 char arr[12][12];
 
 void dfs(int i,int j)
 {
   arr[i][j]='0';
   //cout<<i<<" "<<j<<endl;
   int dx[4]={0,1,0,-1};
   int dy[4]={1,0,-1,0};
   for(int s=0;s<4;s++)
   {
     if((i+dx[s])>=0&&(i+dx[s])<12&&(j+dy[s])>=0&&(j+dy[s])<12&&arr[i+dx[s]][j+dy[s]]=='1')
     {
       int nx=i+dx[s];
       int ny=j+dy[s];
       dfs(nx,ny);                                                          
     }        
   }
   return;     
 }
 
 int main()
 {
   string s;
   bool flag=false;
   while(cin>>s)
   {
     int count=0;
     for(int i=0;i<12;i++) arr[0][i]=s[i];
     for(int i=1;i<12;i++)
     {
       cin>>s;
       for(int j=0;j<12;j++) arr[i][j]=s[j];
     }      
     for(int i=0;i<12;i++)
     {
       for(int j=0;j<12;j++)
       {
         if(arr[i][j]=='1')
         { 
           //cout<<"start"<<i<<" "<<j<<endl;
           dfs(i,j);
           count++;
         }        
       }        
     }         
     cout<<count<<endl;
     getline(cin,s);
   }
   //while(1);
   return 0;
 }

 

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, Q;
    cin >> N >> Q;
    typedef pair<ll, pll> plll;
    vector<plll> query;
    REP(i, N){
    	ll S, T, X;
    	cin >> S >> T >> X;
    	query.push_back({X, {S, T}});
    }
    set<pll> st;
    vector<ll> res(Q, -1);
    REP(i, Q){
    	ll D;
    	cin >> D;
    	st.insert({D, i});
    }
    sort(query.begin(), query.end());
    REP(i, N){
    	ll X = query[i].first;
    	ll S = query[i].second.first;
    	ll T = query[i].second.second;
    	auto itr = st.lower_bound({S-X, -1});
    	while(itr != st.end()){
    		ll D = itr->first;
    		ll idx = itr->second;
    		if(D > T-X-1) break;
    		res[idx] = X;
    		itr = st.erase(itr);
    	}
    }
    REP(i, Q) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 21484
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>

using namespace std;

int main(){
    int N,M;
    long long x[1000],y[1000],z[1000];
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>z[i];
    }
    
    long long ans=0;
    long long tmp[1000];
    for(int bitmask=0;bitmask<8;bitmask++){
        int signX=1;
        int signY=1;
        int signZ=1;
        if( bitmask&1 ) signX=-1;
        if( (bitmask>>1)&1 ) signY=-1;
        if( (bitmask>>2)&1 ) signZ=-1;
        for(int i=0;i<N;i++){
            tmp[i]=signX*x[i]+signY*y[i]+signZ*z[i];
        }
        sort(tmp,tmp+N);
        long long now=0;
        for(int i=N-M;i<N;i++){
            now+=tmp[i];
        }
        ans=max(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define PYES cout << "Yes" << endl
#define PNO cout << "No" << endl

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    bool ok=true;
    for(int j=0;j<i;j++){
      if(a[i]<a[j]){
        ok=false;
        break;
      }
    }
    if(ok) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    long long N, K;
    cin >> N >> K;

    if (N > K)
    {
        {
            long long amari = N % K;
            long long hamidashi = ((N / K) * K + K) - N;
            if (amari == 0)
            {
                cout << 0 << endl;
            }
            else if (amari < hamidashi)
            {
                cout << amari << endl;
            }
            else
            {
                cout << hamidashi << endl;
            }
        }
    }

    else
    {
        cout << min(K - N, N) << endl;
    }
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
from collections import deque

def solve():
    d = deque(input())
    Q = int(input())

    is_reverse = False # 反転中か？

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            _, f, c = query.split()

            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    d.append(c)
                else:
                    # 先頭にcを追加
                    d.appendleft(c)
            else:
                if is_reverse:
                    # 先頭に追加
                    d.appendleft(c)
                else:
                    # 末尾に追加
                    d.append(c)

    if is_reverse:
        print("".join(reversed(list(d))))
    else:
        print("".join(d))


def solve2():
    S = list(input())
    Q = int(input())
    M = 2*10**5+10
    data = [None]*M
    data.extend(S)
    data.extend([None]*M)
    left, right = M-1, M+len(S)

    is_reverse = False

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            t, f, c = query.split()
            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    data[right] = c
                    right += 1
                else:
                    # 先頭にcを追加
                    data[left] = c
                    left -= 1
            else:
                if is_reverse:
                    # 先頭に追加
                    data[left] = c
                    left -= 1
                else:
                    # 末尾に追加
                    data[right] = c
                    right += 1

    # 出力
    if is_reverse:
        print("".join(data[right-1:left:-1]))
        # for i in range(right-1, left, -1):
        #     print(data[i], end="")
    else:
        # for i in range(left+1, right):
        #     print(data[i], end="")
        print("".join(data[left+1:right]))
    # print()


if __name__ == "__main__":
    solve()


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

int main() {
  string s;
  cin >> s;
  int i, j;
  string res;
  for (i = 0; i < 26; i++) {
    char alpha = 'a' + i;
    for (j = 0; j < s.size(); j++) {
      if (s[j] == alpha) break;
    }
    if (j == s.size()) {
      res = alpha;
      break;
    }
  }
  if (i == 26) res = "None";
  cout << res << endl;
  return 0;
}

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

int main()
{
  int num[101] = {0};
  int n;

  while (~scanf("%d", &n)){
    num[n]++;
  }
  
  int n_max = 0;
  for (int i = 1; i <= 100; i++){
    n_max = max(n_max, num[i]);
  }

  for (int i = 1; i <= 100; i++){
    if (num[i] == n_max){
      printf("%d\n", i);
    }
  }

  return (0);
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 998244353
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

i64 mof = 1000000000000000000LL % MOD;

int N;
vector<int> edge[101010];
int grundy[101010];

vector<i64> analyze()
{
	int M;
	scanf("%d", &M);
	for (int i = 1; i <= N; ++i) edge[i].clear();
	for (int i = 0; i < M; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a > b) swap(a, b);
		edge[a].push_back(b);
	}
	grundy[N] = 0;
	for (int i = N - 1; i >= 1; --i) {
		set<int> waf;
		for (int j : edge[i]) waf.insert(grundy[j]);
		for (int j = 0;; ++j) {
			if (waf.count(j) == 0) {
				grundy[i] = j;
				break;
			}
		}
	}
	vector<i64> res(1024, 0LL);

	i64 w = 1;
	for (int i = 1; i <= N; ++i) {
		w = w * mof % MOD;
		ADD(res[grundy[i]], w);
	}
	return res;
}

int main()
{
	scanf("%d", &N);
	vector<i64> seq1 = analyze();
	vector<i64> seq2 = analyze();
	vector<i64> seq3 = analyze();
	i64 ret = 0;
	for (int i = 0; i < 1024; ++i) {
		for (int j = 0; j < 1024; ++j) {
			ADD(ret, seq1[i] * seq2[j] % MOD * seq3[i ^ j]);
		}
	}
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 5632
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		if (1 <= N && N <= 100) {
			if (0 <= M && M <= N) {
				if (M == N) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}
			}
		}
	}

}


Measured memory_bytes: 21204