akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()
len_s = len(s)
len_t = len(t)
minimum = len_t

for i in range(len_s - len_t + 1):
  replace = 0
  for j in range(len_t):
    if s[i + j] != t[j]:
      replace += 1
  if replace < minimum:
    minimum = replace

print(minimum)

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  vector<int> a(n);
  int zero = 1;
  for (auto &i : a) {
    cin >> i;
    if (i) zero = 0;
  }
  if (zero) {
    cout << "Yes" << '\n';
    return;
  }
  sort(all(a));
  if (n % 3) {
    cout << "No" << '\n';
    return;
  }
  int t = n / 3;
  for (int i = 0; i < t; i++) {
    if ((a[i] ^ a[i + t]) != a[i + t * 2]) {
      cout << "No" << '\n';
      return;
    }
    if (i && (a[i] != a[i - 1] || a[i + t] != a[i + t - 1])) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

#define ll long long
int main() {
  ll N, K;
  cin >> N >> K;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  
  ll ans = 0;
  for (ll b = K+1; b <= N; b++) {
    ans += (b-K) * (N / b);
    if ((N % b) >= K)
    ans += (N % b) - K + 1;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

// Optimized implementation of Bubble sort 
#include <stdio.h> 
  
void swap(int *xp, int *yp) 
{ 
    int temp = *xp; 
    *xp = *yp; 
    *yp = temp; 
} 
  
// An optimized version of Bubble Sort 
void bubbleSort(int arr[], int n) 
{ 
   int i, j; 
   bool swapped; 
   for (i = 0; i < n-1; i++) 
   { 
     swapped = false; 
     for (j = 0; j < n-i-1; j++) 
     { 
        if (arr[j] > arr[j+1]) 
        { 
           swap(&arr[j], &arr[j+1]); 
           swapped = true; 
        } 
     } 
  
     // IF no two elements were swapped by inner loop, then break 
     if (swapped == false) 
        break; 
   } 
} 

int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n;
    cin >> k;
    int* prices = (int*)malloc(n*sizeof(int));
    for (int i = 0; i < n; i ++)
    {
        cin >> prices[i];
    }

    bubbleSort(prices, n);

    int cnt = 0;
    for (int i = 0; i < k; i ++)
    {
        cnt += prices[i];
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3572
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    X=[int(_) for _ in input().split()]
    sum=0
    for x in X:
        if x == 1:sum+=300000
        elif x==2:sum+=200000
        elif x==3:sum+=100000
    if X[0]==X[1] and X[0]==1:
        sum+=400000
    print(sum)

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
from collections import Counter
N = int(input())
 
A=[]
for i in range(N):
    A.append(input())

B = Counter(A)

saidai = max(B.values())

C=[]
for i, j in B.items():
    if j == saidai:
        C.append(i)
C.sort()
for i in C:
    print(i)

Measured memory_bytes: 100432
n = int(input())
ls_a = [int(input()) for _ in range(n)]

ls_as = sorted(ls_a, reverse=True)
fst = ls_as[0]
snd = ls_as[1]

for i in range(n):
	if ls_a[i] != fst:
		print(fst)
	elif ls_a[i] == fst:
		print(snd)

Measured memory_bytes: 14088
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int h, w;
	while (cin >> h >> w && h > 0) {
		for (int i = 0; i < h; ++i)
			cout << string(w, '#') << endl;
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long N,A;
  int ans=0;
  cin>>N;
  for(long i=(long)sqrt(N);i>0;i--){
      if(N%i==0){
        A=N/i;
        while(A!=0){
      		ans++;
      		A=A/10;
    	}
        break;
      }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int k=0, s=0, ans=0;
  cin >> k >> s;
  
  
  rep (i, k+1) {
    rep (j, k+1){
      if (i+j <= s && s-(i+j) <= k) ++ans;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
ai_ = lambda: [int(x)-1 for x in input().split()]
ai = lambda: list(map(int, input().split()))

h,w,n = ai()
bl = [ai_() for _ in range(n)]
from collections import defaultdict
d = defaultdict(int)

from itertools import product
l = list(product((-1,0,1), repeat=2))

for a,b in bl:
    for da,db in l:
        if 0 < a+da < h-1 and 0 < b+db < w-1:
            d[(a+da, b+db)] += 1

print((h-2)*(w-2) - len(d))
ll = list(d.values())
for i in range(1, 10):
    print(ll.count(i))


Measured memory_bytes: 191972
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;
int main()
{
	int c,m=0,n;cin>>n;
	char s[105];cin>>s;
	for(int i=1;i<n;i++)
	{
		c=0;
		for(int j=0;j<26;j++)
		{
			for(int k=0;k<i;k++)
			{
				if(s[k]=='a'+j)
				{
					for(int l=i;l<n;l++)
					{
						if(s[l]=='a'+j)
						{
							c++;
							break;
						}
					}
					break;
				}
			}
		}
		m=max(m,c);
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 504
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
using namespace std;

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

class CCandles {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, k; in >> n >> k;
		int arr[n];
		f(i, n) in >> arr[i];
		int res = INT_MAX;
		rep(i, k-1, n-1){
			res = min(res, arr[i] - arr[i-k+1] + min(abs(arr[i-k+1]), abs(arr[i])));
		}
		out << res;
	}
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CCandles solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
// Brute Force Attack!
int main(int argc, char *argv[])
{
  int n, m, a, b ,c;
  cin >> n >> m >> a >> b >> c;
  vector<int> abc = {a, b, c};
  sort(abc.begin(), abc.end());
  vector<vector<bool>> step(n, vector<bool>(n, false));
  for(int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    step[u-1][v-1] = true;
  }
  a = abc[0];
  b = abc[1];
  c = abc[2];
  vector<vector<bool>> arch(n,vector<bool>(n));
  vector<vector<bool>> brch(n,vector<bool>(n));
  vector<vector<bool>> crch(n,vector<bool>(n));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      arch[i][j] = i == j;
      brch[i][j] = i == j;
      crch[i][j] = i == j;
    }
  }
  auto mul = [](int n, vector<vector<bool>> &z, vector<vector<bool>> &y) {
    bool t[n][n];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        bool c = false;
        for(int k = 0; k < n; k++) {
          c = c || (z[i][k] && y[k][j]);
        }
        t[i][j] = c;
      }
    }
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        z[i][j] = t[i][j];
      }
    }
  };
  // c is the biggest
  while(c != 0) {
    if(a & 1) { // arch *= step
      mul(n, arch, step);
    }
    if(b & 1) { // brch *= step
      mul(n, brch, step);
    }
    if(c & 1) { // crch *= step
      mul(n, crch, step);
    }
    mul(n, step, step);
    a >>= 1;
    b >>= 1;
    c >>= 1;
  }
  
  // arch: a-step reachable
  // brch: b-step reachable
  // crch: c-step reachable

  vector<int> ok(n, -1);
  ok[n-1] = 0; // the goal is ok

  auto reachable = [&ok,&n](const vector<vector<bool>> &rch, int i){
    for(int j = 0; j < n; j++) {
      if(rch[i][j] && (ok[j] >= 0)) return true;
    }
    return false;
  };
  
  auto search = [&]() {
    bool done = false;
    int ss = 0;
    while(!done) {
      ss++;
      done = true;
      vector<int> ok2(n, -1);
      for(int i = 0; i < n; i++) {
        // if i has a-reachable ok, b-reachable ok, and c-reachable ok vertives,
        // then i is also ok
        if(ok[i] < 0 && reachable(arch, i) && reachable(brch, i) && reachable(crch, i)) {
          ok2[i] = ss;
          if(i == 0) {
            ok[i] = ok2[i];
            return;
          }
          done = false;
        }
      }
      for(int i = 0; i < n; i++) {
        ok[i] = ok2[i] >= 0 ? ok2[i] : ok[i];
      }
    }
  };
  search();
  if(ok[0] < 0) cout << "IMPOSSIBLE" << endl;
  else cout << ok[0] << endl;
  return 0;
}



Measured memory_bytes: 3152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };





#define fs  first
#define sc  second


int main() {
	ll n, a, b, c, d;

	cin >> n >> a >> b >> c >> d;
	n--;

	bool f = false;
	reP(i, n) {
		ll x = a + c*i - d*(n - i);
		ll y = a + d*i - c*(n - i);
		//cerr << x << " " << y << endl;
		if (x <= b&& b <= y) {
			f = true; break;
		}
	}
	cout << (f ? "YES" : "NO") << endl;
}
/*
1 1


1


*/

Measured memory_bytes: 256
INF = 10**10

H, W = map(int,input().split())

res = INF
if H % 3 == 0 or W % 3 == 0:
	res = 0

def cmp1(cH, cW):
	res = INF
	for w1 in range(1, cW - 2 + 1):
		w2 = (cW - w1) // 2
		w3 = cW - w1 - w2
		s1 = cH * w1
		s2 = cH * w2
		s3 = cH * w3
		minS = min(s1, min(s2, s3))
		maxS = max(s1, max(s2, s3))
		res = min(res, maxS - minS)
	return res

def cmp2(cH, cW):
	res = INF
	w = cW // 2
	for h in range(1, cH):
		s1 = h * cW
		s2 = (cH - h) * w
		s3 = (cH - h) * (cW - w)
		minS = min(s1, min(s2, s3))
		maxS = max(s1, max(s2, s3))
		res = min(res, maxS - minS)
	return res

res = min(res, cmp1(H,W))
res = min(res, cmp1(W,H))
res = min(res, cmp2(H,W))
res = min(res, cmp2(W,H))

print(res)



Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>
 
int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld %ld", &n, &k );
 
    if(k%2==0) {
        long k2 = k / 2;
        long m = n / k2;
        long a = m / 2;
        long b = m - a;
        long long ans = (long long)a*a*a + (long long)b*b*b;
        printf("%lld\n", ans);
    }
    else {
        long m = n / k;
        long long ans = (long long)m*m*m;
        printf("%lld\n", ans);
    }
 
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

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


int main() {
	int N;
	cin >> N;
	ll ans = 0;
	vector<int>d(N);
	rep(i, N)cin >> d[i];
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {

			ans+=d[i] * d[j];
		}
	}
	cout << ans;
}


Measured memory_bytes: 3148
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N = int(input())
A = list(map(int, input().split()))

odd = False
for i in range(len(A)):
    if A[i] < 0:
        A[i] *= -1
        odd = not odd

if odd:
    print(sum(A) - min(A) * 2)
else:
    print(sum(A))


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int[] counter = new int[26];
            long total = 1;
            int i;

            for (i = 0; i < n; ++i)
            {
                ++counter[s[i] - 'a'];
            }
            for (i = 0; i < 26; ++i)
            {
                total *= (counter[i] + 1);
                total %= 1000000007;
            }
            Console.WriteLine(total - 1);
        }
    }
}


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

