akhauriyash/Code-Regression huggingface dataset:
import math
 
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=0
b=0
c=0
d=s[1]
t.sort(reverse=True)
if s[0]==1:
  for i in range(s[1]):
    t[0]=math.floor(t[0]/2)
else:
  c=t[0]/2
  for j in range(s[1]):
    for l in range(s[0]):
      if d>0:
        if c<t[l]:
          t[l]=math.floor(t[l]/2)
          d=d-1
        else:
            t.sort(reverse=True)
            c=t[0]/2
            break
      else:
        break
e=sum(t)
print(e)

Measured memory_bytes: 15020
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        double r = sc.nextDouble();
        double pi = Math.PI;
        
        double s = r * r * pi;
        double l = 2 * r * pi;

        System.out.printf("%f %f", s, l);
        sc.close();
    }
}


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

int main() {
  long long mod = 1000000007;
  vector<long long> ki(2001);
  vector<long long> kii(2001);
  ki[0] = 1;
  kii[0] = 1;
  long long lll;
  long long llc;
  for (int i=1; i<=2000; i++) {
    ki[i] = ki[i-1] * i % mod;
    lll = ki[i];
    for (int j=0; j<9; j++) {
      llc = lll;
      for (int k=0; k<9; k++) {
        lll *= llc;
        lll %= mod;
      }
    }
    
    for (int j=0; j<5; j++) {
      lll *= ki[i];
      lll %= mod;
    }
    kii[i] = lll;
    kii[i] %= mod;
  }
  
  
  
  int N,K;
  cin >> N >> K;
  long long ans = 0;
  for (int i=1; i<=K; i++) {
    ans = 0;
    if (N-K < i-1) {
      cout << 0 << endl;
      continue;
    }
    if (i != 1) {
      ans += ki[N-K-1] * kii[i-2] % mod * kii[N-K-i+1] % mod;
    }
    else if (N-K == 0) {
      cout << 1 << endl;
      continue;
    }
    if (N-K > i-1) {
      ans += ki[N-K-1] * kii[i-1] % mod * kii[N-K-i] % mod * 2;
    }
    if (N-K > i) {
      ans += ki[N-K-1] * kii[i] % mod * kii[N-K-i-1] % mod;
    }
    ans %= mod;
    ans *= ki[K-1] % mod * kii[i-1] % mod * kii[K-i] % mod;
    ans %= mod;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int z=0;
		boolean ans=true;
		while(z<N){
			A[z]=stdIn.nextInt();
			z++;
		}z=N-1;
		while(z>0){
			if(A[z]<A[z-1])
				if(A[z-1]-A[z]==1)
					A[z-1]--;
				else{
					ans=false;
					break;
				}
			z--;
		}
		if(ans)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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


const double EPS = 1e-10;

typedef complex<double> Point;
#define X real()
#define Y imag()

struct Segment {
  Point p1, p2;
  Segment(){};
  Segment(Point p1, Point p2) : p1(p1), p2(p2) {};
};
typedef Segment Line;

double dot(Point a, Point b){return real(conj(a) * b);}
double cross(Point a, Point b){return imag(conj(a) * b);}

string ccw(Point a, Point b, Point c) {
  Point x = b - a;
  Point y = c - a;
  if(cross(x, y) > EPS) return "COUNTER_CLOCKWISE";
  if(cross(x, y) < -EPS) return "CLOCKWISE";
  if(dot(x, y) < -EPS) return "ONLINE_BACK";
  if(norm(x) < norm(y)) return "ONLINE_FRONT";
  return "ON_SEGMENT";
}


int main() {
  int a,b,c,d,q;
  cin>>a>>b>>c>>d>>q;
  Point p0(a,b), p1(c,d);
  for(int i=0;i<q;++i){
    int e,f;
    cin>>e>>f;
    Point p2(e,f);
    cout<<ccw(p0,p1,p2)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
 
int main(){
  string s,t;
  cin >> s >> t;
  long sn = s.size();
  long tn = t.size();
  map<char,int> moji;
  vvi str(26,vi(0));
  int id;
  rep(i,sn){
    if(!moji.count(s.at(i))){
    moji[s.at(i)] = i;
    }
    id = s.at(i) - 'a';
    str.at(id).push_back(i);
  }
  rep(i,tn){
    if(!moji.count(t.at(i))){
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> data(tn);
  id = t.at(0) - 'a';
  data.at(0) = str.at(id).at(0);
  char tmp;
  set<char> tev;
  tev.insert(t.at(0));
  int ppp;
  for(int i=1;i<tn;i++){
    tmp = t.at(i);
    id = tmp - 'a';
    if(1){
      ppp = str.at(id).size();
      if(data.at(i-1) >= str.at(id).at(ppp-1)){
        data.at(i) = str.at(id).at(0);
      }else{
        data.at(i) = *upper_bound(str.at(id).begin(), str.at(id).end(),data.at(i-1));
      }
    }
    //data.at(i) = moji.at(t.at(i));
  }
  
  long count = 0;
  for(int i=1;i<tn;i++){
    if(data.at(i-1) >= data.at(i)){
      count++;
    }
  }
  //rep(i,tn) cout << data.at(i) << endl;
  //cout << count << endl;
  //rep(i,tn) cout << data.at(i) << endl;
  long answer = sn*count + data.at(tn-1)+1;
  cout << answer << endl;
  //cout << str.at(t.at(2)-'a').at(ppp-1) << endl;
}

Measured memory_bytes: 1468
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 200005
int n, k, l;
int tar[2 * N], nex[2 * N], fir[N], cnt;
int bel[N], sum[N], ans[N], stk[N], vis[N], top;
int Getbel(int x)
{
	if (!bel[x])
		return x;
	return bel[x] = Getbel(bel[x]);
}
void add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
void dfs(int r)
{
	vis[r] = 1;
	stk[++top] = r;
	for (int i = fir[r]; i; i = nex[i])
	{
		int v = tar[i];
		if (!vis[v])
			dfs(v);
	}
}
int main()
{
	scanf("%d%d%d", &n, &k, &l);
	for (int i = 1; i <= k; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a = Getbel(a), b = Getbel(b);
		if (a != b)
			bel[a] = b;
	}
	for (int i = 1; i <= l; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		add(a, b), add(b, a);
	}
	for (int i = 1; i <= n; i++)
	{
		if (!vis[i])
		{
			dfs(i);
			for (int j = 1; j <= top; j++)
				sum[Getbel(stk[j])]++;
			for (int j = 1; j <= top; j++)
				ans[stk[j]] = sum[Getbel(stk[j])];
			for (int j = 1; j <= top; j++)
				sum[Getbel(stk[j])]--;
			top = 0;
		}
	}
	for (int i = 1; i <= n; i++)
		printf("%d%c", ans[i], i == n ? 10 : 32);
}


Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

//parent[i]:ノード番号iの親のノード番号
//親が存在しないときは-(属するグループのサイズ)を格納
//parent = vector<int>(N, -1);で初期化
vector<int> parent;
//ノードXの根を返す
int root(int X){
	if(parent[X] < 0)return X;
	return parent[X] = root(parent[X]);
}
//ノードXが属するグループのサイズ(属するノード数)を返す
int size(int X){
	return -parent[root(X)];
}
//Xの属するグループとYの属するグループを繋ぐ
//それぞれの根どうしを繋ぐ
bool connect(int X, int Y){
	//根同士をつなぐため指すノードを根にする
	X = root(X);
	Y = root(Y);
	//すでに繋がっているときは繋がずにfalseを返す
	if(X == Y){
		return false;
	}
	//大きいほうに小さいほうを繋ぎたいので逆ならスワップ
	if(size(X) < size(Y))swap(X, Y);
	//繋がれる方のサイズを更新
	parent[X] += parent[Y];
	//繋ぐ方の親を設定
	parent[Y] = X;
	return true;
}
int main(){

	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0 && H == 0)break;
		vector<vector<int>> C(H, vector<int>(W));
		int landNum = 0;
		for(int i = 0; i < H; i ++){
			for(int j = 0; j < W; j ++){
				cin >> C[i][j];
				if(C[i][j] == 1)landNum ++;
			}
		}
		parent = vector<int>(H * W, -1);
		for(int i = 0; i < H; i ++){
			for(int j = 0; j < W; j ++){
				if(C[i][j] == 1){
					if(i + 1 < H && C[i + 1][j] == 1)connect((i + 1) * W + j, i * W + j);
					if(i - 1 >= 0 && C[i - 1][j] == 1)connect((i - 1) * W + j, i * W + j);
					if(j + 1 < W && C[i][j + 1] == 1)connect(i * W + (j + 1), i * W + j);
					if(j - 1 >= 0 && C[i][j - 1] == 1)connect(i * W + (j - 1), i * W + j);
					if(i + 1 < H && j + 1 < W && C[i + 1][j + 1] == 1)connect((i + 1) * W + (j + 1), i * W + j);
					if(i + 1 < H && j - 1 >= 0 && C[i + 1][j - 1] == 1)connect((i + 1) * W + (j - 1), i * W + j);
					if(i - 1 >= 0 && j + 1 < W && C[i - 1][j + 1] == 1)connect((i - 1) * W + (j + 1), i * W + j);
					if(i - 1 >= 0 && j - 1 >= 0 && C[i - 1][j - 1] == 1)connect((i - 1) * W + (j - 1), i * W + j);
				}
			}
		}
		map<int, int> m;
		for(int i = 0; i < H; i ++){
			for(int j = 0; j < W; j ++){
				if(C[i][j] == 1)m[root(i * W + j)] ++;
			}
		}
		int ans = 0;
		for(auto itr = m.begin(); itr != m.end(); itr ++){
			if(itr -> second > 0)ans ++;
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int a[5];
bool cmp(int a,int b) { return a>b; }
int main()
{
	scanf("%s",s); for(int i=0;i<strlen(s);i++) a[s[i]-'a']++;
	bool f=1; sort(a,a+3,cmp);
	if(a[0]-a[1]>1||a[0]-a[2]>1) f=0;
	puts(f?"YES":"NO");
	return 0;
}

Measured memory_bytes: 384
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import heapq

import logging
logging.basicConfig(level=logging.DEBUG)

import sys
input = sys.stdin.readline().rstrip

setrecursionlimit(1000000)

MOD = 10**9+7
INF = float('inf')

def main():
    S=input()

    dp = [[0] * 13 for _ in range(len(S)+1)] # 0の行＋桁数
    dp[0][0]=1
    for k in range(len(S)):
        c=S[k]
        #print(c)
        if c=="?":
            for i in range(13):
                for j in range(10):
                    dp[k+1][(i*10+j)%13]+=dp[k][i]
                    dp[k+1][(i*10+j)%13]%=MOD
        else:
            for i in range(13):
                dp[k+1][(i*10+int(c))%13]+=dp[k][i]
                dp[k+1][(i*10+int(c))%13]%=MOD
    #print(dp)
    print(dp[len(S)][5])

main()

Measured memory_bytes: 91864
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
using namespace std;
static const int MAX_N = 1000000;
 
int n, k;
int a [MAX_N];
 
int b[MAX_N];
int deq[MAX_N];
 
void solve(){
  int s = 0, t = 0;
 
  for ( int i = 0; i < n; i++ ){
    while( s < t && a[deq[t - 1]] >= a[i] ) t--;
    deq[t++] = i;
 
    if ( i - k + 1 >= 0 ){
      b[i - k + 1] = a[deq[s]];
 
      if ( deq[s] == i - k + 1 ){
        s++;
      }
    }
  }
 
  for ( int i = 0; i <= n-k; i++ ){
    if ( i ) printf(" ");
    printf("%d", b[i]);
  }
  printf("\n");
 
 
}
 
main(){
  cin >> n >> k;
  for ( int i = 0; i < n; i++ ) scanf("%d", &a[i]);
  solve();
 
  return 0;
}


Measured memory_bytes: 14884
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} ;
// } fio;

vector<int> a, ans;
vector<int> lis;
vector<vector<int>> tree; 
int N;

void solve(int cur, int per){// cout<<cur<<endl;
	int in = -1, bn = -1, f = false;
	
	// cout<<"BEGIN BEGIN LIS ::: "<<cur+1<<" "<<a[cur]<<endl;
	// for(int i = 0; i < lis.size(); i++){
		// cout<<lis[i]<<" ";
	// }
	// cout<<endl;
	
	in = lower_bound(lis.begin(), lis.end(), a[cur]) - lis.begin();
	
	
	// cout<<"in = "<<in<<" "<<lis.size()<<endl;
	
	if(in == lis.size()) {
		f = true;
		lis.push_back(a[cur]);
	} else {
		bn = lis[in];
		lis[in] = a[cur];
	}
	
	// cout<<"LIS ::: "<<cur+1<<" "<<a[cur]<<endl;
	// for(int i = 0; i < lis.size(); i++){
		// cout<<lis[i]<<" ";
	// }
	// cout<<endl;
	// cout<<"<> "<<endl;
	
	ans[cur] = lis.size();
	// cout<<"<> "<<endl;
	
	for(int next : tree[cur]){
		if(next == per) continue;
		// cout<<"[][] "<<endl;
		solve(next, cur);
	}
	
	// cout<<"in = "<<in<<" "<<lis.size()<<endl;
	// if(in ==  lis.size()+1) {
	if(f) {
		lis.pop_back();
	} else {
		lis[in] = bn;
	}
	
	// cout<<"END END LIS ::: "<<cur+1<<" "<<a[cur]<<endl;
	// for(int i = 0; i < lis.size(); i++){
		// cout<<lis[i]<<" ";
	// }
	// cout<<endl;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	cin>>N;
	
	a.resize(N);
	ans.resize(N);
	tree.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	
	for(int i = 0; i < N-1; i++){
		int u, v;
		
		cin>>u>>v;
		
		u--, v--;
		
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	
	solve(0, -1);
	
	for(int i = 0; i < N; i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 31684
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
    long long a, b;
    cin >> a >> b;
    if( a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        System.out.println(comp(
                scan.nextInt() , scan.nextInt(), scan.nextInt(),
 scan.nextInt(), scan.nextInt()));
    }

    private static String comp(int w,int h,int x,int y,int r) {
        if (!(-100 <= x || y <=100 || 0 < w || r <= 100)) {
            return "";
        }
        if (circle_in_a_Rectangle_X(w,x,r) && circle_in_a_Rectangle_Y(h,y,r)) {
            return "Yes";
        } else {
            return "No";
        }
    }

    // 水平方向
    // x - r が0 より小さい、または、x + r がW より大きいならばNoと判定。
    // x - r が0 以上、かつ、x + r がW 以下ならばYesと判定。
    private static boolean circle_in_a_Rectangle_X(int w,int x,int r) {
        int a = x - r;
        int b = x + r;
        if (a < 0 || b > w) {
            return false;
        } else if (a >= 0 && b <= w) {
            return true;
        } else {
            return false;
        }
    }

    // 垂直方向
    // y - r が0 より小さい、または、y + r がH より大きいならばNoと判定。
    // y - r が0 以上、かつ、y + r がH 以下ならばYesと判定。
    private static boolean circle_in_a_Rectangle_Y(int h,int y,int r) {
        int a = y - r;
        int b = y + r;
        if (a < 0 || b > h) {
            return false;
        } else if (a >= 0 && b <= h) {
            return true;
        } else {
            return false;
        }
    }
}

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

int main(){
	int n, m;
	cin >> n >> m;
	string ans;
	rep(i,n) {
		if (i == 0) {
			ans.insert(0,"1");
		} else {
			ans.insert(i,"0");
		}
	}

	if (n == 1 && m == 0) {
		cout << 0 << endl;
		return 0;
	}

	vector<pair<int, string>> a;

	rep(i,m) {
		int s;
		string t;
		cin >> s >> t;
		if (n < s) {
			cout << -1 << endl;
			return 0;
		}
		s--;
		ans.replace(s,1,t);
		a.push_back(make_pair(s,t));
	}

	sort(a.begin(), a.end());
	if (m > 1) {
		rep(i,a.size()) {
			if (a[i].first == a[i+1].first && a[i].second != a[i+1].second) {
				cout << -1 << endl;
				return 0;
			}
		}
	}

	if (ans[0] == '0' && n != 1) {
		cout << -1 << endl;
		return 0;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

int n;

void brute(string s,char c)
{
    if(s.size()==n)
        cout<<s<<"\n";
    else
    {
        for(char t='a';t<c;t++)
            brute(s+t,c);
        brute(s+c,c+1);
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    brute("",'a');
}


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

int main() {
  //宣言と入力、違いの和
  int N,tigai=0;
  cin >> N;
  vector<int>p(N);
  vector<int>tadasii(N);
  for(int i=0; i<N; i++){
    cin >> p[i];
    tadasii[i] = i+1;
    if(p[i] != tadasii[i]){
      tigai++;
    }
  }
  //判断、出力
  if(tigai == 0 || tigai == 2){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#define LL long long
#define For(i,n) for(int i=1;i<=n;i++)

using namespace std;
int n,m,t;

int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H')
	{
		if(b=='H')
		{
			cout<<"H";
		}
		else cout<<"D";
		
	}
	else 
	{
		if(b=='H')
		{
			cout<<"D";
		}
		else cout<<"H";
	}
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long int N;
    ifstream in("a.in");
    cin>>N;
    if(N%2==1) cout<<0;
  	else{
      unsigned long long int m=10,cnt=0,n=5;
      N/=2;
     
      while(n<=N) {cnt+=N/n;n*=5;}
      cout<<cnt;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
int A[mn];
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    for (int i=1; i<=n; i++) cin>>A[i];
    int cash = 1000, stock = 0;
    int ptr = 1;
    bool find_max = 0;
    while (ptr < n) {
        if (!find_max) { // buy all stocks with money you have
            while (ptr < n) {
                if (A[ptr] < A[ptr+1]) break;
                ptr++;
            }
            stock += cash / A[ptr];
            cash = cash % A[ptr];
            find_max = !find_max;
        } else {
            while (ptr < n) {
                if (A[ptr] > A[ptr+1]) break;
                ptr++;
            }
            cash += stock*A[ptr];
            stock = 0;
            find_max = !find_max;
        }
    }

    cash += stock*A[ptr];
    stock = 0;
    cout<<cash;
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3648
// #pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma vector temporal
// #pragma simd
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

map<pair<unsigned ll,unsigned ll>,int> mp[20];

int main(){
    CPPinput;
    int n; cin>>n; 
    string s; cin>>s;
    for(int i=0;i<(1<<n);++i){
        unsigned ll val1=0,val2=0;
        int g=0;
        for(int j=0;j<n;++j){
            if(i&(1<<j)){
                val1=val1*7122+s[j];
                ++g;
            }
            else{
                val2=val2*7122+s[j];
            }
        }
        ++mp[g][make_pair(val1,val2)];
    }
    ll ans=0;
    for(int i=0;i<(1<<n);++i){
        unsigned ll val1=0,val2=0;
        int g=0;
        for(int j=0;j<n;++j){
            if(i&(1<<j)){
                val1=val1*7122+s[2*n-1-j];
                ++g;
            }
            else{
                val2=val2*7122+s[2*n-1-j];
            }
        }
        auto it=mp[g].find(make_pair(val1,val2));
        if(it!=mp[g].end())ans+=it->second;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 16640
class binaryTreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

n = int(input())
root = None
for index in range(n):
    inputL = input().split()
    if inputL[0] == 'insert':
        if root == None:
            root = binaryTreeNode(int(inputL[1]))
        else:
            def insertN(node, val, parent):
                if node != None:
                    if node.val > val:
                        insertN(node.left, val, node)
                    else:
                        insertN(node.right, val, node)
                else:
                    if parent.val > val:
                        parent.left = binaryTreeNode(val)
                    else:
                        parent.right = binaryTreeNode(val)
            insertN(root, int(inputL[1]), None)
    elif inputL[0] == 'print':
        inL = []
        def lookNodeIn(node):
            if node != None:
                lookNodeIn(node.left)
                inL.append(node.val)
                lookNodeIn(node.right)
        lookNodeIn(root)

        preL = []
        def lookNodePre(node):
            if node != None:
                preL.append(node.val)
                lookNodePre(node.left)
                lookNodePre(node.right)
        lookNodePre(root)

        print(' '+' '.join(list(map(str, inL))))
        print(' '+' '.join(list(map(str, preL))))
    
    else:
        def searchNode(node, val):
            if node != None:
                if node.val == val:
                    return 'yes'
                else:
                    if node.val > val:
                        return searchNode(node.left, val)
                    else:
                        return searchNode(node.right, val)
            return 'no'
        print(searchNode(root, int(inputL[1])))



Measured memory_bytes: 121524
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
typedef vector<LL> LV;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

LL gcd(LL a, LL b){    return b != 0 ? gcd(b, a % b) : a;} 

LL lcm(LL number1,LL number2){	return number1 * number2 / gcd(number1,number2);}


LL f(LL a,LL x,LL y){
    LL ax=a/x;
    LL ay=a/y;
    LL axy=a/(lcm(x,y));
    return ax+ay-axy;
}

int main(){
    LL a,b,c,d; cin >> a>>b>>c>>d;
    cout << b-a+1 -( f(b,c,d) - f(a-1,c,d));
    return 0;

}




// LL numBY(LL A,LL B,LL x){
//     LL a = ceil(A/((double)x));
//     LL b = (B/x);
//     return b-a+1;
// }

// int main() {
// 	LL A,B,C,D;
//     cin >>A >> B >> C >> D;
//     LL a = numBY(A,B,C);
//     LL b = numBY(A,B,D);
//     // LL ab =0;
//     LL c = lcm(C,D);
//     LL ab = numBY(A,B,c);
//     // if(c==C || c==D){
//     //     ab=0;
//     // }

//     cout << (100000000000000001.0/100000000000000000) << endl;

//     cout << B-A+1-a-b+ab << endl;
    

//     return 0;
    

// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  int A = 0;
  vector<string> ans(N);
  int B = 0;
  int n = 0;
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      B++;
      if (A < B) {
        ans = vector<string>(N, " ");
        n = 0;
        ans.at(n) = S.at(i);
        A = B;
        B = 0;
      }
      else if (A == B) {
        n++;
        ans.at(n) = S.at(i);
        B = 0;
      }
      else {
        B = 0;
      }
    }
    else if (S.at(i) == S.at(i + 1)) {
      B++;
    }
    else {
      B++;
      if (A < B) {
        ans = vector<string>(N, " ");
        n = 0;
        ans.at(n) = S.at(i);
        A = B;
        B = 0;
      }
      else if (A == B) {
        n++;
        ans.at(n) = S.at(i);
        B = 0;
      }
      else {
        B = 0;
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    cout << ans.at(i) << endl;; 
  }
}
  

Measured memory_bytes: 21928
#include <bits/stdc++.h>
using namespace std;
int64_t A[310][310];
int64_t B[310][310];

int main()
{
  int64_t N, ans = 0, INF = (1LL << 62);
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin >> A[i][j];
      B[i][j] = A[i][j];
    }
  }
  for (int k = 0; k < N; k++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        B[i][j] = min(B[i][j], B[i][k] + B[k][j]);
      }
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < i + 1; j++)
    {
      if (i == j)
        continue;
      if (A[i][j] != B[i][j])
      {
        cout << -1 << endl;
        return 0;
      }
      ans += A[i][j];
      for (int k = 0; k < N; k++)
      {
        if (i == k || j == k)
          continue;
        if (A[i][j] == A[i][k] + A[k][j])
        {
          ans -= A[i][j];
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5036
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}

const ll mod = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    bool ans = true;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        if (a[i] % 2 == 0){
            if (a[i] % 3 != 0 && a[i] % 5 != 0){
                ans = false;
            }
        }
    }

    if (ans) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
n = int(input()) 
  
# input the array 
# arr = []
arr = list(map(int, input().split()))
den=0
app=0
for i in arr:
    i=int(i)
    if (i%2==0):
        if i%3==0 or i%5==0:
            app+=1
        else:
            den+=1
            break

if den>0:
  print("DENIED")
else:
  print("APPROVED")

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

int main(void){
    int n;
    cin>>n;
    int a[n];
    for (int i = 0; i < n; i++)cin>>a[i];
    long int scr=1000,cnt=0;

    for (int i = 0; i < n-1; i++)
    {
        cnt=0;
        if(a[i]<a[i+1]){
            cnt=scr/a[i];
            scr+=(a[i+1]-a[i])*cnt;
        }

        //cout<<scr<<endl;
    }
    cout<<scr<<endl;
    
    return 0;
}

Measured memory_bytes: 3140
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int ar[5][5];

int main()
{

    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            scanf("%d",&ar[i][j]);
        }
    }
    int a1,a2,a3,b1,b2,b3;
    a1 = 0;
    b1 = ar[1][1];
    b2 = ar[1][2];
    b3 = ar[1][3];
    a2 = ar[2][1] - b1;
    a3 = ar[3][1] - b1;
    if(a1+b1!=ar[1][1]||a1+b2!=ar[1][2]||a1+b3!=ar[1][3]||a2+b1!=ar[2][1]||a2+b2!=ar[2][2]||a2+b3!=ar[2][3]||a3+b1!=ar[3][1]||a3+b2!=ar[3][2]||a3+b3!=ar[3][3])
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n;
  cin >> n;
  vl x(60, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    rep(j, 60) if(a >> j & 1) x[j]++;
  }
  mint ans = 0;
  rep(i, 60) ans += mint(2).pow(i) * x[i] * (n - x[i]);
  cout << ans << endl;
}

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

int main(){
  int H,W,N;
  cin >> H >> W >> N;
  vector<vector<int>> M(H,vector<int>(W,0));
  int color;
  int x=0;
  for(int i=1;i<=N;i++){
    cin >> color;
    for(int j=0;j<color;j++){
      M.at(x/W).at(x%W) = i;
      x++;
    }
  }
  for(int i=0;i<H;i++){
    if(i%2==1){
      reverse(M.at(i).begin(),M.at(i).end());
    }
    for(int j=0;j<W;j++){
      cout << M.at(i).at(j) << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;


int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;
	
	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

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

const int mod = 1000000007;
//const int mod = 998244353;

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

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


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    int N;
    cin >> N;

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    rep(i, N) {
        if (A[i] %2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi V(N); REP(i, N) cin >> V[i];
    vi C(N); REP(i, N) cin >> C[i];

    int M = 0x01 << N;
    int ans = -INF;
    REP(i,M) {
        int ptn = i;
        int mask = 0x01;
        int X = 0, Y = 0;
        REP(j,N) {
            if (ptn & mask) {
                X += V[j];
                Y += C[j];
            }
            mask <<= 1;
        }
        ans = max(ans, X - Y);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[51][6000];
const int offset=2505;
int main(){
ll n,k;
cin>>n>>k;
V<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){a[i]-=k;}
for(int i=0;i<n;i++){
    for(int j=0;j<6000;j++){
    if(dp[i][j])dp[i+1][j+a[i]]+=dp[i][j];
    if(j==a[i]+offset)dp[i][j]++;
    dp[i+1][j]+=dp[i][j];
    }
}
cout<<dp[n][offset]<<endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(){
  int i,j,n,a[100],min,c=0,swap;

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

  for(i = 0; i < n; i++){
    min = i;
    for(j = i; j < n; j++){
      if(a[j] < a[min]){
	min = j;
      }
    }
    if(i != min) c++;
    
    swap = a[i];
    a[i] = a[min];
    a[min] = swap;
  }
  
  for( j = 0; j < n-1; j++){
    printf("%d ",a[j]);
  }
  printf("%d\n%d\n",a[n-1],c);

  
  return 0;
}
  

Measured memory_bytes: 600
#include<iostream>
#include<utility>
#define N 10
#define Pair pair<int,int>
#define x first
#define y second

using namespace std;

int X[] = {-2,-2,-2,2,2,2,-1,0,1,-1,0,1};
int Y[] = {-1,0,1,-1,0,1,-2,-2,-2,2,2,2};
bool tab[N][N], tab_[N][N];

void init(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      tab[i][j]=false, tab_[i][j]=false;
    }
  }
}
void copy(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      tab[i][j]=tab_[i][j], tab_[i][j]=false;
    }
  }
}
void jump(const Pair& p1, const Pair& p2){
  Pair p;
  for(int i=0; i<12; ++i){
    p.x=p1.x+X[i], p.y=p1.y+Y[i];
    if(p.x>=0 && p.x<N && p.y>=0 && p.y<N &&
       p.x >= p2.x-1 && p.x <= p2.x+1 &&
       p.y >= p2.y-1 && p.y <= p2.y+1){
      tab_[p.x][p.y]=true;
    }
  }
}
void check1(const Pair& p){
  Pair p_;
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      if(tab[i][j]) p_.x=i, p_.y=j, jump(p_,p);
    }
  }
}
bool check2(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      if(tab[i][j]) return true;
    }
  }
  return false;
}

int main(){
  int n, x_, y_;
  while(cin >> x_ >> y_ && x_ && y_){
    cin >> n;
    init();
    tab[x_][y_]=true;
    Pair p;
    for(int i=0; i<n; ++i){
      cin >> p.x >> p.y;
      check1(p), copy();
    }
    cout << (check2() ? "OK" : "NA") << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n + 1);
    forn(m) {
        int a, b;
        cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    vector<bool> visited(n + 1, false);
    queue<int> que;
    que.push(1);
    visited[1] = true;
    vector<int> par(n + 1, -1);
    while (!que.empty()) {
        auto temp = que.front();
        que.pop();
        visited[temp] = true;
        for (auto i : v[temp]) {
            if (!visited[i]) {
                par[i] = temp;
                visited[i] = true;
                que.push(i);
            }
        }
    }
    bool ok = true;
    for (int i = 1; i <= n; ++i) {
        ok &= visited[i];
    }
    if (!ok) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (int i = 2; i <= n; ++i) {
            cout << par[i] << '\n';
        }
    }
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string a,b;
  cin>>a>>b;
  Int n=a.size();

  if(a==b){
    cout<<0<<endl;
    return 0;
  }
  if(b==string(n,'0')){
    cout<<-1<<endl;
    return 0;
  }

  vector<Int> lf(n,n),ri(n,n);
  for(Int i=0;i<n;i++){
    for(Int j=0;j<n;j++){
      if(b[(j+n-i)%n]=='1') chmin(lf[j],i);
      if(b[(j+n+i)%n]=='1') chmin(ri[j],i);
    }
  }

  Int ans=3*n;
  for(Int i=0;i<n;i++){
    vector<Int> dp(n,0);
    for(Int j=0;j<n;j++)
      if(lf[j]>i&&a[j]!=b[(j+n-i)%n]) chmax(dp[lf[j]-1],ri[j]);
    for(Int j=n-1;j>0;j--) chmax(dp[j-1],dp[j]);
    
    Int tmp=3*n;
    for(Int j=0;j<n;j++) chmin(tmp,(max(j-i,(Int)0)+dp[j])*2);
    tmp+=i;
    for(Int j=0;j<n;j++) tmp+=a[j]!=b[(j+n-i)%n];
    chmin(ans,tmp);
  }
  
  for(Int i=0;i<n;i++){
    vector<Int> dp(n,0);
    for(Int j=0;j<n;j++)
      if(ri[j]>i&&a[j]!=b[(j+n+i)%n]) chmax(dp[ri[j]-1],lf[j]);
    for(Int j=n-1;j>0;j--) chmax(dp[j-1],dp[j]);
    
    Int tmp=3*n;
    for(Int j=0;j<n;j++) chmin(tmp,(max(j-i,(Int)0)+dp[j])*2);
    tmp+=i;
    for(Int j=0;j<n;j++) tmp+=a[j]!=b[(j+n+i)%n];
    chmin(ans,tmp);
  }

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


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

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 T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const ll INF = 1LL << 60;



//大文字小文字気をつけろ


int main(){
  int n,k;
  cin >> n >> k;
  int h[1000000];
  FOR(i,n){
    cin >> h[i];
  }
  sort(h,h+n);
  int mini=1000000000;
  FOR(i,n-k+1){
    chmin(mini,h[i+k-1]-h[i]);
  }
  cout << mini << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


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


  int n;
  cin>>n;
  int dp[110][4][4][4]={};
  dp[0][0][0][0]=1;

  rep(i,n){
    rep(a,4)rep(b,4)rep(c,4)rep(d,4){
      if(a==1&&b==3&&d==2)continue;
      if(b==1&&c==3&&d==2)continue;
      if(a==1&&c==3&&d==2)continue;
      if(b==1&&c==2&&d==3)continue;
      if(b==3&&c==1&&d==2)continue;
      dp[i+1][b][c][d]+=dp[i][a][b][c];
      dp[i+1][b][c][d]%=M;
    }
  }

  int ans=0;
  rep(a,4)rep(b,4)rep(c,4){
    ans+=dp[n][a][b][c];
    ans%=M;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 256
x = int(input())
for i in range(-10**5, 10**5):
    if (x + i**5) < 0:
        continue
    #     flag = '-'
    # else:
    #     flag = '+'
    else:
        A_tmp = (x + i**5)**(1.0/5)
        # print("i", i)
        # print(x + i**5)
        # print(A_tmp)
        if int(A_tmp)**5 == (x + i**5):
            A = int(A_tmp)
            B = i
            # if flag == '-':
            #     A *= -1
            break
print(str(A) + ' ' + str(B))

Measured memory_bytes: 68260
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, i, S = 0, minBi = inf, ans;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	int *B = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &A[i], &B[i]);
		if(A[i] > B[i]){
			minBi = min(minBi, B[i]);
		}
		S += A[i];
	}
	if(minBi == inf){
		ans = 0;
	}
	else{
		ans = S - minBi;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
    string w;
    cin >> w;
    int alphabet[26];
    memset(alphabet, 0, sizeof alphabet);

    for(char c : w){
        alphabet[c - 'a']++;
    }
    for(int a : alphabet){
        if(a%2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256