akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

#include <stack>
#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << "=" << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n); inn(m);

    vi adj[n];
    rep(i, m) {
        inn(x); --x;
        inn(y); --y;
        adj[x].push_back(y);
    }

    int d[n] = {0};
    auto dfs = [&]() {

        std::function<int(int)> rdfs = [&](int u) {
            if (!d[u]) for (int v: adj[u])
                d[u] = std::max(d[u], rdfs(v) + 1);
            return d[u];
        };

        rep(i, n) if (!d[i]) rdfs(i);
    }; dfs();

    out(*std::max_element(d, d + n));
}

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

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 8832
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
      int output = 0;
      output ^= one.get(0);
      output ^= one.get(1);
      output ^= one.get(2);
      myout(output);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<(n);i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

struct Edge{
  int to,id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int c = -1,int p = -1){
  int nowc = 1;
  rep(v2,g[v].size()){
    int eto = g[v][v2].to,eid = g[v][v2].id;
    if(eto == p) continue;
    if(nowc == c) nowc++;
    ans[eid] = nowc;
    nowc++;
    dfs(eto,ans[eid],v);
  }
}

signed main(){
  int n;
  cin >> n;
  g.resize(n);
  ans.resize(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back((Edge){b,i});
    g[b].push_back((Edge){a,i});
  }
  dfs(0);
  int mx = 0;
  rep(i,n-1){
    mx = max(mx,(int)g[i].size());
  }
  cout << mx << endl;
  rep(i,n-1){
    cout << ans[i] << endl;
  }
}



Measured memory_bytes: 9728
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[3 * n];
		for(int i = 0 ; i < 3 * n ; i++) a[i] = sc.nextInt();
		Arrays.sort(a, Comparator.reverseOrder());
		long ans = 0;
		for(int i = 0 ; i < n ; i++) {
			ans += a[2 * i + 1];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 100376
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N, ans = 0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N - 2; i++) {
    if (S.substr(i, 3) == "ABC") ans++;
  }

  cout << ans << endl;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int a,b;cin>>a>>b;
   int ans=max({a+b,a-b,a*b}); 
   cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
def main():
    n=int(input())
    a=list(map(int,input().split()))
    m=int(input())
    q=list(map(int,input().split()))
    
    ans=[None]*m
    
    for i in range(2**n):
        total=0
        for j in range(n):
            if ((i>>j)&1):
                total+=a[j]
        for i in range(m):
            if q[i]==total:
                ans[i]=True
    for i in ans:
        if i==True:
            print('yes')
        else:
            print("no")

if __name__=="__main__":
    main()


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, ans = 0;
  int a[100001], b[100001];
  map<int, int> mp;
  cin >> n;
  rep(i, 0, n) cin >> a[i], b[i] = a[i];

  sort(b, b + n);

  rep(i, 0, n) mp[b[i]] = i % 2;

  int ka = 0, kb = 0;

  rep(i, 0, n) {
    if(i % 2 != mp[a[i]]) {
      if(i % 2) ka++;
      else kb++;
    }
  }

  ans += min(ka, kb);
  ka -= ans;
  kb -= ans;
  ans += ka + kb;

  cout << ans << endl;
}


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