int mochi = 10000;
int n;
int c = 0;
std::vector<int> vec;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        std::cin >> t;
        vec.push_back(t);
    }
    std::sort(vec.begin(), vec.end());
    std::reverse(vec.begin(), vec.end());
    for (int i = 0; i < n; i++) {
        if (vec[i] < mochi) {
            c++;
            mochi = vec[i];
        }
    }
    std::cout << c << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N;
int fr[100005];
int a;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>a;
        if(a)fr[a-1]++;
        fr[a]++;
        fr[a+1]++;
    }
    int rez=0;
    for(int i=1;i<=100000;i++)
    {
        if(fr[i]>fr[rez])rez=i;
    }
    cout<<fr[rez];
    return 0;
}


Measured memory_bytes: 640
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int n, m;
	cin >> n >> m;
	queue<pair<string, int> > q;
	vector<pair<string, int> > ans;
	for(int i = 0; i < n; i++){
		string s;int t;
		cin >> s >> t;
		q.push({s, t});
	}
	int elapsed = 0;
	while(!q.empty()){
		auto u = q.front();
		q.pop();
		if(u.second <= m){
			elapsed += u.second;
			ans.push_back({u.first, elapsed});
		}else{
			int rem = u.second - m;
			elapsed += m;
			q.push({u.first, rem});
		}
	}
	for(auto i:ans)cout << i.first << ' ' << i.second << '\n';
	return 0;
}



