akhauriyash/Code-Regression huggingface dataset:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    R = II()
    from math import pi
    print(R*2*pi)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65348
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define MAXN 4003
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define si set<int>
#define pb push_back
#define SZ(v) int(v.size())
#define FORINT(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) FORINT(i,0,n)
#define INF INT_MAX;
#define ms(v,x) memset(v,x,sizeof(v))
using namespace std;

char valor,v[MAXN],A,B,carac;
int dif,n;
ll soma;
vi r,g,b;

int diferente(char x, char y){
	return ((A==x || B==x) && (A==y || B==y));
}

int main(){_
	cin >> n;
	
	FOR(i,n){
		cin >> valor;
		v[i] = valor;
		if(valor=='R') r.pb(i);
		else if(valor=='G') g.pb(i);
		else b.pb(i);
	}
	
	FOR(i,n){
		FORINT(j,i+1,n){
			A = v[i]; B = v[j];
			if(A==B) continue;
			
			vi::iterator up;
			if(diferente('R','B')){
				up = upper_bound(g.begin(), g.end(), j);
				int pos = (up-g.begin());
				soma+=(SZ(g)-pos);
				carac = 'G';
				
			}else if(diferente('R','G')){
				up = upper_bound(b.begin(), b.end(), j);
				int pos = (up-b.begin());
				soma+=(SZ(b)-pos);
				carac = 'B';
			}else{
				up = upper_bound(r.begin(), r.end(), j);
				int pos = (up-r.begin());
				soma+=(SZ(r)-pos);
				carac = 'R';
			}
			
			dif = j-i;
			if(j+dif < n && v[j+dif]==carac) soma--;
		}
	}
	
	cout << soma << endl;
	

	return 0;
}

Measured memory_bytes: 3668
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int a[1000001];
int main() {
    int k;
    cin >> k;
    a[1] = 7%k;
    for (int i = 2; i<=k; ++i) a[i]=(10*a[i-1] + 7)%k;
    for (int i = 1; i <= k; ++i) {
        if (a[i] == 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 7440
if __name__ == "__main__":
    S = input()
    res = set(S)
    ok = True
    for x in S:
        if x == 'N':
            if 'S' not in res:
                ok = False
        elif x == 'S':
            if 'N' not in res:
                ok = False
        elif x == 'E':
            if 'W' not in res:
                ok = False
        elif x == 'W':
            if 'E' not in res:
                ok = False
    if ok:
        print ('Yes')
    else:
        print ("No")


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;

    ll x = n/11;
    ll y = n%11;

    ll ans= 2*x;
    if(y>0){
        ans++;
    }
    if(y>6){
        ans++;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll n,dp[5005][5005];
P p[5005];
bool cmp(const P&a,const P&b){
	return a.fi+a.sc<b.fi+b.sc;
}
int main(){
	rep(i,5005)rep(j,5005) dp[i][j]=1e18;
	cin>>n; repn(i,n){ll a,b;cin>>a>>b;p[i]=mp(a,b);}
	sort(p+1,p+n+1,cmp);
	dp[0][0] = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			if(dp[i][j] > p[i+1].fi) continue;
			dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+p[i+1].sc);
		}
	}
	int ans = INF;
	for(int i=0;i<=n;i++){
		if(dp[n][i] <= 1e17){
			ans = i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 196096
#include<iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int ans = 0;

    if(N%2==0)
    {
        ans = N/2 -1;
    }
    else
    {
        ans = (N-1)/2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))

ans = 1
ans2 = abs((t-h[0]*0.006)-a)

for i in range(1,n):
    if abs((t-h[i]*0.006)-a)<ans2:
        ans=i+1
        ans2=abs((t-h[i]*0.006)-a)

print(ans)

Measured memory_bytes: 3064
#include <cstring>
#include <cstdio>

const int _ = 3002;

int tot, head[_]; struct Edge { int v, nxt; } edge[_ << 1];
void Add_edge(int u, int v) { edge[++tot] = (Edge) { v, head[u] }, head[u] = tot; }

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

void dfs(int u, int f) {
    dp[u] = 0;
    for (int i = head[u]; i; i = edge[i].nxt) {
        int v = edge[i].v; if (v == f) continue ;
        dfs(v, u);
        if (!dp[v] && a[u] > a[v]) dp[u] = 1;
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int u, v, i = 1; i < n; ++i)
        scanf("%d %d", &u, &v), Add_edge(u, v), Add_edge(v, u);
    for (int i = 1; i <= n; ++i) {
        memset(dp, 0, sizeof dp), dfs(i, 0);
        if (dp[i]) printf("%d ", i);
    }
    return 0;
}
//asdadsad

Measured memory_bytes: 512
import java.util.Scanner;

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

		int sum = 0;
		for(int a=1; a<=K; a++){
			for(int b=1; b<=K; b++){
				for(int c=1; c<=K; c++){
					int x = getGCD(getGCD(a, b), c);
					//System.out.printf("%d %d %d %d\n", a, b, c, x);
					sum += x;
				}
			}
		}
		
		System.out.printf("%d\n", sum);
	}

	public static int getGCD(int a, int b){
		int[] numArray = {a, b};
		int x;
        int y;
        if (numArray[0] > numArray[1]) {
            x = numArray[0];
            y = numArray[1];
        } else {
            x = numArray[1];
            y = numArray[0];
        }

        // ここからがユークリッドの互除法を用いた最大公約数を
        // 求める為の式
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
		}

		return y;
	}

}

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    ll ans = max(max(a * c, a * d), max(b * c, b * d));
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;
/*Question
/?????? P1(x1, y1), P2(x2, y2) ????????¢????±???????????????°???????????????????????? 
*/
/*Input
/x1, y1, x2, y2 ????????°???????????????????????§????????????????????? 
*/

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		/*??\?????¨
		/??????????????§????????????String[]???????????????double?????????
		*/
		String[] s = sc.readLine().split(" ");
		double[] z = new double[s.length];
		for(int i = 0;i < s.length;i++){
			z[i] = Double.parseDouble(s[i]);
		}
		//?¨????
		//?????°???????????????????????????????????????????????????
		double d = Math.sqrt(Math.pow(z[0]-z[2], 2) + Math.pow(z[1]-z[3], 2));
		System.out.println(d);
	}
}

