akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#define NO 0
#define S 1
#define W 2
using namespace std;

const int MAX_N = 1e+5 + 5;

int animals[MAX_N];

int main() {
    int N;
    string s;
    cin >> N >> s;
    // 1番目と2番目の動物を固定して全探索
    for (int i = 1; i < 3; i++) {
        for (int j = 1; j < 3; j++) {
            // 0とN+1にはそれぞれN番目と1番目の動物が入る
            for (int k = 0; k <= N + 1; k++) animals[k] = NO;
            animals[1] = animals[N + 1] = i, animals[2] = j;
            if (animals[1] == S) {
                if (s[0] == 'o') animals[0] = j;
                else {
                    if (animals[2] == S) animals[0] = W;
                    else animals[0] = S;
                }
            }
            else {
                if (s[0] == 'x') animals[0] = j;
                else {
                    if (animals[2] == S) animals[0] = W;
                    else animals[0] = S;
                }
            }
            for (int k = 2; k <= N; k++) {
                if (animals[k] == S) {
                    if (s[k - 1] == 'o') animals[k + 1] = animals[k - 1];
                    else {
                        if (animals[k - 1] == S) animals[k + 1] = W;
                        else animals[k + 1] = S;
                    }
                }
                else {
                    if (s[k - 1] == 'x') animals[k + 1] = animals[k - 1];
                    else {
                        if (animals[k - 1] == S) animals[k + 1] = W;
                        else animals[k + 1] = S;
                    }
                }
                if (k == N) {
                    if (animals[0] == animals[N] && animals[N + 1] == animals[1]) {
                        for (int l = 1; l <= N; l++) {
                            cout << (animals[l] == S ? 'S' : 'W');
                        }
                        cout << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

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

ll n,m,a[100000],par[100000],x,y,MIN[100000];
ll ans;

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

int main(){
    cin>>n>>m;
    if(n-1==m){
        cout<<0<<endl;
        return 0;
    }
    ll num=2*(n-m-1);
    if(n<num){
        cout<<"Impossible"<<endl;
        return 0;
    }
    rep(i,n)cin>>a[i],par[i]=i,MIN[i]=-1;
    rep(i,m){
        cin>>x>>y;
        if(root(x)!=root(y))par[root(y)]=root(x);
    }

    rep(i,n){
        if(MIN[root(i)]==-1)MIN[root(i)]=i;
        else if(a[MIN[root(i)]]>a[i])MIN[root(i)]=i;
    }
    rep(i,n){
        if(a[MIN[root(i)]]!=1e18){
            ans+=a[MIN[root(i)]];
            a[MIN[root(i)]]=1e18;
            num--;
        }
    }
    sort(a,a+n);
    rep(i,num)ans+=a[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, m, p; cin >> n >> m >> p, n;){
        int cnt = 0, ind = 0, nm;
        while(n--){
            int x; cin >> x;
            if(m == ++ind) nm = x;
            cnt += x;
        }
        cout << (nm ? 100 * cnt * (100 - p) / nm / 100:0) << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<char,int>ma;
  string S;
  cin>>S;
  rep(i,S.length())ma[S[i]]++;
  if(ma.size()==1){cout<<S.length()<<endl<<1<<endl;return 0;}
  vector<int>A(S.length());
  int c = 0;
  for (int i = 1; i < S.size(); i++){
    if (i+A[i-c] < c+A[c]) {
      A[i] = A[i-c];
    } else {
      int j = max(0, c+A[c]-i);
      while (i+j < S.size() && S[j] == S[i+j]) ++j;
      A[i] = j;
      c = i;
    }
  }
  A[0]=S.length();
  vector<bool>G(S.length()+1,0);
  for (int i = 1; i <= S.length(); i++) { G[i] = true; }
  for (int p = 1; p < S.length(); p++)
  {
    for (int k = 2; (k - 1) * p <= A[p]; k++) { G[k * p] = false;}
  }
  if(G[S.length()]==1){cout<<1<<endl<<1<<endl;return 0;}

  int l=S.size();
  reverse(all(S));
  c = 0;
  fill(all(A),0);
  for (int i = 1; i < S.size(); i++){
    if (i+A[i-c] < c+A[c]) {
      A[i] = A[i-c];
    } else {
      int j = max(0, c+A[c]-i);
      while (i+j < S.size() && S[j] == S[i+j]) ++j;
      A[i] = j;
      c = i;
    }
  }
  A[0]=S.length();
  for (int p = 1; p < S.length(); p++)
  {
    for (int k = 2; (k - 1) * p <= A[p]; k++) { G[l-k * p] = false;}
  }




  int cnt=0;
  for(auto i:G){cnt+=i;}
  cout<<2<<endl<<cnt<<endl;




  return 0;

}


Measured memory_bytes: 2844
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
ll v[maxn],phi[maxn],prime[maxn];
ll m=0;
inline void euler(int n=400000){
memset(v,0,sizeof(v));
  m=0;
    for(int i=2;i<=n;i++){
        if(!v[i]) v[i]=i,prime[++m]=i,phi[i]=i-1;
        for(int j=1;j<=m;j++) {
            if(prime[j]>v[i]||prime[j]>n/i) break;
            v[i*prime[j]]=prime[j];
            phi[i*prime[j]]=phi[i]*(i%prime[j]?prime[j]-1:prime[j]);
        }
    }
}
ll n,k;
inline ll mpow(ll a,ll b){
    ll ans=1%mod;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main() {
    phi[1]=1;
    euler();
    scanf("%lld %lld",&n,&k);
    ll ans=0,res=0;
    for(int i=1;i<=k;i++){
        res=mpow(k/i,n);
        // cout<<res<<" "<<phi[i]<<"\n";
        res=(res*phi[i])%mod;
        ans=(ans+res)%mod;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 11088
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int A;
  int B;
  int i;
  int ans;

  
  cin >> A;
  cin >> B;
  i=A%B;
  ans=(A-i)/B;
  if(i==0){
  }else{
    ans+=1;
  }
  cout << ans;
}



Measured memory_bytes: 888
#include <cstdio>
#include <map>
using namespace std;

map <int, int> have, need;

int main() {
	int N;
	scanf("%d", &N);
	while (N--) {
		int x;
		scanf("%d", &x);
		have[x]++;
	}
	int M;
	scanf("%d", &M);
	while (M--) {
		int x;
		scanf("%d", &x);
		need[x]++;
	}
	bool ok = true;
	for (auto it : need)
		ok &= have[it.first] >= it.second;
	puts(ok ? "YES" : "NO");
	return 0;
}			

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

long long n,s;
inline long long f(long long b,long long n)
{
	if(n<b)
		return n;
	return f(b,n/b)+n%b;
}
int main()
{
	scanf("%lld%lld",&n,&s);
	if(s==n)
		{
			printf("%lld\n",n+1);
			return 0;
		}
	if(s>n)
		{
			printf("-1\n");
			return 0;
		}
	for(long long i=2; i<=sqrt(n)+1; ++i)
		{
			if(f(i,n)==s)
				{
					printf("%lld\n",i);
					return 0;
				}
		}
	long long ji=n-s,ans=1e11;
	for(long long i=1; i*i<=ji; ++i)
		{
			if(ji%i==0)
				{
					long long b=ji/i+1;
					if(f(b,n)==s)
						ans=min(ans,b);
				}
		}
	if(ans==1e11)
		printf("-1\n");
	else
		printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
const long long MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

w, h, x, y = map(int, readline().split())

ans = w * h / 2
if x == w / 2 and y == h / 2:
    print(ans, '1')
else:
    print(ans, '0')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()

{
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

int a,b,c,k;

int main()
{
    read(a);
    read(b);
    read(c);
    read(k);
    if(k>a+b) printf("%d",a-(k-a-b));
    else if (k<a) printf("%d",k);
    else printf("%d",a);
    return 0;
}

Measured memory_bytes: 3800
import java.util.Scanner;
 
public class Main {  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt() * 100;
    int B = sc.nextInt() * 100;
    int C = sc.nextInt();
    int D = sc.nextInt();
    int E = sc.nextInt();
    int F = sc.nextInt();
    int total =0, sugar =0;
    double ansCon =0, con =0, maxCon = (double)E / (100 + E);
    for (int i =0; i<=F; i+=A) {
      for (int j =0; j<=F; j+=B) {
        if (i ==0 && j ==0) break;
        for (int k =0; k<=F-i-j; k+=C) {
          for (int l =0; l<=F-i-j-k; l+=D) {
            con = (double)(k + l) / (i + j + k + l);
            if (i + j + k + l <= F && con >= ansCon && con <= maxCon) {
              ansCon = con;
              total = i + j + k + l;
              sugar = k + l;            
            }
          }
        }
      } 
    }
    System.out.println(total + " " + sugar);  
  }
}

Measured memory_bytes: 22740
// Problem : D - .. (Double Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
vector<int> adj[N];
bool vis[N],vis1[N];
void dfs(int child)
{
	vis1[child] = true;
	for(auto it:adj[child])
	{
		if(!vis1[it])
		dfs(it);
	}
}
int par[N];
void dfs1(int child,int pare)
{
	par[child] = pare;
	vis[child] = true;
	for(auto it:adj[child])
	{
		if(!vis[it])
		dfs1(it,child);
	}
}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,m;
		cin>>n>>m;
		for(int i=0,u,v;i<m;++i)
		{
			cin>>u>>v;
			adj[u].pb(v);
			adj[v].pb(u);
		}
		dfs(1);
		bool flag = true;
		for(int i=1;i<=n;++i)
		if(vis1[i]==0)
		flag = false;
		if(!flag)
		{
			cout<<"No";
			return 0;
		}
		cout<<"Yes\n";
		/*dfs1(1,-1);
		for(int i=2;i<=n;++i)
		cout<<par[i]<<"\n";  */
		queue<int> q;
		q.push(1);
		vis[1] = true;
		while(!q.empty())
		{
			int x = q.front();
			q.pop();
			for(auto it:adj[x])
			{
				if(!vis[it])
				{
					vis[it] = true;
					par[it] = x;
					q.push(it);
				}
			}
		}
		for(int i=2;i<=n;++i)
		cout<<par[i]<<"\n";  	
    }
    return 0;
}


Measured memory_bytes: 24512
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
vector<long int> li;

void primeFactorization(long int n,long int N)
{
    long int a = 2;
    //vector<long int> res;
    //int pre = a;
    int cnt=0;

    while (n >= a * a) {
        if (n % a == 0) {
            //res.push_back(a);//cout << a << " * ";
            n /= a;
            cnt++;
            if((cnt%N)==0)li.push_back(a);
        } else {
            a++;
            cnt=0;
        }
    }
    //res.push_back(n);//cout << n<<endl;
    if((cnt%N)==(N-1)&&n==a)li.push_back(a);
    //return res;    
}

int main()
{
    long int N,P;
    
    cin >> N >> P;
    
    long int r=1;
    
    if(N==1)r=P;
    else{
        primeFactorization(P,N);
 
        for(int x : li){
	        r*=x;
        }       
    }
    cout << r <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, x, c = M()
print('A' + x[0] + 'C')

Measured memory_bytes: 74680
#include <iostream>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int s = 0;
  for (int i = 1; i <= N; ++i) {
    if (to_string(i).length() % 2 == 1) s+=1;
  }
  
  cout << s << endl;
}

Measured memory_bytes: 256
N,D = map(int,input().split())
List = []
for _ in range(N):
    List.append(list(map(int,input().split())))
Answer = 0
Count = 0

for i in range(N):
    for j in range(1,N):
        if i+j > N-1:
            continue
        for k in range(D):
            Answer += (List[i][k]-List[i+j][k])**2
        if (int(Answer**(1/2)))**2 == Answer :
            Count += 1
        Answer = 0

print(Count)


Measured memory_bytes: 38256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def main():
    N = int(input())
    N_divisors = make_divisors(N)
    mi = N_divisors[0] + N // N_divisors[0]
    for i in range(len(N_divisors)):
        c_mi = N_divisors[i] + N // N_divisors[i]
        if (c_mi <= mi):
            mi = c_mi
    print(mi-2)
    return 0
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);


	ll a;
	ld b;
	cin>>a>>b;
	ll ans = a*b;
	cout<<ans;

    return 0;
}


Measured memory_bytes: 3744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		for (int i = 0; i < 3001; i++) {
			String line = sc.nextLine();
			String[] a = line.split(" ");
			int x = Integer.parseInt(a[0]);
			int y = Integer.parseInt(a[1]);
			if (x == 0 && y == 0) {
				break;
			}
			if (x >= y) {
				System.out.println(y + " " + x);
			} else {
				System.out.println(x + " " + y);
			}
		}
	}
}

Measured memory_bytes: 34928
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	static void exec(Scanner in, PrintStream out) {
		in.nextInt();
		int Q = in.nextInt();
		String S = in.next();
		List<Integer> found = new ArrayList<>();
		for (int i = 0; i < S.length();) {
			int r = S.indexOf("AC", i);
			if (r >= 0) {
				found.add(r);
				i = r + "AC".length();
			} else {
				break;
			}
		}
		for (int i = 0; i < Q; i += 1) {
			int l = in.nextInt();
			int r = in.nextInt();
			int begin = Collections.binarySearch(found, l - 1);
			if (begin < 0) {
				begin = -(begin + 1);
			}
			int end = Collections.binarySearch(found, r - 1);
			if (end < 0) {
				end = -(end + 1);
			}
			out.println(end - begin);
		}
	}

	public static void main(String[] args) {
		exec(new Scanner(System.in), System.out);
	}

}


Measured memory_bytes: 94580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
/*
 execution in cmd of windows: g++ p1.cpp -op1
  
  
  p1
 
 */
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))  
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 1000000007;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD=1e9+7;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)
#define cs1 ll t;t=1;while(t--)