Measured memory_bytes: 6912
<?php
list($h, $w) = ints();
list($n) = ints();
$a = ints();
$c = 0;
for ($i = 0; $i < $n; ++$i) {
    for ($j = 0; $j < $a[$i]; ++$j) {
        $l = intdiv($c, $w);
        $m = $c % $w;
        if ($l % 2) $m = $w - 1 - $m;
        $ans[$l][$m] = $i + 1;
        $c++;
    }
}
for ($i = 0; $i < $h; ++$i) {
    for ($j = 0; $j < $w; ++$j) {
        echo $ans[$i][$j];
        echo $j < $w - 1 ? ' ' : PHP_EOL;
    }
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;cin>>a>>b;
    if(a<=0 && 0<=b){
        cout<<"Zero"<<endl;
        return 0;
    }else{
        if(a<0 && b<0){
            if(a==b){
                cout<<"Positive"<<endl;
                return 0;
            }else if(abs(b-a)%2==0){
                cout<<"Negative"<<endl;
                return 0;
            }else{
                cout<<"Positive"<<endl;
                return 0;
            }
        }else{
            cout<<"Positive"<<endl;
            return 0;
        }
    }
    
}

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

static vector<long long> adj[100005];
static long long arr[100005];

long long dfs(long long u, long long p){
	if(adj[u].size() == 1) return arr[u];
	long long rope = 0;
	long long maxChildRope = 0;
	for(long long v : adj[u]){
		if(v == p) continue;
		long long childRope = dfs(v,u);
		rope += childRope;
		maxChildRope = max(maxChildRope, childRope);
	}

	long long connect = rope - arr[u];
	long long maxConnect = min(rope / 2, rope - maxChildRope); 
	rope = rope - 2 * connect;
	if(connect < 0 || rope < 0 || connect > maxConnect){
		cout << "NO";
		exit(0);
	}
	return rope;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long n; cin >> n;
	for(long long i = 1;i <= n;i++) cin >> arr[i];
	for(long long i = 1;i < n;i++){
		long long a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	} 
	for(long long i = 1;i <= n;i++){
		if(adj[i].size() != 1){
			if(dfs(i,0) == 0) cout << "YES";
			else cout << "NO";
			return 0;
		}
	}
	if(arr[1] == arr[2]) cout << "YES";
	else cout << "NO";
}