Measured memory_bytes: 24180
#line 1 "main.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>

/* template start */

using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...)                                                    \
  std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
      debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
  std::cerr << " " << h;
  if (sizeof...(t) > 0) std::cout << " :";
  debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  return a > b && (a = b, true);
}

template <typename Num>
constexpr Num mypow(Num a, u64 b, Num id = 1) {
  if (b == 0) return id;
  Num x = id;
  while (b > 0) {
    if (b & 1) x *= a;
    a *= a;
    b >>= 1;
  }
  return x;
}

/* template end */

#line 2 "/home/imperi/cp-library/lib/UnionFind/UnionFind.hpp"

#include <cstddef>
#line 6 "/home/imperi/cp-library/lib/UnionFind/UnionFind.hpp"

class UnionFind {
 public:
  using size_t = std::size_t;

 private:
  std::vector<size_t> par, sz;
  size_t group;

 public:
  UnionFind(size_t n = 0) : par(n, 0), sz(n, 1), group(n) {
    std::iota(par.begin(), par.end(), 0);
  }

  size_t root(size_t n) {
    if (par[n] == n) return n;
    return par[n] = root(par[n]);
  }

  bool unite(size_t a, size_t b) {
    a = root(a);
    b = root(b);
    if (a == b) return false;
    group--;
    if (sz[a] < sz[b]) std::swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
    return true;
  }

  size_t size() { return par.size(); }
  size_t groups() { return group; }
  size_t group_size(size_t n) { return sz[root(n)]; }

  bool same(size_t a, size_t b) { return root(a) == root(b); }
};
#line 92 "main.cpp"

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

  i64 n,q;
  std::cin>>n>>q;

  UnionFind uni(n);

  while(q--){
    i64 t,u,v;
    std::cin>>t>>u>>v;
    if(t==0){
      uni.unite(u,v);
    }else{
      if(uni.same(u,v))std::cout<<1<<"\n";
      else std::cout<<0<<"\n";
    }
  }

  return 0;
}


Measured memory_bytes: 6312
#include<stdio.h>
#define MAX 500001

void maxHeapify(int);

int n,H[MAX];

int main(){
  int i;

  scanf("%d",&n);

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

  for(i = n/2; i >= 1; i--){
    maxHeapify(i);
  }

  for(i = 1; i <= n; i++){
    printf(" %d",H[i]);
  }
  printf("\n");

  return 0;
}

void maxHeapify(int a){
  int l = 2*a,r = 2*a+1;
  int large,temp;

  if(l <= n && H[l] > H[a]){
    large = l;
  }
  else{
    large = a;
  }

  if(r <= n && H[r] > H[large]){
    large = r;
  }

  if(large != a){
    temp = H[a];
    H[a] = H[large];
    H[large] = temp;

    maxHeapify(large);
  }
}