int main()
{
   #ifndef ONLINE_JUDGE
        ifstream cin("in.in");
        ofstream cout("out.out");
    #endif
    
        io;
        //////////////////////////////////
         cs1{
             ll i,j,s=0,c,k,q=0,n,m=0,e;
             cin>>n;
             for(i=1;i<n;i++){
                s=s+(ll)(n-1)/i;
             }
             cout<<s nl;
        }
        //////////////////////////////////
        cer;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin >> n;

    if(n==1){
        cout << "Hello World";
        return 0;
    }
    
    else if(n==2){
        cin >> a >> b;
        cout << a+b;
        return 0;
    }
}


Measured memory_bytes: 3644
#include <cstdio>
int main() {
  int n, ans=0;
  long long d, x, y, dis2;
  scanf("%d%lld", &n, &d);
  for(int i=0;i<n;i++) {
    scanf("%lld%lld", &x, &y);
    dis2 = x*x + y*y;
    if(dis2 <= d*d) ans++; 
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll mod = 1e9 + 7;
vector<vector<ll> > g;
ll k;
ll dfs(ll now , ll from ){
    ll use_col = k-2;
    if( from == -1 ){
	use_col ++ ;
    }
    if( k < g[now].size() ){
	return 0;
    }
    ll res = 1;
    for( ll i= 0;i<g[now].size();i++){
	if(g[now][i] == from ) continue;
	res *= use_col ;
	res %= mod ;
	use_col--;
	res *= dfs(g[now][i], now);
	res %= mod ;
    }
    return res;
}

int main(){
    ll n;
    cin>>n>>k;
    g = vector<vector<ll> > (n);
    for(int i=0;i<n-1;i++){
	ll a,b;
	cin>>a>>b;
	a--,b--;
	g[a].push_back(b);
	g[b].push_back(a);
    }
    ll r = 0;
    for(int i=0;i<n;i++)if(g[i].size() == 1 ) r = i;
    cout<< ( k *  dfs(r,-1 ) )%mod << endl;
    return 0;
}


Measured memory_bytes: 13568
// ABC171-C
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


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

    ll n;
    cin>>n;
    string ans="";
    // ll max_=pow(10,15)+1;
    // ll now=26;
    // int sou=1;
    // while(now<max_){
    //     now*=26;
    //     sou++;
    // }
    // cout<<sou<<endl;
    while(true){
        if(n==0) break;
        n--; //1の位の数を0-25にする。
        ans+=char(97+(n%26));
        n/=26; //1の位を消す。 
    }
    reverse(all(ans));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>

int main()
{
    long long N, X;
    scanf("%lld %lld", &N, &X);
    int L;
    int ans = 1;
    for (int i = 0; i < N; i++) {
        scanf("%d", &L);
        X -= L;
        if (X < 0) {
            printf("%d\n", ans);
            break;
        }
        ans++;
        if (i == N - 1) {
            printf("%d\n", N + 1);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int main(){
  int N;
  scanf("%d%*c", &N);

  VI seq(N);
  REP(i, 0, N){
    scanf("%d ", &seq[i]);
  }

  int s = 0;

  REP(i, 0, N){
    int mi = INF;
    int index;
    REP(j, i, N){
      if(mi > seq[j]){
        mi = seq[j];
        index = j;
      }
    }
    if(mi != INF){
      if(seq[i] != seq[index]){
        int tmp = seq[i];
        seq[i] = mi;
        seq[index] = tmp;
        s++;
      }
    }
  }
  REP(i, 0, N){
    if(i > 0){
      printf(" ");
    }
    printf("%d", seq[i]);
  }
  printf("\n");
  printf("%d\n", s);

  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;
int N,cnt[110] = {};
ll p[110],q[110],r[110],b[110],dp[110] = {};

ll gcd(ll n,ll m){
    assert(n!=0);
    assert(m!=0);
    if(n%m==0) return m;
    else return gcd(m,n%m);
}

void dfs(int n){
    if(n==0){
        dp[0] = 1;
    }else{
        dfs(r[n]); dfs(b[n]);
        assert(dp[r[n]] != 0);
        assert(dp[b[n]] != 0);
        assert(p[n] != 0);
        assert(q[n] != 0);
        ll g = gcd(dp[r[n]]*p[n],dp[b[n]]*q[n]);
        assert(g!=0);
        dp[n] = (dp[r[n]]*p[n])/g*dp[b[n]]+(dp[b[n]]*q[n])/g*dp[r[n]];
    }
    assert(dp[n]!=0);
}

int main(){
    while((cin >> N) && (N>0)){
        int par;
        for(int i=0;i<=N;i++) cnt[i] = 0;
        for(int i=1;i<=N;i++){
            cin >> p[i] >> q[i] >> r[i] >> b[i];
            cnt[r[i]]++; cnt[b[i]]++;
        }
        for(int i=1;i<=N;i++) if(cnt[i]==0) par = i;
        dfs(par);
        cout << dp[par] << endl;
    }
}


Measured memory_bytes: 3096
N = int(input())
H = list(map(int,input().split()))
count = 0
answer = 0

for i in range(N - 1):
	if H[i + 1] <= H[i]:
		count = count + 1
	else:
		if answer < count:
			answer = count
			count = 0
		else:
			count = 0

if answer < count:
	answer = count
	
print(answer)

Measured memory_bytes: 14252
def main():
     x,n = map(int,input().split())
     L = list(map(int,input().split()))
     i = 0
     if n == 0 or x not in L:
          print(x)
          return 0
     while(True):
          i += 1
          if x - i not in L:
               print(x - i)
               return 0
          if x + i not in L:
               print(x + i)
               return 0
main()

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

using namespace std;

const int MAX = 2 * 1e5;
const int MOD = LONG_MAX;

long long fac[MAX], finv[MAX], inv[MAX];


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] ) ;
}


int main(void) {
	long long N, tmp, ans,sum=0;

	cin >> N;

	vector<long long> A(N+1), count(N+1, 0);//, sum(N+1, 0);

	// 前処理
	COMinit();

	for (long long i = 0; i < N; i++) {
		cin >> tmp;
		A[i] = tmp;
		count[tmp] ++;
	}

	for (long long i = 1; i <= N; i++) {
		// sum[i] =  sum[i-1] + COM(count[i], 2);
        sum =  sum +  (count[i]*(count[i]-1)/2); //COM(count[i], 2);
	}

	for (long long i = 0; i < N; i++) {
		ans = sum - (count[A[i]] - 1);
        cout << ans << endl;
	}



	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

const double INF = 1e+9;
const double EPS = 1e-9;
const int MAX_N = 15;

int main(){
	int n;
	cin >> n;
	
	int ID[MAX_N], d[MAX_N], w[MAX_N];
	for(int i=0 ; i < n ; i++ ){
		cin >> ID[i] >> d[i] >> w[i];
	}
	
	// dp[s][i] := 訪れた蔵 s(集合), 現在の蔵 i のときの最小の時間
	double dp[1<<MAX_N][MAX_N];
	// ws[s] := 訪れた蔵 s(集合)から千両箱の重さを返す.
	int ws[1<<MAX_N];
	// p[s][i] := 訪れた蔵 s(集合), 現在の蔵 i のときの一つ前の蔵
	int p[1<<MAX_N][MAX_N];
	
	// 任意の集合に対して重さを計算しておく
	for(int k=0 ; k < (1<<n) ; k++ ){
		for(int i=0 ; i < n ; i++ ){
			ws[k|(1<<i)] = ws[k] + 20 * w[i];
		}
	}
	
	// 初期化
	for(int s = 1 ; s < (1<<n) ; s++ ){
		fill( dp[s] , dp[s]+n , INF );
	}
	// bitDP
	for(int s=0 ; s < (1<<n) ; s++){
		for(int j=0 ; j < n ; j++ ){
			for(int i=0 ; i < n ; i++ ){
				if( (s >> i & 1) == 0 ){
					double v = dp[s][j] + abs(d[i]-d[j]) / 2000.0 * (70 + ws[s]);
					if( v + EPS < dp[s|1<<i][i] ){
						dp[s|1<<i][i] = v;
						p[s|1<<i][i] = j;
					}
				}
			}
		}
	}
		
	// path を求める.
	int m = 0;
	for(int i=0 ; i < n ; i++ ){
		if( dp[(1<<n)-1][i] + EPS < dp[(1<<n)-1][m] ){
			m=i;
		}
	}
	vector<int> path;
	for(int i=m, sup=(1<<n)-1 ; sup != 0 ; ){
		path.push_back( i );
		int j = p[sup][i];
		sup &= ~(1<<i);
		i=j;
	}
	reverse( path.begin() , path.end() );
	for(int i=0 ; i < path.size() ; i++ ){
		cout << ID[ path[i] ];
		if( i == path.size()-1 ){
			cout << endl;
		}else{
			cout << " ";
		}
	}
}

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

bool isprime(int x) {
  if (x == 2) return true;
  else if(x < 2 || x % 2 == 0) return false;
  int i = 3;
  while(i <= sqrt(x)) {
    if( x % i == 0 ) return false;
    i = i + 2;
  }

  return true;
}

int main() {
  int a, d, n;
  while(cin >> a >> d >> n){
    if(a == 0 && d == 0 && n == 0) break;
    int i = 0, j = 0;
    int sum;
    while(true) {
      sum = a + i * d;
      if(isprime(sum))j++;
      if(j == n) {
        cout << sum << endl;
        break;
      }
      i++;
    }
  }

  return 0;
}

Measured memory_bytes: 3048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var H = NextInt();
            var W = NextInt();
            var matrix = new int[10, 10];
            var diff = Enumerable.Repeat(int.MaxValue, 10).ToArray();
            long count = 0;

            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    matrix[i, j] = NextInt();
                }
            }

            for (int k = 0; k < 10; k++) {
                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 10; j++) {
                        matrix[i, j] = Math.Min(matrix[i, j], matrix[i, k] + matrix[k, j]);
                    }
                }
            }

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    var tmp = NextInt();
                    if(tmp != -1) {
                        count += matrix[tmp, 1];
                    }
                }
            }

            Console.WriteLine(count);
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll num=-1;
	for(ll i=1;i<=100000;i++)
	{
		ll a1=(ll)(i*1.0*0.08);
		ll b1=(ll)(i*1.0*0.1);
		if(a1==a&&b1==b)
		{
			num=i;
			break;
		}
	}
	printf("%lld",num);
 } 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a * b < c * d)
		cout << c * d << "\n";
	else
		cout << a * b << "\n";
}