Measured memory_bytes: 11904
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int n_max;
  int n_min = 1000;
  int a;
  
  for (int kaisuu = 0;kaisuu <= N;kaisuu++){
    cin >> a;
  if (a%2==0){
    for (int n=1;a%2==0;n++){
    a = a/2;
    n_max = n;
  }
    //cout << n_max <<"\n";
  }
    if (n_max < n_min){
      n_min = n_max;
    }
  }
  cout << n_min <<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
  int N,K,pointtotal = 0;
  cin >> N >> K;
  vector<int> point(3);
  cin >> point.at(0) >> point.at(1) >> point.at(2);
  string s;
   cin >> s;
  vector<char> command;
  froop1(0,N){
    if(i < K){
	if(s[i] == 'r'){
    	command.push_back('p');
      pointtotal += point.at(2);
    }else if(s[i] == 's'){
      command.push_back('r');
      pointtotal += point.at(0);
    }else{
      command.push_back('s');
      pointtotal += point.at(1);
    }
    }else{
    if(s[i] == 'r'){
      if(command.at(i - K) == 'p'){
        command.push_back(' ');
        continue;
      }
    	command.push_back('p');
      pointtotal += point.at(2);
    }else if(s[i] == 's'){      
      if(command.at(i - K) == 'r'){
        command.push_back(' ');
        continue;
      }
      command.push_back('r');
      pointtotal += point.at(0);
    }else{
        if(command.at(i - K) == 's'){
        command.push_back(' ');
        continue;
      }
      command.push_back('s');
      pointtotal += point.at(1);
    }
    }
  }
  cout << pointtotal << endl;
    
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
string s,t,u;
int ans,n; 
int main()
{
	cin>>n>>s>>t>>u;
	for(int i=0;i<n;i++)
	{
		int sum=0;
		if(s[i]!=t[i])
			sum++;
		if(s[i]!=u[i])
			sum++;
		if(u[i]!=t[i])
			sum++;
		if(s[i]==u[i]&&s[i]==t[i]&&t[i]==u[i])
			ans+=0;
		else
			ans=ans+sum-1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,n,a[100];

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

  for(i = n - 1;i >= 0;--i){
    printf("%d",a[i]);
    if(i != 0){
      printf(" ");
    }
  }
  printf("\n");

  return 0;
}



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

int main() {
  int n, m, l;
  cin >> n >> m >> l;

  // 行列A
  vector<vector<ll>> matrix_a(n, vector<ll>(m, 0));
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < m; y++) {
      cin >> matrix_a.at(x).at(y);
    }
  }

  // 行列B
  vector<vector<ll>> matrix_b(m, vector<ll>(l, 0));
  for (int x = 0; x < m; x++) {
    for (int y = 0; y < l; y++) {
      cin >> matrix_b.at(x).at(y);
    }
  }

  // 行列C
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < l; y++) {
      ll sum = 0;
      for (int k = 0; k < m; k++) {
        sum += matrix_a.at(x).at(k) * matrix_b.at(k).at(y);
      }
      cout << sum;

      if (y < l - 1) { cout << " "; }
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3264
import sys
input=sys.stdin.readline
from operator import itemgetter
n,q=map(int,input().split())
c=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  l[i].append(i)
l.sort(key=itemgetter(1))

L=[-1]*(5*10**5+1)

class Bit:
  def __init__(self,n):
    self.size=n
    self.tree=[0]*(n + 1)
    self.depth=n.bit_length()

  def sum(self,i):
    s=0
    while i>0:
      s+=self.tree[i]
      i-=i&-i
    return s

  def add(self,i,x):
    while i<=self.size:
      self.tree[i]+=x
      i+=i&-i

BIT=Bit(n+1)

ans=[0]*q
ct=0
for i in range(q):
  while ct<=l[i][1]:
    if L[c[ct-1]-1]!=-1:
      BIT.add(L[c[ct-1]-1],-1)
    L[c[ct-1]-1]=ct+1
    BIT.add(ct+1,1)
    ct+=1
  ans[l[i][2]]=BIT.sum(l[i][1]+1)-BIT.sum(l[i][0])

for i in range(q):
  print(ans[i])

Measured memory_bytes: 233820
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

string L;
int mod = 1e9 + 7;

int main() {
    cin >> L;
    int F = 1, T = 0;
    for (int i = 0; i < L.size(); i++) {
        if (L[i] == '0') {
            T = 3LL * T % mod;
        } else {
            T = (3LL * T + F) % mod;
            F = 2LL * F % mod;
        }
    }
    cout << (T + F) % mod << endl;
}



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

typedef long double ld;
typedef long long ll;

using namespace std;

const ll p = 998244353;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
   // freopen("input.txt", "r", stdin);
    cout << setprecision(20);
    int n;
    cin >> n;
    vector<int> a(n, 0);
    int det;
    cin >> det;
    a[det]++;
    for (int i = 1; i < n; i++) {
        int x;
        cin >> x;
        a[x]++;
    }

    if (a[0] != 1 || det != 0) {
        cout << "0";
        return 0;
    }
    ll ans = 1;
    for (int i = 1; i < n; i++) {
        ll pw = 1;
        for (int j = 0; j < a[i]; j++) {
            pw *= a[i - 1];
            pw %= p;
        }
        ans *= pw;
        ans %= p;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 640
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 100005
#define maxC 2005
#define oo 1000000007
#define sz(a) (int)a.size()
#define EPS 1e-11

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, k, c, t[maxN];

int main () {
    scanf("%d%d%d", &n, &c, &k);
    fto(i, 1, n) scanf("%d", &t[i]);
    sort(t+1, t+n+1);

    int ans = 1, last = 1;
    fto(i, 2, n) {
        if (i == last+c || t[i] > t[last]+k) {
            ++ans;
            last = i;
        }
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 640
n, k = [int(e) for e in input().split()]
r, s, p = [int(e) for e in input().split()]
t = input()
t1 = list()
for i in t:
    if i =='r':
        t1.append('p')
    elif i =='p':
        t1.append('s')
    else:
        t1.append('r')
t2=list()
for j,i in  enumerate(t1):
    if j < k:
        t2.append(i)
    else:
        if i == t2[j-k]:
            t2.append('x')
        else:
            t2.append(i)

num = 0

num += t2.count("r")*r
num += t2.count("s")*s
num += t2.count("p")*p

print(num)

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

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream source)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public string[] StringArray()
    {
        Next();
        Index = S.Length;
        return S.ToArray();
    }
    public int[] IntArray(int index)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public int[] IntArray()
    {
        return StringArray().Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public long[]LongArray()
    {
        return StringArray().Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private int N;
    private long[] a;

    private void Scan()
    {
        var cin = new Scanner(Console.OpenStandardInput());
        N = cin.NextInt();
        a = cin.LongArray();
    }

    public void Solve()
    {
        Scan();
        Array.Sort(a);
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            int index = N * 3 - (i + 1) * 2;
            ans += a[index];
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 46088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
#define y1			fafa____
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);puts("");}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);puts("");}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);puts("");}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=110;
ll c[N],n;
bool Check(){
	ll mx=n;for(;!c[mx];--mx);
	ll mid=(mx+1)/2;
	rep(i,0,mid)if (c[i])return 0;
	if (c[mid]!=mx%2+1)return 0;
	For(i,mid+1,mx)if (c[i]<2)return 0;
	return 1;
}
int main(){
	n=read();For(i,1,n)++c[read()];
	puts(Check()?"Possible":"Impossible");
}

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