Measured memory_bytes: 2552
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;
int a[MaxN + 5], cost[MaxN + 5], sum[MaxN + 5];
int n, cnt = 0;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++)
	{
		if(i == 1) cost[i] = a[i];
		else cost[i] = a[i] - a[i - 1];
		cost[n + 1] = 0 - a[n];
	}
	for(int i = 1; i <= n; i++)
	{
		if(i == 1) sum[i] = abs(a[i] - 0);
		else sum[i] = abs(a[i] - a[i - 1]);
		sum[n + 1] = abs(0 - a[n]);
		cnt += sum[i];
	}
	cnt +=  sum[n + 1];
	int ans = 0, nxt;
	for(int i = 1; i <= n; i++)
	{
		nxt = abs(cost[i] + cost[i + 1]);
		ans = cnt - sum[i] - sum[i + 1] + nxt;
		printf("%d\n", ans);
	}
	return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int n;
    cin >> n;
    vi c(n-1),s(n-1),f(n-1);
    rp(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }
    rp(i,n-1){
        int t=0;
        rep(j,i,n-2){
            while(!(t>=s.at(j)&&t%f.at(j)==0)){
                t++;
            }
            t += c.at(j);
        }
        cout << t << endl;
    }
    cout << 0 << endl;
    return 0;
}


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

string s;
int n;

void dfs(int depth, int last)
{
    if (depth == n)
    {
        cout << s << "\n";
        return;
    }

    for (int i = 0; i <= last + 1; i++)
    {
        s[depth] = 'a' + i;
        dfs(depth + 1, max(last, i));
    }
    
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        s.append("a");
    }
    
    dfs(0, -1);
    // system("pause");
}

Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

string s;