Measured memory_bytes: 3572
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import defaultdict

m = defaultdict(int)

n = ni()
for i in range(n):
    a = ni()
    if m[a] == 0:
        m[a] = 1
    else:
        m[a] = 0

print(sum(m.values()))

Measured memory_bytes: 15460
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdio>

using namespace std;

int N, M;

struct UnionFind {
  int* data;

  UnionFind(int size) {
    data = (int*)malloc(sizeof(int) * size);
    for (int i = 0; i < N; ++i) {
      data[i] = -1;
    }
  }

  ~UnionFind() {
    free(data);
  }

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

  void insert(int x, int y) {
    if (root(x) == root(y)) {
      return;
    }
    connect(root(x), root(y));
  }

  bool isRoot(int x) {
    return data[x] == -1;
  }

  void connect(int from, int to) {
    data[from] = to;
  }

  int root(int x) {
    if (data[x] == -1) {
      return x;
    }
    int r = root(data[x]);
    connect(x, r);
    return r;
  }
};
      

int main() {
  cin >> N >> M;
  int p[N];
  int q[M][2];
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> q[i][0] >> q[i][1];
  }

  struct UnionFind uf = UnionFind(N);

  for (int i = 0; i < M; ++i) {
    uf.insert(q[i][0]-1, q[i][1]-1);
  }

  int count = 0;
  for (int i = 0; i < N; ++i) {
    if (uf.isUnion(p[i]-1, i)) {
      ++count;
    }
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  x = sc.nextInt();
     int y = sc.nextInt();
     int z = sc.nextInt();
     System.out.print(z);
     System.out.print(" ");
     System.out.print(x);
     System.out.print(" ");
     System.out.println(y);
   }
}