int main() {
  int N;
  int flag = 0;
  std::string str;
  std::cin >> N;
  std::cin >> str;
  if (str.size() % 2 == 1) {
    flag = 1;
  }
  else {
    for (int i = 0; i < str.size()/2; i++) {
      if (str.at(i) != str.at(i + str.size()/2)) {
        flag = 1;
        break;
      }
    }
  }
  
  if (flag) {
    std::cout << "No" << std::endl;
  }
  else {
    std::cout << "Yes" << std::endl;
  }
}

Measured memory_bytes: 384
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  for(j=2;j<=n;j++)
    {
      key=A[j];
      i=j-1;
      while(i>0&&A[i]>key)
	{
	  A[i+1]=A[i];
	  i=i-1;

	  A[i+1]=key;


 }
      trace(A,n);
   }
  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


vll v[100010];
ll vis[100010];

void dfs(ll u)
{
    vis[u]=1;
    for(ll i:v[u])
    {
        if(!vis[i])
            dfs(i);
    }
}



int main()
{
    ll n,m;
    cin>>n>>m;
    for(ll i =0; i<m; i++)
    {
        ll a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    ll ans=-1;
    for(ll i=1; i<=n; i++)
    {
        if(!vis[i])
            dfs(i),ans++;
    }

    cout<<ans<<nn;




}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






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

int main(){
    double a,b;
    int ans;
    cin >> a >> b;
    int A1=int(a*12.5+0.5);
    int A2=int((a+1)*12.5+0.5);
    int B1=int(b*10);
    int B2=int((b+1)*10);
    if(A2 <= B1 or B2 <= A1){
        ans = -1;
    }else{
        ans = max(A1,B1);
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
    ll n;cin>>n;
    string str;cin>>str;
    ll i,j,cc=0;
    for(i=0;i<str.size();i++){
        string s=str.substr(i,3);
        //cout<<s<<endl;
        if(s=="ABC")cc++;
    }
    cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 4992
import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by vikas.k on 26/12/16.
 */
public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        long n = sc.nextLong();
        long x = sc.nextLong();

        long a = x;
        long b = n-x;

        if(b > a){
            b = x;
            a = n-x;
        }
        long ans = n;
        while(b!=0){
            ans+= b*2*(a/b);
            long tmp = a%b;
            a=b; b=tmp;
        }
        ans-=a;
        out.println(ans);
        out.close();
    }

    public static PrintWriter out;

    private static class MyScanner{
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private MyScanner(){
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next(){
            if(stringTokenizer == null || !stringTokenizer.hasMoreElements()){
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt(){
            return Integer.parseInt(next());
        }
        private long nextLong() { return Long.parseLong(next()); }
        private String nextLine(){
            String ret= "";
            try {
                ret= bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }
}


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

long long n,a,b;

long long f(long long x){
	return (a*x)/b-a*(x/b);
}

int main(){

	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>a>>b>>n;
	
	cout<<f(min(b-1,n))<<"\n";

return 0;
}


Measured memory_bytes: 3556
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define int long long
int n,sz[100100],u[100100],v[100100],D;
struct node{
	int dis,x;
	bool operator<(node b)const{
		return dis>b.dis;
	}
}a[100100];
map<int,int>mp;
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i].dis);
		a[i].x=i;
		mp[a[i].dis]=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)sz[i]=1;
	for(int i=1;i<n;i++){
		int dis=a[i].dis,x=a[i].x;
		int tmp=dis-abs(n-2*sz[x]);
		int fa=mp.find(tmp)->second;
		if(fa==x||!fa)return puts("-1"),0;
		sz[fa]+=sz[x];
		D+=sz[a[i].x];
		u[i]=x,v[i]=fa;
	}
	if(D!=a[n].dis)return puts("-1"),0;
	for(int i=1;i<n;i++)
		printf("%lld %lld\n",u[i],v[i]);
}

Measured memory_bytes: 13392
//****** @author mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p);
int n,m;
char a[21][21];
map<pair<int,int>,int >mp;
int bfs(int sx,int sy){
    queue<pair<int,int>> q;
    q.push({sx,sy});
    int count=0;
    bool visited[n][m];
    memset(visited,0, sizeof(visited));
    int matrix[n][m];
    for(int i=0;i<n;i++)for(int j=0;j<m;j++)matrix[i][j]=10000;
    matrix[sx][sy]=0;
    int mx=0;
    while(!q.empty()){
        int size=q.size();
        for(ll i=0;i<size;i++){
            pair<int,int> x=q.front();q.pop();
            sx=x.F;sy=x.S;
            visited[sx][sy]=true;
            matrix[sx][sy]=min(matrix[sx][sy],count);
            mx=max(mx,matrix[sx][sy]);
            if(sx+1<n && !visited[sx+1][sy] && a[sx+1][sy]!='#'){
                q.push({sx+1,sy});
            }
            if(sx-1>=0 && !visited[sx-1][sy] && a[sx-1][sy]!='#'){
                q.push({sx-1,sy});
            }

            if(sy+1<m && !visited[sx][sy+1] && a[sx][sy+1]!='#'){
                q.push({sx,sy+1});
            }

            if(sy-1>=0 && !visited[sx][sy-1] && a[sx][sy-1]!='#'){
                q.push({sx,sy-1});
            }
        }
        count++;
    }
    return mx;
}

void solve() {
    cin>>n>>m;
    for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)cin>>a[i][j];
    int ans=0;
    ll count=0;
    bool flag=true;
    for(ll i=0;i<n;i++)for(ll j=0;j<m;j++){
        if(a[i][j]=='#')flag=false;
    }
    if(flag){
        cout<<n+m-2<<endl;
        return;
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if(a[i][j]=='.'){
                ans=max(ans,bfs(i,j));
                count++;
            }
        }
    }
    cout<<ans<<endl;

}