int main()
{
	int n, m, x; cin >> n >> m >> x;
	
	vector<int> num(110, 0);

	vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i];
		num[a[i]]++;
	}
	
	int leftCnt = 0;
	for (int j = 1; j < x; j++) {
		if (num[j] == 1) leftCnt++;
	}
	int rightCnt = 0;
	for (int j = x + 1; j < n; j++) {
		if (num[j] == 1) rightCnt++;
	}

	cout << min(leftCnt,rightCnt) << endl;
			
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n, c[510], s[510], f[510];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, 0, n){
        int now = 0;
        rep(j, i, n - 1){
            if(now <= s[j]){
                now = s[j];
            }else{
                now = (now + f[j] - 1) / f[j] * f[j];
            }
            now += c[j];
        }
        cout << now << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i=1;i<n;i++){
        dp[i][0] = a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<< max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 5936
import collections
n,k = map(int, input().split())
a = list(map(int, input().split()))
c = collections.Counter(a)
li = c.most_common()
count = m = len(li)
ans = 0
for i in range(1,m+1):
    if count <= k:
        break
    count -= 1
    ans += li[-i][1]
print(ans)

Measured memory_bytes: 39320
// AOJ 0563: Walking Santa
// 2017.10.25 bal4u@uu
// 2018.1.5

#include <stdio.h>
//#include <stdlib.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define THRESHOLD 10
#define STACKSIZE 35		// 2^32 for int

void quicksort(int *a, int n)
{
	int i, j, l, r, m, p;
	int lsp[STACKSIZE], rsp[STACKSIZE];
	int t;
	
	l = 0, r = n-1, p = 0;
	while (1) {
		if (r-l <= THRESHOLD) {
			if (!p--) break;
			l = lsp[p], r = rsp[p];
		}
		m = a[(l+r)>>1];
		i = l, j = r;
		while (1) {
			while (a[i] < m) i++;
			while (m < a[j]) j--;
			if (i >= j) break;
			t = a[i], a[i] = a[j], a[j] = t;
			i++, j--;
		}
		if (i-l > r-j) {
			if (i-l > THRESHOLD) {
				lsp[p] = l;
				rsp[p] = i-1;
				p++;
			}
			l = j+1;
		} else {
			if (r-j > THRESHOLD) {
				lsp[p] = j+1;
				rsp[p] = r;
				p++;
			}
			r = i-1;
		}
	}
	
	// insert sorting
	for (i = 1; i < n; i++) {
		m = a[i];
		for (j = i-1; j >= 0 && a[j] > m; j--) a[j+1] = a[j];
		a[j+1] = m;
	}
}


//int cmp(int *a, int *b) { return *a - *b; }

typedef struct { int x, y; } PP;
PP pp[100002];
int x[100002], y[100002];

long long calc(int x0, int y0, int n)
{
	int i;
	long long sum, ans, dx, dy, max;
	PP *p;

	sum = 0, max = 0, ans = 1LL << 60;
	p = pp, i = n;
	while (i--) {
		dx = x0 - p->x, dy = y0 - p->y;
		if (dx < 0) dx = -dx;
		if (dy < 0) dy = -dy;
		dx += dy;
		sum += dx << 1;
		if (dx > max) max = dx;
		p++;
	}
	if (sum - max < ans) ans = sum - max;
	return ans;
}

int main()
{
	int w, h, n, i, xpos, ypos, m;
	long long ans, a;

	w = in(), h = in(), n = in();
	for (i = 0; i < n; i++) {
		pp[i].x = x[i] = in(), pp[i].y = y[i] = in();
	}
#if 0
	qsort(x, n, sizeof(int), cmp), qsort(y, n, sizeof(int), cmp);
#else
	quicksort(x, n), quicksort(y, n), 
#endif
	m = (n-1)>>1, xpos = x[m], ypos = y[m];
	ans = calc(xpos, ypos, n);
	if (!(n & 1)) {
		if (x[m] == x[m+1] && y[m] == y[m+1]);
		else if (x[m] == x[m+1]) {
			a = calc(xpos, y[m+1], n);
			if (a < ans) ans = a, ypos = y[m+1];
		} else if (y[m] == y[m+1]) {
			a = calc(x[m+1], ypos, n);
			if (a < ans) ans = a, xpos = x[m+1];
		} else {
			a = calc(x[m], y[m+1], n);
			if (a < ans) ans = a, xpos = x[m], ypos = y[m+1];
			a = calc(x[m+1], y[m], n);
			if (a < ans) ans = a, xpos = x[m+1], ypos = y[m];
			a = calc(x[m+1], y[m+1], n);
			if (a < ans) ans = a, xpos = x[m+1], ypos = y[m+1];
		}
	}
	printf("%lld\n%d %d\n", ans, xpos, ypos);
	return 0;
}



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

typedef long long ll;

struct myChar {
    myChar* prev = NULL;
    unsigned short len = 0;
    char ch;
};

myChar dp[3002][3002];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= m; j++) {
            if(i == 0 || j == 0) dp[i][j].len = 0;
            else if(s[i - 1] == t[j - 1]) {
                dp[i][j].ch = s[i - 1];
                dp[i][j].prev = &dp[i - 1][j - 1];
                dp[i][j].len = dp[i - 1][j - 1].len + 1;
            } else {
                if(dp[i - 1][j].len > dp[i][j - 1].len)
                    dp[i][j] = dp[i - 1][j];
                else
                    dp[i][j] = dp[i][j - 1];
            }
        }
    }

    string ans = "";
    if(dp[n][m].len != 0) {
        ans = dp[n][m].ch;
        auto it = dp[n][m].prev;
        while(it != NULL) {
            if(it->ch != '\0')
                ans = it->ch + ans;
            it = it->prev;
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 141056
#include<iostream>
#include<algorithm>

using namespace std;




int main()
{
	int i;
	int n;
	int tcard[100];
	int hcard[100];
	int ncard = 0, turn = 0;
	int tscore[100];
	int hscore[100];
	for(i = 0;;i++)
	{
		cin >> n;
		if(n == 0)
		{
			break;
		}
		ncard = 0;
		turn = 0;
		for(int a = 0;a<n;a++)
		{
			tcard[a] = 0;
			hcard[a] = 0;

		}
		tscore[i] = n;
		hscore[i] = n;

		for(int a = 0;a<n;a++)
		{
			cin >> tcard[a];
		}
	
		sort(tcard,tcard+n);

		int b = 0;
		int c = 1;
	
		for (int a = 0; a < n;)
		{
			if (c < tcard[b])
			{
				hcard[a] = c;
				a++;
				c++;
			}
			else
			{
				b++;
				c++;
			}
		}

		for(;;)
		{
			if(turn == 0)
			{
				for (int b = 0; b <= n;b++)
				{
					if (b == n)
					{
						ncard = 0;
						turn = 1;
					}
					else if (ncard < tcard[b])
					{
						ncard = tcard[b];
						tcard[b] = -1;
						hscore[i]--;
						turn = 1;
						break;
					}
				}
			}

			if(hscore[i] == 0 || tscore[i] == 0)
			{
				break;
			}

			if(turn == 1)
			{
				for (int b = 0; b <= n; b++)
				{
					if (b == n)
					{
						ncard = 0;
						turn = 0;
					}
					else if (ncard < hcard[b])
					{
						ncard = hcard[b];
						hcard[b] = -1;
						tscore[i]--;
						turn = 0;
						break;
					}
				}
			}
			if(hscore[i] == 0 || tscore[i] == 0)
			{
				break;
			}
		}

	}

	for(int a = 0;a<i;a++)
	{
		cout << tscore[a] << endl;
		cout << hscore[a] << endl;
	}

	return 0;
}

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

int main() {
int n,c0=0,c1=0,c2=0,c3=0;
string s;
cin>>n;
for(int i=1;i<=n;i++)
{
	cin>>s;
	if(s=="AC")
		c0++;
	else if(s=="WA")
		c1++;
	else if(s=="TLE")
		c2++;
	else
		c3++;
}
cout<<"AC x "<<c0<<endl<<"WA x "<<c1<<endl<<"TLE x "<<c2<<endl<<"RE x "<<c3;

return 0;
}

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

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

int par[100010], w[100010];
int root(int i) { if (par[i] < 0) return i; return root(par[i]); }
int sum(int i) { if (par[i] < 0) return 0; return sum(par[i]) + w[i]; }
// w[r] - w[l] = d
void unite(int l, int r, int d) {
    int lr = root(l), rr = root(r);
    if (lr == rr) {
        if (sum(rr) - sum(lr) != d + sum(r) - sum(l)) 
            cout << "No" << endl, exit(0);
    } else {
        if (-par[lr] < -par[rr]) swap(l, r), swap(lr, rr), d *= -1;
        par[lr] += par[rr], par[rr] = lr;
        w[rr] = -(d + sum(r) - sum(l));
    }
}

int main(void) {
    int n,m;cin>>n>>m;
    rep(i, n) par[i] = -1;
    rep(i, m) {
        int l, r, c; cin >> l >> r >> c; l--, r--;
        unite(l, r, c);
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll a[N];
  ll sum=0;
  rep(i,N){
    cin>>a[i];
    sum+=a[i];
    sum%=INF;
  }
  ll ans=0;
  for(int i=0;i<N-1;i++){
    sum-=a[i];
    if(sum<0) sum+=INF;
    ans+=(sum*a[i]);
    ans%=INF;
  }
  
  cout<<ans<<endl;
}


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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int n,x,y;

int main()
{
  cin >> n >> x >> y;
  int m = max(0, x+y-n);
  printf("%d %d\n", min(x,y), m);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n;
    cin>>n;
    ll s=n+n*n+n*n*n;
    cout<<s<<endl;
}








































Measured memory_bytes: 3612
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::vector<long long> x, std::vector<long long> y, std::vector<std::string> u){
    map<i64, set<i64>> vu, vd, vl, vr;
    // +x, +y, -x, -y
    map<i64, set<i64>> vy1u, vy2u;
    map<i64, set<i64>> vy1d, vy2d;
    for(int i = 0; i < n; ++i){
        if(u[i] == "U"){
            vu[x[i]].emplace(y[i]);
            vy1u[x[i] - y[i]].emplace(x[i]);
            vy2u[x[i] + y[i]].emplace(x[i]);
        }
        if(u[i] == "D"){
            vd[x[i]].emplace(y[i]);
            vy1d[x[i] - y[i]].emplace(x[i]);
            vy2d[x[i] + y[i]].emplace(x[i]);
        }
        if(u[i] == "L")
            vl[y[i]].emplace(x[i]);
        if(u[i] == "R")
            vr[y[i]].emplace(x[i]);
    }
    i64 ans = INF;
    auto chmi = [&](auto& v, int pos){
        auto iter = v.upper_bound(pos);
        if(iter != v.end())
            chmin(ans, abs(*iter - pos) * 10);
    };
    auto chmi2 = [&](auto& v, int pos){
        auto iter = v.lower_bound(pos);
        if(iter != v.begin())
            chmin(ans, abs(*prev(iter) - pos) * 10);
    };
    for(int i = 0; i < n; ++i){
        if(u[i] == "R"){
            chmi(vy1d[x[i] - y[i]], x[i]);
            chmi(vy2u[x[i] + y[i]], x[i]);
        }
        if(u[i] == "L"){
            chmi2(vy1u[x[i] - y[i]], x[i]);
            chmi2(vy2d[x[i] + y[i]], x[i]);
        }
    }
    for(auto p : vu){
        int ax = p.first;
        for(auto d : p.second){
            auto iter = vd[ax].upper_bound(d);
            if(iter != vd[ax].end())
                chmin(ans, abs(*iter - d) * 5);
        }
    }
    for(auto p : vr){
        int ax = p.first;
        for(auto d : p.second){
            auto iter = vl[ax].upper_bound(d);
            if(iter != vl[ax].end())
                chmin(ans, abs(*iter - d) * 5);
        }
    }
    if(ans == INF)
        cout << "SAFE\n";
    else
        cout << ans << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    std::vector<long long> Y(N);
    std::vector<std::string> U(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
        std::cin >> U[i];
    }
    solve(N, std::move(X), std::move(Y), std::move(U));
    return 0;
}


Measured memory_bytes: 96188
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main(){
  string S;
  cin >> S;
  if((S.at(2)==S.at(3))&&(S.at(4)==S.at(5))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main(){
    int a,b,c,count;
    
    cin>>a>>b>>c;
    
    int i=a;
    
    while(i<=b){
        if(c%i==0){
            count++;
        }
        i++;
    }
    cout<<count<<endl;
    return 0;
}


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

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


const int INF = 1 << 29;
vector<pii> G[100010];
int d[100010];

int main(){
    int K;
    cin >> K;
    for(int i = 0; i < K; i++){
        G[i].push_back(make_pair((i+1)%K,  1));
        G[i].push_back(make_pair((i*10)%K, 0));
    }

    for(int i = 0; i < K; i++) d[i] = INF;
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    d[1] = 1;
    pq.push(pii(1, 1));
    while(pq.size()) {
        pii p = pq.top(); pq.pop();
        if(d[p.second] < p.first) continue;
        for(pii e : G[p.second]){
            int to = e.first;
            int e_cost = e.second;
            int ncost  = e_cost + p.first;
            if(d[to] > ncost){
                d[to] = ncost;
                pq.push(pii(d[to], to));
            }
        }
    }
    cout << d[0] << endl;

    return 0;
}


Measured memory_bytes: 6780
def solve():

    N, C, K = map(int, input().split())
    T = [int(input()) for i in range(N)]

    T = sorted(T)
    i = 0
    k = 0

    ans = 0

    #print(T)

    while i < N:
        n = 0
        while k < N and n < C and T[i] <= T[k] <= T[i]+K:
            n += 1
            k += 1
            if n == C:
                ans += 1
                break

        if n != C:
            ans += 1

        i = k



    print(ans)            


if __name__ == "__main__":
    solve()


Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]-=i+1;
	}
	sort(a.begin(),a.end());
	ll res=0;
	for(int i=0;i<n;i++) res+=abs(a[i]-a[n/2]);
	cout<<res<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	int ans=0;
	for(ll i=2;i*i<=n;i++)if(n%i==0){
		int cnt=0;
		while(n%i==0)n/=i,cnt++;
		for(int j=1;j<=cnt;j++){
			cnt-=j;
			ans++;
		}
	}
	if(n!=1)ans++;
	printf("%d\n",ans);
}


Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

//A
//int main()
//{
// int n, h;
// std::vector<int> heights;
//
// cin >> n;
// for (int i = 0; i < n; ++i)
// {
//  cin >> h;
//  heights.push_back(h);
// }
//
// vector<int> m(n, 0);
// m[0] = 0;
// m[1] = abs(heights[1] - heights[0]);
//
// for (int i = 2; i < n; ++i)
// {
//  m[i] = min(m[i - 2] + abs(heights[i] - heights[i - 2]), m[i - 1] + abs(heights[i] - heights[i - 1]));
// }
//
// cout << m[n - 1];
//}


//B
//int main()
//{
// int n, k, h;
// std::vector<int> heights;
//
// cin >> n >> k;
// for (int i = 0; i < n; ++i)
// {
//  cin >> h;
//  heights.push_back(h);
// }
//
// vector<int> m(n, 0);
// m[0] = 0; 
//
// for (int i = 1; i < n; ++i)
// {
//  int m_min = INT_MAX;
//  for (int j = 1; j <= k; ++j)
//  {
//   if (i - j < 0) break;
//   int m_cur = m[i - j] + abs(heights[i] - heights[i - j]);
//   if (m_cur < m_min) m_min = m_cur;
//  }
//  m[i] = m_min;
// }
//
// cout << m[n - 1];
//}

//C
int main()
{
    size_t n;
    cin >> n;
    vector<vector<int>> activities;

    int a, b, c;
    for (size_t i = 0; i < n; ++i)
    {
        cin >> a >> b >> c;
        vector<int> acts;
        acts.push_back(a);
        acts.push_back(b);
        acts.push_back(c);
        activities.push_back(acts);
    }

    vector<vector<int>> m(n, vector<int>(3, 0));

	for (int j = 0; j < 3; ++j)
	{
        m[0][j] = activities[0][j];
	}

    for (size_t i = 1; i < n; ++i)
    {
        m[i][0] = activities[i][0] + max(m[i - 1][1], m[i - 1][2]);
        m[i][1] = activities[i][1] + max(m[i - 1][0], m[i - 1][2]);
        m[i][2] = activities[i][2] + max(m[i - 1][0], m[i - 1][1]);
    }

    cout << *max_element(m[n-1].begin(), m[n-1].end());
}

Measured memory_bytes: 11824
<?php

$s = trim(fgets(STDIN));
$count = 0;
for($i=0;$i<strlen($s);$i++){
    if(substr_count($s,$s[$i]) <= 1 || substr_count($s,$s[$i]) > 2){
        $count ++;
    }
}
if($count >0){
    echo "No\n";
}else{
    echo "Yes\n";
}



Measured memory_bytes: 4728
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
H = read_ints()

ans = 0
for i in range(N):
    tmp = H[i]
    ok = True

    for h in H[:i]:
        if tmp < h:
            ok = False

    if ok:
        ans += 1

print(ans)


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> pp(n);
  rep(i, n) {
    string s;
    int p;
    cin >> s;
    cin >> p;
    pp[i] = make_pair(make_pair(s, -p), i + 1);
  }

  sort(pp.begin(), pp.end());

  rep(i, n) {
    cout << pp[i].second << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val h = IntArray(n + 1)
    for (i in 1..n) {
        h[i] = sc.nextInt()
    }
    h.forEachIndexed { i, v ->
        if (i == 0) {
            return@forEachIndexed
        }
        print("node $i: key = $v, ")
        if (i != 1) {
            print("parent key = ${h[i / 2]}, ")
        }
        if (h.size > i * 2) {
            print("left key = ${h[i * 2]}, ")
        }
        if (h.size > i * 2 + 1) {
            print("right key = ${h[i * 2 + 1]}, ")
        }
        println()
    }
}



Measured memory_bytes: 26376
using System;
using System.Linq;

namespace MaximalValue
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var B = Console.ReadLine().Split().Select(x => int.Parse(x));
            var A = new int[N];

            A[0] = B.ElementAt(0);
            A[N - 1] = B.ElementAt(N - 2);
            for(var i = 1;i <= N - 2;i++)
            {
                A[i] = B.ElementAt(i -1) < B.ElementAt(i) ? B.ElementAt(i-1) : B.ElementAt(i);
            }

            Console.WriteLine(A.Sum());
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
int main()
{
  int A[100],i,j,v,N,x;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
        if(i==N-1) printf("%d\n",A[i]);
      else printf("%d ",A[i]);
  }
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(x=0;x<N;x++){
      if(x==N-1) 
	printf("%d\n",A[x]);
      else printf("%d ",A[x]);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
using ll = long long;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repp(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)


int main() {
  int x;  cin >> x;
  if (x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int r, d, x2000, i;
	long long int arr[11];
	cin>>r>>d>>x2000;
	arr[0] = x2000;
	for(i=1; i<11; i++){
		arr[i] = r*arr[i-1]-d;
	}
	for(i=1; i<11; i++)
		cout<<arr[i]<<endl;
	return 0;
	
}

Measured memory_bytes: 256
N_koma, M_visit = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
diff = []

for i in range(len(X) - 1):
    diff.append(abs(X[i + 1] - X[i]))

diff.sort()

if (N_koma >= M_visit):
    print(0)
    exit()

answer = sum(diff[: M_visit - N_koma])

print(answer)

Measured memory_bytes: 13968
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Point struct {
	x int
	y int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nPoints := scanInt(sc)
	first := Point{
		x: scanInt(sc),
		y: scanInt(sc),
	}

	maxD := abs(first.x) + abs(first.y)
	parity := maxD % 2

	ps := make([]Point, nPoints)
	ps[0] = first
	for i := 1; i < nPoints; i++ {
		p := Point{
			x: scanInt(sc),
			y: scanInt(sc),
		}
		ps[i] = p

		d := abs(p.x) + abs(p.y)
		if parity != d%2 {
			fmt.Println(-1)
			return
		}

		if d > maxD {
			maxD = d
		}
	}

	nArms := int(math.Ceil(math.Log2(float64(maxD))))
	if maxD == 0 {
		nArms = 1 // 腕は 1 本以上必要
	}

	out := bufio.NewWriter(os.Stdout)

	fmt.Fprintln(out, nArms-(parity-1))
	for i := nArms - 1; i >= 0; i-- {
		fmt.Fprintf(out, "%d ", 1<<uint(i))
	}
	if parity == 0 {
		fmt.Fprintf(out, "%d ", 1)
	}
	fmt.Fprintln(out)

	adjust := parity - 1
	for _, p := range ps {
		x := p.x
		y := p.y + adjust
		for exp := nArms - 1; exp >= 0; exp-- {
			a := 1 << uint(exp)
			if abs(x) > abs(y) {
				if x > 0 {
					fmt.Fprint(out, "R")
					x -= a
				} else if x < 0 {
					fmt.Fprint(out, "L")
					x += a
				}
			} else {
				if y > 0 {
					fmt.Fprint(out, "U")
					y -= a
				} else if y < 0 {
					fmt.Fprint(out, "D")
					y += a
				}
			}
		}
		if adjust == -1 {
			fmt.Fprint(out, "U")
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int tmph, tmpa;
  int ans = 1234567890;
  vector<int> h;
  REP(j, n){
      cin >> tmph;
      h.pb(tmph);
    }
    sort(h.begin(), h.end());
    REP(i, (n-k+1)){
    tmpa = abs(h[i + k - 1] - h[i]);
    if(ans >= tmpa) ans = tmpa;
  }
    cout << ans << endl;
    return 0;
}


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

vector<int> pl, mi;
int n, k, ans = 2000000005;

int main() {
  int x, i;
  cin >> n >> k;
  for(i = 0; i < n; ++i) {
    cin >> x;
    if(x < 0)
      mi.push_back(-x);
    else if(x == 0)
      --k;
    else
      pl.push_back(x);
  }
  sort(mi.begin(), mi.end());
  sort(pl.begin(), pl.end());
  for(i = 0; i <= k; ++i) {
    x = 0;
    if(k - i > pl.size() || i > mi.size()) continue;
    if(i > 0 && k - i > 0)
      x = min(mi[i - 1], pl[k - i - 1]) * 2 +
          max(mi[i - 1], pl[k - i - 1]);
    else if(i > 0)
      x = mi[i - 1];
    else if(k - i > 0)
      x = pl[k - i - 1];
    ans = min(x, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
# -*- coding: utf-8 -*-

n = int(input())

"""
def n2count(n):
    if n%2==1:
        return 0
    else:
        return 1 + n2count(n//2)
        
lis = []
for i in range(1, 101):
    lis.append(n2count(i))
print(lis)
print(len(lis))
"""

lis_c = [0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2]

m = max(lis_c[:n])
for idx, num in enumerate(lis_c[:n]):
    if num == m:
        print(idx+1)
    








Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<string>
#include<string.h>
#include<list>
#include<queue>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<stack>
using namespace std;
#define debug(x) cout<<"###"<<x<<"###"<<endl;
const int INF=0x3f3f3f3f,MAXN=4e5+5;
typedef long long ll;
int main(){
	string str;
	cin>>str;
	int q,u,f,k;
	char c;
	int flag=0;
	cin>>q;
	while(q--){
		cin>>u;
		if(u==1){
			flag++;
		}
		else{
			cin>>k>>c;
			if(flag%2==0){
				if(k==1){
					str.insert(str.begin(),c);
				}
				else{
					str.insert(str.end(),c);
				}
			}
			else{
				if(k==1){
					str.insert(str.end(),c);
				}
				else{
					str.insert(str.begin(),c);
				}
			}
		}
	}
	if(flag%2==1){
		reverse(str.begin(),str.end());
	}
	cout<<str<<endl;
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.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(){
  //input
  ll n;
  cin>>n;
  vector<ll>a(3*n);
  rep(i,3*n)cin>>a[i];

  //整列させてからの形で良ければ簡単だが、もとの順序で並んだ状態のため厄介
  //前半がより大きく、後半がより小さくの方針
  //前半パート
  priority_queue<ll,vector<ll>,greater<ll>>que;
  vector<ll>s(n*2+1);//s[i]=i文字目までの数字からn文字選んだときの最大値（tは最小値になる）
  rep(i,n){//前半n個のa[i]を小さい順に並べる。この部分は後ろの部分にはなることができない。
    s[i+1]=s[i]+a[i];//s[n]は前半部分のa[i]の総和
    que.push(a[i]);}
  Rep(i,n,2*n){
    ll mi=que.top();//s[i]の総和を作るに当たり今現在使っているa[i]の中で最小を取り出した
    if(a[i]>mi){s[i+1]=s[i]-mi+a[i];
      que.pop();
      que.push(a[i]);}//これにより、より大きな数字を選ぶことになる
    else s[i+1]=s[i];
  }
  //後半パート（作業は同じ,ただし向きが逆）
  priority_queue<ll>euq;
  vector<ll>t(n*2+1);
  rep(i,n){
    t[i+1]=t[i]+a[n*3-1-i];
    euq.push(a[n*3-1-i]);}
  Rep(i,n,2*n){
    ll ma=euq.top();
    if(a[3*n-1-i]<ma){
      t[i+1]=t[i]-ma+a[n*3-1-i];
      euq.pop();
      euq.push(a[3*n-1-i]);}
    else t[i+1]=t[i];
  }

  //output
  ll ans=-1e18;
  Rep(i,n,2*n+1)ans=max(ans,s[i]-t[3*n-i]);//i文字目で区切ったときの前半でn,後半でn選んだときの和の差の最大値が答え
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 11112
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int n, k;
	while (cin >> n >> k) {
		vector<int> num;
		if (n == 0 && k == 0) {
			break;
		}
		int o;
		for (int i = 0; i < n; i++) {
			cin >> o;
			num.emplace_back(o);
		}
		int m = 0;
		for (int i = 0; i < n - k + 1; i++) {
			int h = 0;
			for (int j = 0; j < k; j++) {
				h += num[i + j];
			}
			m = max(m, h);
		}
		cout << m << endl;
	}
}

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

int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<char> S(N);
    for (int i = 0; i < N;i++){
        cin >> S[i];
        }

    vector <int> l(Q), r(Q);
    vector<int> list(N);
    int k = 0;
    for (int i = 1; i < N;i++){
        if(S[i-1] == 'A'&& S[i]=='C'){
            k++;
        }
        list[i] = k;
    }
    for (int i = 0; i < Q;i++){
        cin >> l[i] >> r[i];
    }

        for (int i = 0; i < Q; i++)
        {
            cout << list[r[i]-1]-list[l[i]-1] << endl;
        }
    
}

Measured memory_bytes: 2048
package main

import "fmt"

var h, w int
var maze [][]byte
var d [][]int

type point struct {
	x, y int
}

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

type container struct {
	data []point
}

func (c *container) queue(p point) {
	c.data = append(c.data, p)
}
func (c *container) dequeue(p *point) bool {
	if len(c.data) > 0 {
		*p = c.data[0]
		c.data = c.data[1:]
		return true
	}
	return false
}

func bfs(s, g point) int {
	d = make([][]int, h)
	for i := 0; i < h; i++ {
		d[i] = make([]int, w)
		for j := 0; j < w; j++ {
			d[i][j] = -1
		}
	}
	// fmt.Println("d", d, "maze", maze)
	var q container
	q.queue(s)
	d[s.y][s.x] = 0
	for len(q.data) > 0 {
		var p point
		q.dequeue(&p)
		if p.x == g.x && p.y == g.y {
			break
		}
		for i := 0; i < 4; i++ {
			nx := p.x + dx[i]
			ny := p.y + dy[i]
			// fmt.Println("p", p, "nx", nx, "ny", ny)
			if 0 <= nx && nx < w && 0 <= ny && ny < h && d[ny][nx] == -1 && maze[ny][nx] == '.' {
				var np point
				np.x = nx
				np.y = ny
				d[ny][nx] = d[p.y][p.x] + 1
				q.queue(np)
			}
		}
	}
	return d[g.y][g.x]
}

func main() {
	fmt.Scan(&h, &w)
	maze = make([][]byte, h)
	points := make([]point, 0)
	for i := range maze {
		maze[i] = make([]byte, w)
		fmt.Scan(&maze[i])
		for j := 0; j < w; j++ {
			if maze[i][j] == '.' {
				var p point
				p.x = j
				p.y = i
				points = append(points, p)
			}
		}
	}
	// fmt.Println("h", h, "w", w, "points", points)
	ans := 0
	for i := 0; i < len(points); i++ {
		for j := i + 1; j < len(points); j++ {
			start := points[i]
			goal := points[j]
			ans = max(ans, bfs(start, goal))
		}
	}
	fmt.Println(ans)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 7680
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int maxi = 1e6+10;
string s;
vector<int> v[maxi];
int n;
ll a[maxi];

void dfs(int x, int pred) {
  //ここに処理をかく
  a[x] += a[pred];

  for(int i:v[x]) {
    if(i != pred) dfs(i,x);
  }
}

int main () {
  int q;
  cin >> n >> q;
  for(int i=1; i<n; i++) {
    int x,y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  while(q--) {
    int x,y;
    cin >> x >> y;
    a[x]+=y;
  }

  dfs(1,0);

  for(int i=1; i<=n; i++) printf("%lld ",a[i]);
  printf("\n");
}


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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
   int n, m, c;
   cin >> n >> m >> c;
   vector<int>b(m);
   rep(i, 0, m)cin >> b[i];
   vector<vector<int>>a(n,vector<int>(m));
   rep(i, 0, n)rep(j, 0, m)cin >> a[i][j];
   int ans = 0;
   rep(i, 0, n){
       int temp = c;
       rep(j, 0, m){
           temp += b[j]*a[i][j];
       }
       if(temp>0)ans++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()



int main()
{
    int a, b;
    cin >> a >> b;
    if(a>b)
        cout << "safe";
    else
        cout << "unsafe";
    return 0;
}


Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);

        var ans = (int)(Math.Log(N, K) + 1);

        WriteLine(ans);
    }
}


Measured memory_bytes: 28084
n, k = map(int, input().split())
a=list(map(int, input().split()))

st = set()
st.add(0)

oof = [1]

cur = a[0] - 1

while cur not in st:
    st.add(cur)
    oof += [cur+1]
    cur = a[cur] - 1
ind = oof.index(cur+1)
#print(oof,ind)

if k <= ind:
    print(oof[k])
else:
    print(oof[ind + (k-ind) % (len(oof) - ind)])

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

int main() {

  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  int count = 0;
  bool flag = true;
  while(flag) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 == 0) A[i] /= 2;
      else flag = false;
    }
    count++;
  }
  cout << count-1 << endl;
    
}


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

vector<int> prime_table(int n) {
    vector<int> is_prime(n + 1);
    if (n) iota(is_prime.begin() + 2, is_prime.end(), 2);
    for (int i = 2; i * i <= n; i++) if (is_prime[i]) {
        for (int j = i + i; j <= n; j += i) is_prime[j] = 0;
    }
    return is_prime;
}

int main() {
    auto is_prime = prime_table(1000000);
    int n, x;
    while (cin >> n >> x, n) {
        vector<int> vs(n);
        for (int &v: vs) cin >> v;
        vector<int> dp(x + 1, false); dp[0] = true;
        for (int i = 0; i < n; i++) for (int j = vs[i]; j <= x; j++) {
            dp[j] |= dp[j - vs[i]];
        }
        int ans = -1;
        for (int j = 0; j <= x; j++) if (dp[j]) {
            if (is_prime[j]) ans = j;
        }
        if (ans == -1) cout << "NA" << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 13608
/* ex_7-3.
   nknm */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void){

    int ver, hor;
    char **ptr;
    int *p_hor, *p_ver;
    int i, j;

    //マス目の数と記号を入力
    scanf("%d%d", &hor, &ver);

    ptr = (char**)calloc(hor, sizeof(char*));       //2次元動的メモリを確保
    if(ptr == NULL){
        exit(1);
    }
    
    for(i = 0; i < hor; i++){
        ptr[i] = (char*)calloc(ver, sizeof(char));
        if (ptr[i] == NULL){
            exit(1);
        }
    }

    
    p_hor = (int*)calloc(hor, sizeof(int));     //1次元動的メモリを確保
    if (p_hor == NULL){
        exit(1);
    }

    p_ver = (int*)calloc(ver, sizeof(int));
    if (p_ver == NULL){
        exit(1);
    }

    for(i = 0; i < hor; i++){       //行列の入力
        for(j = 0; j < ver ; j++){
            scanf(" %c", &ptr[i][j]);
        }
    }


    for(i = 0; i < hor; i++){       //'#'がある行と列を1として記録
        for(j = 0; j < ver ; j++){
            if(ptr[i][j] == '#'){
                p_hor[i] = 1;
                p_ver[j] = 1;
            }
        }
    }

    for(i = 0; i < hor; i++){       //行と列がともに1である行、列のみ表示
        if(p_hor[i] == 1){
            for(j = 0; j < ver; j++){
                if (p_ver[j] == 1){
                    printf("%c", ptr[i][j]);
                }
                
            }
            printf("\n");
        }
    }



    free(p_hor);        //各メモリの開放
    free(p_ver);

    for(i = 0; i < hor; i++){
        free(ptr[i]);
    }
    free(ptr);

   
    return 0;
}

Measured memory_bytes: 1572
#include<stdio.h>
 
int main(void){
 
  int i;
 
  /* 文字 */
  char moji;
 
  /* 文字を入力 */
  scanf("%c", &moji);
 
  /* アルファベットの小文字か大文字かを判定 */
  if((moji>= 'a') && (moji<='z')){
    printf("a");
  }
  else if((moji>= 'A') && (moji<='Z')){
    printf("A");
  }
  else {
    printf("その他の文字！\n");
  }
 
  return 0;
}

Measured memory_bytes: 1596