int main(){
  cin >> s;
  if(*s.begin() != *(s.end()-1)){
    if(s.size() % 2 == 0) puts("Second");
    else puts("First");
  }
  else{
    if(s.size() % 2 == 0) puts("First");
    else puts("Second");
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    
    ll n;
    cin>>n;
    ll i,j,x[n][n],y[n][n];
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=n-1;i>=0;i--){
        for(j=i;j<n;j++){
            if(i==j){
                x[i][j]=a[i];
                y[i][j]=0;
            }
            else if(j==i+1){
                x[i][j]=max(a[i],a[j]);
                y[i][j]=min(a[i],a[j]);
            }
            else{
                x[i][j]=max(a[i]+y[i+1][j], a[j]+y[i][j-1]);
                if((a[i]+y[i+1][j])== (a[j]+y[i][j-1]))
                y[i][j]=min(x[i][j-1],x[i+1][j]);
                else if(x[i][j]==a[i]+y[i+1][j])
                y[i][j]=x[i+1][j];
                else
                y[i][j]=x[i][j-1];
            }
        }
    }
    cout<<x[0][n-1]-y[0][n-1]<<endl;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans;
void dfs(string s,int sum){
    if(s.length()==0){
        ans+=sum;
        return;
    }
    for(int i=0;i<s.length();i++){
        int t=0;
        for(int j=0;j<s.length()-i;j++){
            t+=(s[s.length()-1-j]-'0')*pow(10,j);
        }
        dfs(s.substr(0,i),sum+t);
    }
}
signed main(){
    string st;
    cin>>st;
    dfs(st,0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
k = int(input())
def ispf(n,m):
    return (((9 * n) - 1)*pow(10, n) + 1) + pow(10, n) * (sum([int(l) for l in str(m)]) - 10*m)
result = []
for n in range(100):
    for i in range(100000):
        if ispf(n,i)<0:
            break
        for j in range(10):
            result.append(int(str(i) + str(j) + '9'*n))
for item in sorted(list(set(result[1:])))[:k]:
    print(item)


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

void CountTriangles(vector <int> A){

    int n=A.size();

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

    int count = 0;

    for( int i = n-1; i >= 1; i--){
        int l = 0, r = i-1;
        while( l < r){
            if( A[l] + A[r] > A[i]){

                count += r - l ;

                r--;
            }
            else

                l++;
        }
    }
    cout<<count<<endl;
}

int main()
{
    ll int n,i,j,k,ans=0;
    vector<int> l;
    int p;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>p;
        l.push_back(p);
    }
CountTriangles(l);
return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i64,
    };

    println!("{}", n / 2 + n % 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	bool three = true;
	for (int i = 0; i < n; i++) {
		char s;
		cin >> s;
		if (s == 'Y') {
			three = false;
		}
	}
	if (three) {
		cout << "Three" << endl;
		return 0;
	}
	cout << "Four" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
	int a,b;
	cin >> a >>b;
	if(a<b) {
		int t=a;
		a=b;
		b=t;
	}
	for(int i=0;i<a;i++) {
		cout << b;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 205

using namespace std;

int L[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<2*n;i++) scanf("%d",&L[i]);
	sort(L,L+2*n);
	int ret=0;
	for(int i=0;i<n;i++) ret+=L[2*i];
	printf("%d\n",ret);
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  
  int x = n % 10;
  if(x == 3){
    cout << "bon" << endl;
  }else if(x == 0 || x == 1 || x == 6 || x == 8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
    
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll N, A, B;

ll calc(ll sml, ll lrg) {
  if (sml - 1 < N-lrg) {
    // 卓1に集合する
    return sml - 1 + 1 + (lrg-sml-1)/2;
  }
  return N-lrg +1 + (lrg-sml-1)/2;
}

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

  cin >> N >> A >> B;
  if ((A-B)%2==0) {
    cout << abs(A-B) /2 << "\n";
    return 0;
  }

  cout << calc(min(A,B), max(A,B)) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define endl "\n"

int main(){

	int n[3];

	for(int i=0;i<3;i++){
		cin >> n[i];
	}

	int n5=0,n7=0;
	for(int i=0;i<3;i++){
		if(n[i] == 5){
			n5++;
		}else if(n[i] == 7){
			n7++;
		}
	}

	if(n5 == 2 && n7 == 1){
		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(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
const double pi=3.141592653589793;

int main(){
  int a,b,ans;cin>>a>>b;
  if(a<=5)ans=0;
  else if(a<=12)ans=b/2;
  else ans=b;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
int sx,sy,tx,ty;
cin >> sx >> sy >> tx >> ty;

const int dx=tx-sx,dy=ty-sy;

 // Path 1
cout << string(dy,'U') << string(dx,'R');

// Path 2
cout << string(dy,'D') << string(dx,'L');

// Path 3
cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';

// Path 4
cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';

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

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,a[N],s0,s1,s2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t=0;
		scanf("%d",&a[i]);
		while(a[i]%2==0&&t<2) a[i]>>=1,t++;
		if(!t) s0++;
		else  if(t==1) s1++;
		else s2++;
	}
	if(s2>=n/2||!s0||s2>=s0) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include <vector>
#include <set>

int main() {
  std::vector<std::set<int>> card(8);

  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      int a;
      std::cin >> a;
      if (i==0)
        card[0].insert(a);
      else if (i==1)
        card[1].insert(a);
      else if (i==2)
        card[2].insert(a);

      if (j==0)
        card[3].insert(a);
      else if (j==1)
        card[4].insert(a);
      else if (j==2)
        card[5].insert(a);

      if (i==j)
        card[6].insert(a);

      if (2-i==j)
        card[7].insert(a);
    }
  }

  int N;
  std::cin >> N;

  for (int i=0; i<N; i++) {
    int b;
    std::cin >> b;

    for (auto& s : card) {
      s.erase(b);
    }
  }

  bool ans = false;

  for (auto s : card) {
    if (s.size() == 0) ans = true;
  }

  std::cout << (ans ? "Yes" : "No") << std::endl;

  return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
from collections import defaultdict

def comdiv(n):
  end = int(n**0.5) + 2
  dic = defaultdict(lambda: 0)
  for i in range(2, end):
    while n % i == 0:
      n //= i
      dic[i] += 1
  else:
    if n > 1:
      dic[n] = 1
  return dic

A = comdiv(a).keys()
B = comdiv(b).keys()
C = set(A) & set(B)
print(len(C) + 1)

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

int main() {
    string s; cin >> s;
    string ans = "";
    for(int i = 0; i < s.length(); i ++) {
        switch (s[i])
        {
        case '0':
            ans += '0';
            break;
        case '1':
            ans += '1';
            break;
        case 'B':
            if(ans.length()!=0) {
                ans.erase(ans.length()-1,1);
            }
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
A11, A12, A13=list(map(int,input().split()))
A21, A22, A23=list(map(int,input().split()))
A31, A32, A33=list(map(int,input().split()))
N=int(input())
b=[int(input()) for i in range(N)]
if A11 in b and A12 in b and A13 in b:
    print('Yes')
elif A21 in b and A22 in b and A23 in b:
    print('Yes')
elif A31 in b and A32 in b and A33 in b:
    print('Yes')
elif A11 in b and A21 in b and A31 in b:
    print('Yes')
elif A12 in b and A22 in b and A32 in b:
    print('Yes')
elif A13 in b and A23 in b and A33 in b:
    print('Yes')
elif A11 in b and A22 in b and A33 in b:
    print('Yes')
elif A13 in b and A22 in b and A31 in b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
        using namespace std;
        int main(){
			int n,d,x[15][15],ans=0;
			cin>>n>>d;
			for(int i=0;i<n;i++){
				for(int j=0;j<d;j++){
					cin>>x[i][j];
				}
			}
			int sum=0;
			for(int i=0;i<n-1;i++){
				for(int j=i+1;j<n;j++){
					for(int k=0;k<d;k++){
						sum+=abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]);
					}
					double a=sum;
					sum=sqrt(sum);
					if(sqrt(a)==sum){
						ans++;
					}
					
					sum=0;
				}
			}
			cout<<ans<<endl;
    		return(0);
        }

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;

template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main()
{
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m, q;
    cin >> n >> m >> q;
    int x0, y0;
    cin >> x0 >> y0;
    --x0;
    --y0;
    string s, t;
    cin >> s >> t;
    
    int x1 = 0, y1 = 0, x2 = n - 1, y2 = m - 1;
    for (int i = q - 1; i >= 0; --i)
    {
        if (!(s[i] == 'L' && t[i] == 'R' || s[i] == 'R' && t[i] == 'L' || s[i] == 'D' && t[i] == 'U' || s[i] == 'U' && t[i] == 'D'))
        {
            if (s[i] == 'L') ++y1;
            if (s[i] == 'R') --y2;
            if (s[i] == 'U') ++x1;
            if (s[i] == 'D') --x2;

            if (t[i] == 'L') ++y2;
            if (t[i] == 'R') --y1;
            if (t[i] == 'U') ++x2;
            if (t[i] == 'D') --x1;
        }
        chkmax(y1, 0);
        chkmax(x1, 0);
        chkmin(x2, n - 1);
        chkmin(y2, m - 1);
        if (s[i] == 'L') chkmax(y1, 1);
        if (s[i] == 'R') chkmin(y2, m - 2);
        if (s[i] == 'U') chkmax(x1, 1);
        if (s[i] == 'D') chkmin(x2, n - 2);

        //cout << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << endl;
        if (x1 > x2 || y1 > y2)
        {
            cout << "NO\n";
            exit(0);
        }
    }
    cout << (x1 <= x0 && x0 <= x2 && y1 <= y0 && y0 <= y2 ? "YES\n" : "NO\n");
    
    return 0;
}

Measured memory_bytes: 920
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int q=sc.nextInt();
	int[] ans=new int[q];
	for(int n=0;n<q;n++){
	    String X=sc.next();
	    String Y=sc.next();
	    int[][] A=new int[X.length()+1][Y.length()+1];
	    for(int i=1;i<X.length()+1;i++){
		for(int j=1;j<Y.length()+1;j++){
		    if((X.substring(i-1,i)).equals(Y.substring(j-1,j))){
			A[i][j]=A[i-1][j-1]+1;
		    }else{
			if(A[i-1][j]<A[i][j-1]){
			    A[i][j]=A[i][j-1];
			}else{
			    A[i][j]=A[i-1][j];
			}
		    }
			
		}
	    }
	    ans[n]=A[X.length()][Y.length()];
	}
	for(int num:ans){
	    System.out.println(num);
	}
    }
}


Measured memory_bytes: 545572
// 解き直し.
// https://img.atcoder.jp/cf17-final/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
#define pb push_back
#define a first
#define b second
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL INF = 2020202020;
const int MAX = 5050;
LL dp[MAX][MAX];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    vector<P> v;
    LL h, p;
    v.pb({0, 0});
    rep(i, N){
        scanf("%lld %lld", &h, &p);
        v.pb({h, p});
    }
    rep(i, MAX) rep(j, MAX) dp[i][j] = INF;
    
    // 2. h + p を 小さい順に, sort.
    // ex.
    // 6
    // 1 6
    // 2 5
    // 3 4
    // 4 3
    // 5 2
    // 6 1
    // 
    // -> 以下のようにsortする必要があるはず.
    // h=0 p=0
    // h=6 p=1
    // h=5 p=2
    // h=4 p=3
    // h=3 p=4
    // h=2 p=5
    // h=1 p=6
    // -> この場合, 3人(sort後 の 1番目, 2番目, 3番目, もしくは, sort前 の 6番目, 5番目, 4番目)が座布団を積める.
    sort(v.begin(), v.end(), [](const P &x, const P &y){
        if(x.a + x.b < y.a + y.b)                    return true;
        else if(x.a + x.b == y.a + y.b && x.b < y.b) return true;
        else                                         return false;
    });
    // for(auto &p : v) printf("h=%lld p=%lld\n", p.a, p.b);
    
    // 3. dp更新.
    dp[1][1] = v[1].b;
    repx(i, 2, N + 1){
        repx(j, 1, i + 1){
            if(dp[i - 1][j - 1] > v[i].a) dp[i][j] = dp[i - 1][j];
            else                          dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + v[i].b);
        }
    }
    // rep(i, N + 1){
    //     rep(j, N + 1){
    //         printf("%lld ", dp[i][j]);
    //     }
    //     printf("\n");
    // }
    
    // 4. 出力.
    int ans = 0;
    rep(i, N + 1) if(dp[N][i] != INF) ans++;
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 199680
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {  
		Scanner input = new Scanner(System.in);
		int W = input.nextInt();
		int H = input.nextInt();
		int N = input.nextInt();
		int ans = W*H; //Whole area is white initially
		int xCovL = 0;
		int yCovL = 0;
		int xCovR = 0; //Variables that define the range of the black area
		int yCovR = 0;
		for (int i = 0; i < N; i++) {
			int x = input.nextInt();
			int y = input.nextInt();
			int a = input.nextInt();
			if (a==1) {
				xCovL = Math.max(xCovL, x);
			}else if (a==2) {
				xCovR = Math.max(xCovR, W-x); //Converting tricky area to simpler number to work with
			}else if (a==3) {
				yCovL = Math.max(yCovL, y);
			}else if (a==4) {
				yCovR = Math.max(yCovR, H-y);
			}
		}
		ans-=xCovL*H;
		ans-=xCovR*H;
		int xDiff = W-xCovL-xCovR; //Prevents overcounting
		xDiff = Math.max(0, xDiff);
		ans-=yCovL*xDiff;
		ans-=yCovR*xDiff;
		System.out.println(Math.max(ans,0));	
	}
}

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

int main(){
    int N, Q;
    cin >> N >> Q;
    static vector<int> STX[200000];
    for(int i=0; i<N; i++){
        int s, t, x;
        cin >> s >> t >> x;
        STX[i] = {s-x, t-x, x};
    }
    sort(STX, STX+N);

    typedef vector<int> V;
    int pt = 0;
    // XST
    priority_queue<V, vector<V>, greater<V>> que;
    while(Q--){
        int d;
        cin >> d;
        while(pt < N && STX[pt][0] <= d){
            auto v = STX[pt];
            que.push({v[2], v[0], v[1]});
            pt++;
        }
        while(que.size() && que.top()[2] <= d) que.pop();
        if(que.size()){
            cout << que.top()[0] << endl;
        }else{
            cout << -1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 24364
h, w = map(int, input().split())
grid = [input() for _ in [0]*h]

ans = 0

for i in range(h):
    for j in range(w):
        if grid[i][j] == ".":
            q = [(i, j)]
            dist = [[-1]*w for _ in [0]*h]
            dist[i][j] = 0
            while q:
                x, y = q.pop(0)
                for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nx, ny = x+dx, y+dy
                    if not (nx in range(h) and ny in range(w)):
                        continue
                    if grid[nx][ny] == "#":
                        continue
                    if dist[nx][ny] == -1:
                        dist[nx][ny] = dist[x][y] + 1
                        q.append((nx, ny))
            ans = max(ans, max([max([j for j in i]) for i in dist]))

print(ans)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,m,l;
    cin >> n >> m >> l;
    cout << ((m-n == l-m)?"YES":"NO") << endl;
    return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A1014
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
#include <limits.h>
//Global data section
int d,h;
// distant table from hot spring and district
int hd[50][50];
// distant table between 2 districts
int dd[50][50];
// alredy kaituu
int flag[50];
//
int all_distance()
{
        int rest,ret,shortest,s_d,i,j;

        rest=d;
        ret=0;
        while(rest)
        {
                shortest=INT_MAX;
                for(i=0;i<d;i++)
                {
                        if(flag[i])
                                continue;
                        for(j=0;j<h;j++)
                        {
                                //
                                if(hd[j][i] && shortest > hd[j][i])
                                {
                                        s_d=i;
                                        shortest=hd[j][i];
                                }
                        }
                        for(j=0;j<d;j++)
                                if(dd[j][i] && flag[j] && shortest > dd[j][i])
                                {
                                        s_d=i;
                                        shortest=dd[j][i];
                               }
                }
                flag[s_d]=-1;
#ifdef DEBUG
                printf("%d %d\n",s_d,shortest);
#endif
                ret += shortest;
                rest--;
        }
        return(ret);
}
clear()
{
        int i;

        for(i=0;i<50;i++)
                flag[i]=0;
}
main()
{
        int i,j,x,ret;

        while(EOF!=scanf("%d %d",&h,&d) && (h||d))
        {
                clear();
                for(i=0;i<h;i++)
                        for(j=0;j<d;j++)
                                scanf("%d ",&hd[i][j]);

                for(i=0;i<d-1;i++)
                        for(j=i+1;j<d;j++)
                        {
                                scanf("%d ",&x);
                                dd[i][j]=dd[j][i]=x;
                        }
                ret=all_distance();
                printf("%d\n",ret);
        }
return(0);
}

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

struct data{
  int id;
  string str;
  data(int a,string b){id=a;str=b;}
};
struct edge{ int a,b,c; };

queue<data> A,B,C;
vector< edge > ans;
bool flg;
int cnt;

bool check(string s){
  int ac=0,bc=0;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='o')ac++;
    else bc++;
  }
  return (ac>=bc);
}

void func(data d){
  int len=d.str.size();
  if(len==1)A.push(d);
  else B.push(d);
}

void solve(){

  int count=0;
  while(!C.empty()){
    
    if(count>(int)C.size())break;
    count++;
    
    data d=C.front();C.pop();
    string s=d.str;
    int i;
    if(!check(s)){ flg=true; return; }
    
    if(d.str.size()<=2){ func(d); continue; }

    int O1=0,X1=0,O2=0,X2=0;;
    for(int i=0;i<(int)s.size();i++){
      if(s[i]=='o')O2++;
      else if(s[i]=='x')X2++;
    }
    
    for(i=0;i+1<(int)s.size();i++){
      if(s[i]=='o')O2--,O1++;
      else X2--,X1++;
      
      
      if(O2>=X2&&O1>=X1){
        ans.push_back( (edge){0,d.id,i} );
        string a=s.substr(0,i+1);
        string b=s.substr(i+1);
        data na=data(cnt++,a);
        data nb=data(cnt++,b);        
        C.push(na);
        C.push(nb);
        count=0;
        break;
      }
    }
    if(i+1<(int)s.size())continue;
    if(A.empty()){ C.push(d); continue; }
    data f=A.front();A.pop();
    if( d.str[0]=='x'){
      ans.push_back( (edge){ 1 , f.id , d.id } );
      cnt++;
      ans.push_back( (edge){ 0 , cnt , 1 } );
      B.push( (data){ cnt++, "ox" } );
      C.push( (data){ cnt++, s.substr(2)} );
      count=0;
    }else{
      ans.push_back( (edge){ 1 , d.id , f.id } );
      cnt++;
      ans.push_back( (edge){ 0 , cnt , (int)s.size()-2 } );
      B.push( (data){ cnt++, "xo" } );
      C.push( (data){ cnt++, s.substr(0, (int)s.size()-2 )} );
      count=0;
    }
  }
  if(!C.empty())flg=true;
}

int main(){
  int Tc;
  cin>>Tc;
  while(Tc--){
    cnt=1;
    while(!A.empty())A.pop();
    while(!B.empty())B.pop();
    while(!C.empty())C.pop();
    ans.clear();
    string st;
    cin>>st;
    if(st.size()==1){
      if(st=="o")cout<<0<<endl;
      else cout<<-1<<endl;
      continue;
    }else if(st.size()==2){
      if(st=="xx")cout<<-1<<endl;
      else cout<<0<<endl;
      continue;
    }
    
    C.push( data(0,st) );
    flg=false;
    solve();
    
    if(flg){
      cout<<-1<<endl;
    }else{
      cout<<ans.size()<<endl;
      for(int i=0;i<(int)ans.size();i++){
        edge e=ans[i];
        if(e.a==0)printf("split ");
        else printf("join ");
        printf("%d %d\n",e.b,e.c);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut count = vec![0; n];
    for num in a {
        count[num - 1] += 1;
    }
    for ans in count {
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 5816
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = -1e18-20;
  chmax(ans, a * c);
  chmax(ans, a * d);
  chmax(ans, b * c);
  chmax(ans, b * d);
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll l;
    cin>>l;
    vector<ll> A(l);
    for(auto &I:A){cin>>I;}
    vector<vector<ll>> a(l+1,vector<ll>(5,E)); //hasinasi katahasi ryoutan end nothing
    a[0][4]=a[0][3]=a[0][2]=a[0][1]=a[0][0]=0;
    for(int i=1;i<=l;i++){
        a[i][4]=a[i-1][4]+A[i-1];
        
        a[i][0]=a[i-1][0]+(A[i-1]>=2?A[i-1]%2:2-A[i-1]);
        a[i][0]=min(a[i][0],a[i-1][4]+A[i-1]%2);
        
        a[i][1]=a[i-1][1]+(A[i-1]+1>=2?(A[i-1]+1)%2:2-(A[i-1]+1));
        a[i][1]=min(a[i][1],a[i-1][0]+(A[i-1]>=1?0:1));
        a[i][1]=min(a[i][1],a[i-1][4]);
        
        a[i][2]=a[i-1][2]+(A[i-1]>=2?A[i-1]%2:2-A[i-1]);
        a[i][2]=min(a[i][2],a[i-1][0]+(A[i-1]==0?1:0));
        a[i][2]=min(a[i][2],a[i-1][1]+(A[i-1]==0?1:0));
        a[i][2]=min(a[i][2],a[i-1][4]);
        
        a[i][3]=a[i-1][3]+A[i-1];
        a[i][3]=min(a[i][3],a[i-1][0]);
        a[i][3]=min(a[i][3],a[i-1][1]);
        a[i][3]=min(a[i][3],a[i-1][2]+A[i-1]%2);
        a[i][3]=min(a[i][3],a[i-1][4]);
    }
    /*
    for(int i=0;i<=l;i++){
        cout<<a[i][0]<<" "<<a[i][1]<<" "<<a[i][2]<<" "<<a[i][3]<<" "<<a[i][4]<<endl;
    }
     */
    cout<<a[l][3]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 15872
#include <cstdio>
#include <vector>
#define nmax 16
using namespace std;
vector <pair <int, int > > v[nmax];
int a[nmax], p[nmax], r[nmax][nmax], sol;
int h[nmax];

void bkt(int i, int n, int k);

int main()
{
    int i, j, n, x, y;
    //freopen("date.in", "r", stdin);
    scanf("%d", &n);

    for (i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        for (j = 1; j <= a[i]; j++) {
            scanf("%d %d", &x, &y);
            v[i].push_back(make_pair(x, y));
            r[i][x] = (y == 1 ? 1 : -1);
        }
    }
    bkt(1, n, 0);
    printf("%d", sol);

    return 0;
}

void bkt(int i, int n, int k) {

    bool next = true;

    if (i <= n) {

        int j;
        for (j = 1; j <= k; j++)
            if (r[p[j]][i] == -1) {
                next = false;
                break;
            }
        if (next) {
            p[k + 1] = i;
            h[i] = 1;
            bkt(i + 1, n, k + 1);
        }
        p[k + 1] = 0;
        h[i] = 0;

        bkt(i + 1, n, k);
    }
    else {
        int e, j;
        for (e = 1; e <= k; e++)
            for (j = 0; j < a[p[e]]; j++)
                if (h[ v[p[e]][j].first ] != v[p[e]][j].second)
                    return;

        sol = max(sol, k);
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a, b;
    
    while(cin >> a >> b){
        int cnt = 1;
        double sum = a + b;
        while(sum >= 10)
        {
            sum /= 10;
            cnt++;
        }
        cout << cnt << endl;
    }     
    return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;

int main() {
  int x;
  cin>>x;
  if(x==3 || x==5 || x==7)
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long k = s.nextLong();
		int[] a = new int[n + 1];
		for(int i = 0; i < n; i++) {
			a[i + 1] = s.nextInt();
		}
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		int start = 1;
		while(!map.containsKey(start) && k > 0) {
			map.put(start, map.size());
			start = a[start];
			k--;
		}
		if(k == 0) {
			System.out.println(start);
			return;
		}
		k %= (map.size() - map.get(start));
		map.clear();
//		System.out.println(map);
		while(!map.containsKey(start) && k > 0) {
			map.put(start, map.size());
			start = a[start];
			k--;
		}
		System.out.println(start);
	}

}


Measured memory_bytes: 69748