int main()
{
    IOS;
    ll test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <valarray>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int a, b, c, d, x, y;
	cin >> a >> b >> c >> d;
	x = d - b;
	y = c - a;
	cout << c - x << " " << d + y << " " << a - x << " " << b + y << endl;
}

Measured memory_bytes: 256
mod=10**9+7
l='0'+input()
d=len(l)-1
DP=[[0]*2 for _ in range(d+1)] #DP[上からi桁目][0:less,1:equal]
DP[0][1]=1
for i in range(1,d+1):
    bit=int(l[i])
    if bit:
        DP[i][0]=(DP[i-1][0]*3+DP[i-1][1])%mod
        DP[i][1]=(DP[i-1][1]*2)%mod
    else:
        DP[i][0]=DP[i-1][0]*3%mod
        DP[i][1]=DP[i-1][1]
print((DP[-1][0]+DP[-1][1])%mod)

Measured memory_bytes: 19700
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e10;
int main(){
    int n, k;
    string s;
    cin >> n >> s >> k;
    k--;
    rep(i,n)cout << ((s[i] != s[k])?'*':s[i]);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>

using namespace std;


int key[500000];
int left[500000];
int right[500000];
int root = -1;
int numOfNodes = 0;

void printInOrder(int i) {
	if (i == -1) {
		return;
	}
	printInOrder(left[i]);
	printf(" %d", key[i]);
	printInOrder(right[i]);
}

void printPreOrder(int i) {
	if (i == -1) {
		return;
	}
	printf(" %d", key[i]);
	printPreOrder(left[i]);
	printPreOrder(right[i]);
}

void insert(int k) {
	if (root == -1) {
		root = 0;
		key[root] = k;
		left[root] = -1;
		right[root] = -1;
		++numOfNodes;
		return;
	}

	int y;
	int x = root;
	while (x != -1) {
		y = x;
		if (k < key[x]) {
			x = left[x];
		}
		else {
			x = right[x];
		}
	}

	key[numOfNodes] = k;
	left[numOfNodes] = -1;
	right[numOfNodes] = -1;

	if (k < key[y]) {
		left[y] = numOfNodes++;
	}
	else {
		right[y] = numOfNodes++;
	}
}

void find(int k) {
	if (root == -1) {
		printf("no\n");
		return;
	}

	int x = root;
	while (x != -1) {
		if (k == key[x]) {
			printf("yes\n");
			return;
		}
		else if (k < key[x]) {
			x = left[x];
		}
		else {
			x = right[x];
		}
	}
	printf("no\n");
}

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

	char s[19];
	for (int i = 0; i < m; i++) {
		scanf("%s", s);

		if (s[0] == 'i') {
			scanf("%s", s);
			insert(atoi(s));
		}
		else if (s[0] == 'f') {
			scanf("%s", s);
			find(atoi(s));
		}
		else {
			printInOrder(root);
			printf("\n");
			printPreOrder(root);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 6128
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e8 ;
int main()
{
    ll n;
    cin>>n;
    vector< ll > ara(n+1);
    ll i,s=0,k;
    for(i=0;i<n;i++)
        cin>>ara[i];
    for(i=0;i<n-1;i++){
        if(ara[i]>ara[i+1])
        {
            k=ara[i]-ara[i+1];
            s+=k;
            ara[i+1]=ara[i];
        }
    else
        continue;
    //cout<<s<<endl;

    }
    cout<<s<<endl;

    return 0;
}



Measured memory_bytes: 4816
/**
   Solution by Abil
**/
# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7);

int arr[N],pw[N];
map<int,int > mp,mp1;
main()
{
   pw[0] = 1;
   for(int i = 1;i <= 34; i++){
    pw[i] = pw[i - 1] * 2;
   }
   int n;
   cin >> n;
   for(int i = 1;i <= n; i++){
    cin >> arr[i];
    mp[arr[i]]++;
    mp1[arr[i]]++;
   }
   sort(arr + 1,arr + n + 1);
   int ans = 0;
   for(int i = n;i >= 1; i--){
       for(int j = 0;j <= 31; j++){
         int val = pw[j] - arr[i];
        if(val > 0){
           if(val == arr[i] && mp[val] <= 1){
            continue;
           }
           if(mp[val] >= 1 && mp[arr[i]] > 0){
              mp[val]--;
              mp[arr[i]]--;
              ans++;
              break;
           }
         }
       }
   }
   cout << ans;
}


Measured memory_bytes: 67712
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n;
  cin >> n;
  string ans = "No";
  FOR(i, 1, 10) {
    if(n % i == 0 && n / i <= 9) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,k;
unordered_map<long long,int> m;
int main()
{
	cin>>n>>k;
	for(long long i=2;i*i<=k;i++)
		while(k%i==0)k/=i,m[i]++;
	if(k!=1)m[k]++;
	long long ans=1;
	for(auto x:m)
		for(int i=0;i<x.second/n;i++)ans*=x.first;
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define c(n) cout<<n<<endl;
signed main(){
	int a,b;
	cin>>a>>b;
	c(6-a-b)
}	
			

Measured memory_bytes: 256