Measured memory_bytes: 21588
package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
func nextInt() int64{
  sc.Scan()
  i, e :=strconv.ParseInt(sc.Text(), 10, 64)
  if e!=nil{
    panic(e)
  }
  return i
}
func min (a *int64, b int64) bool{
  if *a>b{
    *a=b
    return true
  }
  return false
}
func abs(a int64) int64{
  if a<0{
    return a*-1
  }else{
    return a
  }
}
func main(){
  var i int64
  dp:=make([]int64, 100001)
  sc.Split(bufio.ScanWords)
  n:=nextInt()
  a:=make([]int64, n)
  for i=0;i<n;i++{
    a[i]=nextInt()
  }
  for i=0;i<100001;i++{
    dp[i]=1000000000
  }
  dp[0]=0
  for i=1;i<n;i++{
    min(&dp[i], dp[i-1]+abs(a[i]-a[i-1]))
    if i>1{
      min(&dp[i], dp[i-2]+abs(a[i]-a[i-2]))
    }
  }
  fmt.Println(dp[n-1])
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
static const int MAX = 26;

int CNT[MAX];

int main() {
    string w;
    cin >> w;
    
    for (int i = 0; i < w.size(); i++) CNT[w[i] - 'a'] ++;
    
    int i = 0;
    for (; i < MAX; i++) if (CNT[i] % 2) break;
    
    if (i == MAX) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> x(N);
    for(int i=0;i<N;i++) cin >> x[i];

    int ans = 0;
    for(int i=0;i<N;i++) ans+= min(x[i],K-x[i])*2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n,w=map(int,input().split())
li=[[int(i) for i in input().split()] for j in range(n)]
 
dp = [[0 for i in range(w+1)] for j in range(n+1)]
 
ans = 0
for i in range(n):
    for j in range(1,w+1):
        if li[i][0] <= j:
            dp[i+1][j]=max(dp[i][j], dp[i][j-li[i][0]]+li[i][1])
        else:
            dp[i+1][j]=dp[i][j]
        ans = max(ans,dp[i+1][j])
print(ans)

Measured memory_bytes: 173704
#include <iostream>

using namespace std;

int main(void)
{
    uint32_t N, H, W;
    cin >> N >> H >> W;

    int ans = 0;
    for(uint32_t i = 0; i < N; ++i)
    {
        uint32_t ai, bi;
        cin >> ai >> bi;
        ans += min(ai / H, bi / W);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
from __future__ import print_function
from sys import stdin
class Node:
    def __init__(self, id):
        self.id = id
        self.left = None
        self.right = None
        self.parent = None

def preorder_tree_walk(root):
    print('', root.id, end='')
    if root.left != None:
        preorder_tree_walk(root.left)
    if root.right != None:
        preorder_tree_walk(root.right)

def inorder_tree_walk(root):
    if root.left != None:
        inorder_tree_walk(root.left)
    print('', root.id, end='')
    if root.right != None:
        inorder_tree_walk(root.right)

def insert(root, z):
    y = None
    x = root
    while isinstance(x, Node):
        y = x
        if z.id < x.id:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y == None:
        root = z
    elif z.id < y.id:
        y.left = z
    else:
        y.right = z
    return root

def find(root, x):
    while root != None and x != root.id:
        if x < root.id:
            root = root.left
        else:
            root = root.right
    return root


n = int(raw_input())
root = None
for i in xrange(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        num = int(cmd[7:])
        root = insert(root, Node(num))
    elif cmd.startswith('p'):
        inorder_tree_walk(root)
        print()
        preorder_tree_walk(root)
        print()
    else:
        # find
        num = int(cmd[5:])
        if find(root, num) != None:
            print('yes')
        else:
            print('no')
    

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


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

class CHAndV {
public:
	void solve(std::istream& in, std::ostream& out) {
        int h,w,k;
        in >> h >> w >> k;
        vector<string> c(h);
        rep(i,h){
            in >> c[i];
        }
        int ph = pow(2,h);
        int pw = pow(2,w);
        int ans = 0;
        for(int i=0;i<ph;i++){
            for(int j=0;j<pw;j++){
                int t=0;
                for(int m=0;m<h;m++){
                    for(int l=0; l<w;l++){
                        if(!(i>>m&1) && !(j>>l&1) && c[m][l]=='#'){
                            t++;
                        }
                    }
                }
                if(k==t)ans++;
            }
        }
        out << ans << endl;
	}
};


int main() {
	CHAndV solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4032
//???????????????
#include <iostream>
using namespace std;

static int selectionSort(int *A, int N){
	int minj, temp, count=0;
	for (int i = 0; i < N; i++){
		minj = i;
		for (int j = i+1; j < N; j++){
			if (A[j] < A[minj]){
				minj = j;
			}
		}

		if (minj != i){
			temp = A[i];
			A[i] = A[minj];
			A[minj] = temp;
			count++;
		}
	}

	return count;
}

int main(void){
	int N, *A, count;

	cin >> N;

	A = new int[N];

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

	count = selectionSort(A, N);

	for (int i = 0; i < N; i++){
		cout << A[i];
		if (i != N - 1){
			cout << " ";
		}
	}

	cout << "\n" << count << "\n";

	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_B&lang=jp

struct Node {
    int key;
    Node *l, *r, *p;
};

Node *root, *NIL;

static Node* find(Node *u, int key) {
    while(u != NIL && u->key != key) {
        if (key < u->key) {
            u = u->l;
        } else {
            u = u->r;
        }
    }
    return u;
}

static void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

    while(x!=NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->l;
        } else {
            x = x->r;
        }
    }
    z->p = y;

    if (y==NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->l = z;
        } else {
            y->r = z;
        }
    }

    z->p = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->l = z;
        } else {
            y->r = z;
        }
    }
}

static void inorder(Node* n) {
    if (n == NIL) return;
    inorder(n->l);
    printf(" %d", n->key);
    inorder(n->r);
}

static void preorder(Node* n) {
    if (n == NIL) return;
    printf(" %d", n->key);
    preorder(n->l);
    preorder(n->r);
}


int main() {

    int n; cin >> n;
    REP(i, n) {
        string com; cin >> com;
        if (com == "find") {
            int key; cin >> key;
            Node *t = find(root, key);
            cout << (t== NIL?"no":"yes") << "\n";
        }
        if (com == "insert") {
            int key; cin >> key;
            insert(key);
        }
        if (com == "print") {
            inorder(root);
            cout << "\n";
            preorder(root);
            cout << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 21996
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
long long a[n];
long long sum=0;
for(long long i=0;i<n;i++){
  cin>>a[i];
  sum+=a[i];
}
long long p=sum/n;
long long ans=0;
long long temp=0;
for(long long i=0;i<n;i++){
  ans+=(p-a[i])*(p-a[i]);
}
for(long long i=0;i<n;i++){
  temp+=(p-1-a[i])*(p-1-a[i]);
}
ans=min(ans,temp);
temp=0;
for(long long i=0;i<n;i++){
  temp+=(p+1-a[i])*(p+1-a[i]);
}
ans=min(ans,temp);
cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k, x int
	fmt.Scan(&k, &x)
	for i := x - k + 1; i <= x+k-1; i++ {
		if i == x-k+1 {
			fmt.Printf("%d", i)
		} else {
			fmt.Printf(" %d", i)
		}
	}
	fmt.Println()
}


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


int main() {
    int H, W, M;
    std::cin >> H >> W >> M;

    std::vector<std::pair<int, int>> pos;
    std::vector<int> hist_h(H, 0), hist_w(W, 0);

    for (int i = 0; i < M; i++) {
        int h, w;
        std::cin >> h >> w;
        h--; w--;
        hist_h[h] += 1;
        hist_w[w] += 1;
        pos.emplace_back(h, w);
    }

    int max = 0;
    long long int count = 0;
    for (auto p : pos) {
        int val = hist_h[p.first] + hist_w[p.second] - 1;
        if (val > max) {
            max = val;
            count = 1;
        } else if (val == max) {
            count++;
        }
    }

    int max_h = hist_h[0];
    long long int count_h = 1;
    for (int i = 1; i < H; i++) {
        if (hist_h[i] == max_h) {
            count_h++;
        } else if (hist_h[i] > max_h){
            max_h = hist_h[i];
            count_h = 1;
        }
    }

    int max_w = hist_w[0];
    long long int count_w = 1;
    for (int i = 1; i < W; i++) {
        if (hist_w[i] == max_w) {
            count_w++;
        } else if (hist_w[i] > max_w) {
            max_w = hist_w[i];
            count_w = 1;
        }
    }

    if (max == max_h + max_w - 1 && count_h * count_w <= count) {
        std::cout << max_h + max_w - 1 << std::endl;
    } else {
        std::cout << max_h + max_w << std::endl;
    }
}


Measured memory_bytes: 9780
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  string s; cin >> s;
  ll ans = 0;
  ll n = s.size();
  vector<ll> run;
  ll cnt = 1;
  REP(i,n-1){
    if(s[i] == s[i+1]) cnt++;
    else{
      run.push_back(cnt);
      cnt = 1;
    }
  }
  run.push_back(cnt);
  ll m = run.size();
  ll i = 0;
  while(i<m){
    if(run[i]%3==2){
      ans += run[i]/3 * 2 + 1;
      if(i!=m-1){
       run[i+1] -= 1;
        ans++;
      } 
    }else{
      ans += run[i] -run[i]/3;
    }
    i++;
  }
  cout << ans << endl;
}



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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long H;
    std::cin >> H;
    long long W;
    std::cin >> W;
    long long N;
    std::cin >> N;

    if (H > W) swap(H, W);
    cout << (N + W - 1) / W << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    int i;

    int sum = 0;
    char W[11], T[1001];

    scanf("%s", W);
    for( i = 0; W[i]; ++i ) W[i] = tolower(W[i]);
    while( 1 ){
        scanf("%s", T);
        if( strcmp("END_OF_TEXT", T) == 0 ) break;
        for( i = 0; T[i]; ++i ) T[i] = tolower(T[i]);
        if( strcmp(W, T) == 0 ) ++sum;
    }

    printf("%d\n", sum);

    return 0;
}



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

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


int main() {

    int a;
    string s;
    cin >> a >> s;
    if (a < 3200) {
        cout << "red" << endl;
    } else {
        cout << s << endl;
    }


}


Measured memory_bytes: 256