akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),ans(n,0);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        ans.at(a.at(i)-1) += i+1;
    }
    for(int i=0;i<n;i++){
        cout << ans.at(i) << " " ;
    }
    cout << endl;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a, b;

    while (true) {
      a = scanner.nextInt();
      b = scanner.nextInt();
      if (a == 0 && b == 0) break;
      for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) System.out.printf("#");
        System.out.println();
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 54816
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int h,w;cin>>h>>w;
  string grid[w][h];
  queue<pair<int,int>> q;
  int cnt_b = 0;
  for(int i=0;i<h;++i){
    string s;cin >> s;
    for(int j=0;j<w;++j){
      auto sub = s.substr(j,1);
      grid[j][i] = sub;
      if(sub=="#") {
        ++cnt_b;
        q.push(make_pair(j,i));
      }
    }
  }
  int out = 0;
  while (cnt_b< h*w) {
    vector<pair<int,int>> vp;
    while(!q.empty()){
      auto p = q.front();
      q.pop();
      int x = p.first;
      int y = p.second;
      if(x-1>=0){
        if(grid[x-1][y]=="."){
          grid[x-1][y] = "#";
          ++cnt_b;
          vp.push_back(make_pair(x-1,y));
        }
      }
      if(x+1<w){
        if(grid[x+1][y]=="."){
          ++cnt_b;
          grid[x+1][y] = "#";
          vp.push_back(make_pair(x+1,y));
        }
      }
      if(y-1>=0){
        if(grid[x][y-1]=="."){
          ++cnt_b;
          grid[x][y-1] = "#";
          vp.push_back(make_pair(x,y-1));
        }
      }
      if(y+1<h){
        if(grid[x][y+1]==".") {
          ++cnt_b;
          grid[x][y+1] = "#";
          vp.push_back(make_pair(x,y+1));
        }
      }
    }
    for(auto&& e: vp)q.push(e);
    ++out;
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 63120
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long int arr[105];
long long int dp[3][100005],n;
long long int solve(long long int player,long long int val)
{
    long long int ans=0,pl,flag,i;
    pl=(player==1?2:1);
    if(val==0)
    {
        dp[player][val]=pl;
        return dp[player][val];
    }
    if(val<0)
    {
        return player; 
    }
    if(dp[player][val]!=-1)
        return dp[player][val];
    ans=pl;
    for(i=0;i<n;i++)
    {
        flag=solve(pl,val-arr[i]);
        if(flag==player)
        {
            ans=flag;
            break;
        }
    }
    dp[player][val]=ans;
    return dp[player][val];    
}
int main()
{
    long long int i,j,k,a,b,ans=0,sum=0,cnt=0;
    cin >> n >> k;
    //long long int arr[n];
    for(i=0;i<n;i++)
        cin >> arr[i];
   // cout << "ok" << endl;
    memset(dp,-1,sizeof(dp));
    a=solve(1,k);
    if(a==1)
        cout << "First" << endl;
    else
        cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 7296
from math import floor, sqrt
from collections import defaultdict
def factors(n):
    d = defaultdict(int)
    for i in range(2,floor(sqrt(n))+1):
        while n % i == 0:
            n //= i
            d[i] += 1
        if n == 1:
            break
    if n != 1:
        d[n] += 1
    return d
def inv(x, mod):
    k = mod - 2
    ret = 1
    while k > 0:
        if k&1:
            ret = (ret*x) % mod
        x = (x*x) % mod
        k >>= 1
    return ret
N, M = map(int,input().split())
mod = 10**9+7
dic = factors(M)
K = len(dic)
SIZE = N+max(dic.values()) if dic.values() else N
fact = [None]*(SIZE+1)
finv = [None]*(SIZE+1)
fact[0] = 1
for i in range(1,SIZE+1):
    fact[i] = (fact[i-1]*i) % mod
finv[SIZE] = inv(fact[SIZE], mod=mod)
for i in range(SIZE, 0, -1):
    finv[i-1] = (finv[i]*i) % mod
def comb(n,k):
    tmp = (finv[k]*finv[n-k]) % mod
    return (fact[n]*tmp) % mod
ans = 1
for p in dic:
    ans = (ans*comb(dic[p]+N-1, dic[p])) % mod
print(ans)

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

signed main() {
  string S;
  cin >> S;
  
  string T;
  for( int i = 0; i < S.size(); i++ ){
    for( int j = 0; j < S.size(); j++ ){
      T = S;
      T.erase(i, j);
      if ( T == "keyence" ){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  
  cout << "NO" << endl;
  
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int ans= 0;
    for(int i=0;i<s.size();i++){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = sc.next()

    var ans = StringBuilder()
    for (c in t) {
      var value = c
      if (c == '?') {
        value = 'D'
      }
      ans.append(value)
    }

    println(ans.toString())

}


Measured memory_bytes: 42404
package main

import "fmt"

func main(){
	var num,ans int
	var temp string
	MARCH := []int{0,0,0,0,0}
	fmt.Scan(&num)
	for i := 0; i < num ;i++{
		fmt.Scan(&temp)
		if string(temp[0]) == "M"{
			MARCH[0]++
		}else if string(temp[0]) == "A" {
			MARCH[1]++
		}else if string(temp[0]) == "R" {
			MARCH[2]++
		}else if string(temp[0]) == "C" {
			MARCH[3]++
		}else if string(temp[0]) == "H" {
			MARCH[4]++
		}
	}
	for i := 0;i<3;i++{
		for j := i+1;j<4;j++{
			for k :=j+1;k<5;k++{
				ans += MARCH[i]*MARCH[j]*MARCH[k]
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int x;
    cin >> x;
    int max= 0;
    int num;
    for(int i=1;i<=x;i++){
        num = i;
        for(int j=1;j<=x;j++){
            num*=i;
            if(num > x){
                break;
            }
            else{
                if(max < num){
                max = num;
            }
            }
            
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

#define INF  1000000000

int n, a, b, c;
int l[8];

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

int min3(int a, int b, int c)
{
  return min2(min2(a, b), c);
}

int min4(int a, int b, int c, int d)
{
  return min2(min2(a, b), min2(c, d));
}


int dfs(int cur, int p, int q, int r)
{
  if (cur == n){
    if (min3(p, q, r) > 0)
      return abs(a - p) + abs(b - q) + abs(c - r) - 30;
    else
      return INF;
  } else {
    int ret0 = dfs(cur + 1, p, q, r);
    int ret1 = dfs(cur + 1, p + l[cur], q, r) + 10;
    int ret2 = dfs(cur + 1, p, q + l[cur], r) + 10;
    int ret3 = dfs(cur + 1, p, q, r + l[cur]) + 10;
    return min4(ret0, ret1, ret2, ret3);
  }
}

    

int main(void)
{
  scanf("%d %d %d %d", &n, &a, &b, &c);
  for (int i = 0; i < n; i++)
    scanf("%d", &l[i]);

  printf("%d\n", dfs(0,0,0,0));

  return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int from, to;
    lint cost;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector< vector<lint> > dis(n);
    rep(i, n){
        dis[i].resize(n, LLINF);
        dis[i][i] = 0;
    }
    vector<edge> edges;
    rep(i, m){
        edge e;
        cin >> e.from >> e.to >> e.cost;
        --e.from;
        --e.to;
        dis[e.from][e.to] = e.cost;
        dis[e.to][e.from] = e.cost;
        edges.push_back(e);
    }
    for(int k = 0 ; k < n ; ++k){
        for(int i = 0 ; i < n ; ++i){
            for(int j = 0 ; j < n ; ++j){
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, m){
        edge e = edges[i];
        if(dis[e.from][e.to] < e.cost){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>


int main(void){

	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		
		printf("a > b\n");
		
	}else if(a < b){
		
		printf("a < b\n");
		
	}else{
		
		printf("a == b\n");
		
	}
	return 0;
}	
	

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(a,n);

  ll ans1=0, ans2=0;
  ll tmp1=0, tmp2=0;
  rep(i,n){
    tmp1+=a[i], tmp2+=a[i];
    if(i%2==0 && tmp1<=0) ans1+=-tmp1+1, tmp1=1;
    if(i%2==1 && tmp1>=0) ans1+=tmp1+1, tmp1=-1;

    if(i%2==0 && tmp2>=0) ans2+=tmp2+1, tmp2=-1;
    if(i%2==1 && tmp2<=0) ans2+=-tmp2+1, tmp2=1;
  }

  prt(min(ans1, ans2));
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll ans = 1;
    for(ll i = 1; i * i <= M; i++) {
        if(M % i)
            continue;
        if(i * N <= M)
            ans = max(ans, i);
        if(M / i * N <= M)
            ans = max(ans, M / i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int x,m,q,ans=0,a[59],b[59],c[59],d[59];
vector<int>v;
void dfs(int sz,int cur)
{
    if (sz==x)
    {
        int cnt=0;
        for (int i=0;i<q;i++){
            if (v[b[i]-1]-v[a[i]-1]==c[i])
                cnt+=d[i];
        }
        ans=max(ans,cnt);
        return;
    }
    for (int i=cur; i<=m; i++)
    {
        v.push_back(i);
        dfs(sz+1,i);
        v.pop_back();
    }
}
int main()
{
    FASTINOUT;
    cin>>x>>m>>q;
    for (int i=0; i<q; i++)
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(0,1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100005;

struct card {
	char suit;
	int value;
};

card A1[MAXN], A2[MAXN], L[MAXN/2], R[MAXN/2];

void merge(card A[], int left, int mid, int right){
	int n1 = mid - left, n2 = right - mid;
	for(int i = 0; i < n1; i++) L[i] = A[left+i];
	for(int i = 0; i < n2; i++) R[i] = A[mid+i];
	L[n1].value = R[n2].value = INF;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		if(L[i].value <= R[j].value)
			A[k] = L[i++];
		else
			A[k] = R[j++];
	}
}

void mergeSort(card A[], int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int partition(card A[], int p, int r){
	int x, i;
	card temp;
	x = A[r].value; 
	i = p - 1;
	for(int j = p; j < r; j++){
		if(A[j].value <= x){
			i++;
			temp = A[i]; A[i] = A[j]; A[j] = temp;
		}
	}
	temp = A[i+1]; A[i+1] = A[r]; A[r] = temp;
	return i+1;
}

void quickSort(card A[], int p, int r){
	if(p < r){
		int q = partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}

int main(){
	int n, stable = 1;
	char s[10];
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%s%d", s, &A1[i].value);
		A1[i].suit = s[0];
		A2[i] = A1[i];
	}
	mergeSort(A1, 0, n);
	quickSort(A2, 0, n-1);
	for(int i = 0; i < n; i++)
		if(A1[i].suit != A2[i].suit)
			stable = 0;
	if(stable)
		printf("Stable\n");
	else
		printf("Not stable\n");
	for(int i = 0; i < n; i++)
		printf("%c %d\n", A2[i].suit, A2[i].value);
	return 0;
}

Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}


int main()
{  
    
    fastio();

    ll n;
    cin>>n;
    vector<pll>v;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            v.pb({i,n/i});
        }
    }





    ll mn=1e18;
    for(auto u:v)
    {
       ll temp=u.first+u.second-2;
       if(temp<mn)
       {
           mn=temp;
       }
    }

    cout<<mn<<endl;



	return 0;
}




Measured memory_bytes: 3700
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC109
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            if ((A % 2 == 0) || (B % 2 == 0))
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

struct edge{
	int to, rev;
	ll cap;
};

vector<edge> g[225];
bool used[225];

void make_edge(int u, int v, ll c = 1ll, ll rc = 1ll){
	edge e;
	e.to = v; e.rev = g[v].l_ength(); e.cap = c;
	g[u].push_back(e);
	e.to = u; e.rev = g[u].l_ength()-1; e.cap = rc;
	g[v].push_back(e);
}

ll dfs(int s, int t, ll c){
	int i;
	ll f;
	edge e;
	if(s == t){
		return c;
	}
	used[s] = true;
	for(i=(g[s].l_ength()-1); i>=0; --i){
		e = g[s][i];
		if((!used[e.to]) && e.cap > 0ll){
			f = dfs(e.to, t, min(c, e.cap));
			if(f > 0ll){
				g[s][i].cap -= f;
				g[e.to][e.rev].cap += f;
				return f;
			}
		}
	}
	return 0ll;
}

int main(void){
	int h,w,i,j;
	ll f,ans=0ll;
	string s;
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> s;
		for(j=0; j<w; ++j){
			if(s[j]=='S'){
				make_edge(h+w,i,INFLL,0ll);
				make_edge(h+w,h+j,INFLL,0ll);
			}else if(s[j]=='T'){
				make_edge(i,h+w+1,INFLL,0ll);
				make_edge(h+j,h+w+1,INFLL,0ll);
			}else if(s[j]=='o'){
				make_edge(i,h+j);
			}
		}
	}
	while(true){
		fill(used,used+225,false);
		f = dfs(h+w,h+w+1,INFLL);
		if(!f){
			break;
		}
		ans += f;
	}
	cout << ((ans<h*w)?ans:(-1ll)) << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    IO;
    int n, x;
    cin >> n >> x;
    int cnt = x - n + 1;
    for(int i = 1; i <= n; i++)
        cout << cnt++ << ' ';
    for(int i = 1; i < n; i++)
        cout << cnt++ << ' ';
    return 0;
}


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

int main() {
  long int N;
  cin >> N;
  
  vector<long int> A(3*N);    
  for (int i = 0; i < 3*N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  long int sum = 0;

  for (int i = 1; i <= N; i++) {
    sum = sum + A.at(2*i-1);
  }  
   
  cout << sum << endl;
    
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int n,m;
    cin >> n >> m;
    vector<string> a(n);
    rep(i,n)cin >> a[i];
    vector<string> b(m);
    rep(i,m)cin >> b[i];
    bool exist = false;
    for(int ly=0;ly<n;++ly){
        for(int lx=0;lx<n;++lx){
            if(ly+m-1>=n or lx+m-1>=n) continue;
            bool match=true;
            for(int y=0;y<m;++y){
                for(int x=0;x<m;++x){
                    if(a[ly+y][lx+x]!=b[y][x]) match=false;
                    }
                }
            if(match) exist=true;
        }
    }
    if(exist)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3576
from collections import Counter
n,*v = map(int,open(0).read().split())
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = sorted([(i,v1[i]) for i in v1.keys()],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2[i]) for i in v2.keys()],key =lambda x:x[1],reverse=True)
if v1[0][0] != v2[0][0]:
  print(n-v1[0][1]-v2[0][1])
else:
  e1 = n-v2[0][1] if len(v1) == 1 else n-v1[1][1]-v2[0][1]
  e2 = n-v1[0][1] if len(v2) == 1 else n-v1[0][1]-v2[1][1]
  print(min(e1,e2))

Measured memory_bytes: 23580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
bool vis[200005];
vector<int>v[200005];
int sz = 0;
void dfs(int x){
    vis[x] = true;
    sz++;
    for(int y:v[x]){
        if(!vis[y])dfs(y);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    int ans = 1;
    for(int i=1;i<=n;i++){
        if(vis[i])continue;
        sz = 0;
        dfs(i);
        ans = max(ans,sz);
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 20988
a,b = map(int,input().split())

def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

aa = set(pf(a))
bb = set(pf(b))
ans = aa & bb

print(len(ans) + 1)

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

//ofstream outputfile("test.txt");
int main(){
    //outputfile.close();
    int n;
    while(cin>>n){
        if(n==0)break;
        int ans =0;
        int m[n][n];
        memset(m,0,sizeof(m));
        for(int a=1;a<n;a++){
            for(int l=a;l<n;l++){
                double v = (double)(l-a+1)/2;
//cout<<"a:"<<a<<" l:"<<l<<" v:"<<v<<" al:"<<((a+l)*v)<<endl;
                if(((a+l)*v)==n){
                    if(m[a][l]==1)continue;
                    ans++;
                    m[a][l]=1;
                }
            }
        }
        cout<<ans<<endl;
    }
}


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

int main()
{
multiset<int>s;
multiset<int>::iterator it;
  int n,x,c=0;
  cin>>n>>x;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
    s.insert(arr[i]);
  }
  int ii=0;
  for(it=s.begin();it!=s.end()&&ii<x;it++){
    c+=*it;

    ii++;
  }
  cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  LL a, b, k;
  cin >> a >> b >> k;
  if (k >= a) {
    k -= a, a = 0;
    if (k >= b) k -= b, b = 0;
    else b -= k;
  }
  else a -= k;
  cout << a << " " << b << endl;
  
  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int N,j;
    cin>>N;
    while(N--){
        int runcnt=0,j;
        char S[128000]={0};
        cin>>S;
            if(S[0]=='>'&&S[1]==39){
                int K=0;
                for(j=2;;j++){
                    if(S[j]=='='){
                        runcnt++;
                        K=1;
                    }
                    else if(S[j]=='#'){
                        break;
                    }
                    else {
                        cout<<"NA"<<endl;
                        goto end;
                    }
                }
                for(int i = j + 1;;i++){
                    if(S[i] == '='){
                        runcnt--;
                    }
                    else if(runcnt == 0 && S[i] == '~' && K == 1){
                        cout<<"A"<<endl;
                        goto end;
                    }
                    else{
                        cout<<"NA"<<endl;
                        goto end;
                    }
                }
            }
            else if(S[0] == '>' && S[1] == '^'){
                int F = 0;
                for(j = 2;;){
                    if(S[j] == 'Q' && S[j + 1] == '='){
                        j += 2;
                        F = 1;
                    }
                    else if(S[j] == '~' && S[j+1] == '~' && F == 1){
                        cout<<"B"<<endl;
                        goto end;
                    }
                    else{
                        cout<<"NA"<<endl;
                        goto end;
                    }
                }
            }
            else cout<<"NA"<<endl;
            end:;
    }
    return 0;
}

Measured memory_bytes: 1292
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX_N = 1e5;
int n, k, a[MAX_N + 1];
int main() {
    scanf("%d%d", &n, &k);
    int g = 0, m = 0;
    for(int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        if(!g) g = a[i];
        else g = __gcd(g, a[i]);
        m = max(m, a[i]);
    }
    puts(k % g == 0 && k <= m ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}

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


typedef long long ll;

int main(){
    ll W,H,N;
    cin >> W >> H >> N;
    ll lx=0,ly=0,hx=W,hy=H;
    for(ll i = 0; i < N ; i++){
      ll x,y,a;
      cin >> x >> y >> a;
      if (a==1 && lx < x) {
          lx=x;
      }
      if (a==2 && hx > x) {
          hx=x;
      }
      if (a==3 && ly < y) {
          ly=y;
      }
      if (a==4 && hy > y) {
          hy=y;
      }
    }
    cout << max((hx-lx),0LL)*max((hy-ly),0LL) << endl;

}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> ac(N+1, false);
    vector<int> p(N+1, 0);
    for (int i = 0; i < M; i++) {
        int a;
        string s;
        cin >> a >> s;
        if (ac[a]) continue;
        if (s == "WA") p[a]++;
        if (s == "AC") ac[a] = true;
    }
    int ansa = 0, ansp = 0;
    for (int i = 1; i <= N; i++) {
        if (ac[i]) {
            ansa++;
            ansp += p[i];
        }
    }
    cout << ansa << ' ' << ansp << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main()
{
    int n;
    cin >> n;
    vi march(5, 0);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') march[0]++;
        if (s[0] == 'A') march[1]++;
        if (s[0] == 'R') march[2]++;
        if (s[0] == 'C') march[3]++;
        if (s[0] == 'H') march[4]++;
    }
    function<ll (int, int, ll)> backtrack = [&](int level, int n, ll acc) {
        if (n <= 0) return acc;
        if (level >= 5) return 0LL;
        ll ans = 0;
        ans += backtrack(level + 1, n - 1, acc * march[level]);
        ans += backtrack(level + 1, n, acc);
        return ans;
    };
    cout << backtrack(0, 3, 1LL) << endl;
    return 0;
}


Measured memory_bytes: 256
import fractions

a,b,c = map(int, input().split())
if a % b == 0:
  if c == 0:
    print("YES")
  else:
    print("NO")
else:
  GCD = fractions.gcd(a,b)
  if c % GCD == 0:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 5048
fn main() {
    let n: i64 = read();
    let mut rtnc: i64 = ((n as f64).sqrt()) as i64;

    loop {
        if n % rtnc == 0 {
            let ans = rtnc - 1 + n / rtnc - 1;
            println!("{}", ans);
            break;
        }
        rtnc -= 1
    }
}





//**********************************************************************************************************************************************//

// 標準入力から一行を読み取り、指定の型に変換する関数
pub 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()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


Measured memory_bytes: 4476
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int questionAllNo = sc.nextInt();
		int[] solveMin = new int[questionAllNo];
		for(int i = 0; i < questionAllNo; i++) {
			solveMin[i] = sc.nextInt();
		}
		int drinkNo = sc.nextInt();
		for (int i = 0; i < drinkNo; i++) {
			int ans = 0;
			int questionNo = sc.nextInt();
			int solveMinDrink = sc.nextInt();
			for (int j = 0; j < questionAllNo; j++) {
				if (j == questionNo-1) {
					ans+= solveMinDrink;
				} else {
					ans+= solveMin[j];
				}
			}
			System.out.println(ans);
		}
		sc.close();
	}
}

Measured memory_bytes: 22868
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int N,M;
void nextnum(int *num,int j){
	if(num[j]<M){
		num[j]++;
		return;
	}
	else{
		nextnum(num,j-1);
		num[j]=num[j-1];
		return;
	}
}
int main(){
	int Q,a[51],b[51],c[51],d[51];
	scan(N>>M>>Q);
	rep(i,Q){
		scan(a[i]>>b[i]>>c[i]>>d[i]);
		a[i]--; b[i]--;
	}
	int num[10];
	rep(i,N) num[i]=1;
	ll ans=0;
	while(1){
		ll sum=0;
		rep(i,Q){
			if(num[b[i]]-num[a[i]]==c[i]) sum+=d[i];
		}
		ans=max(ans,sum);
		int en=1;
		rep(i,N){
			if(num[i]!=M){
				en=0;
				break;
			}
		}
		if(en) break;
		nextnum(num,N-1);
		//rep(i,N) printf("%d ",num[i]);
		//kaigyo;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N == 1){
            System.out.println("Hello World");
        } else{
            int A = sc.nextInt();
            int B = sc.nextInt();
            System.out.println(A+B);
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt", "r", stdin);
    int n, x, y;
    cin>>n>>x>>y;
    int bq=0, nu;
    for(int i=0; i<n; i++) if((x&(1<<i))!=(y&(1<<i))) bq++, nu=i;
    if(bq&1)
    {
        int an[1<<n];
        for(int a=0; a<(1<<n); a++)
        {
            if((x&(1<<nu)) and a<(1<<(n-1))) an[a]=(1<<nu);
            else if((y&(1<<nu)) and a>=(1<<(n-1))) an[a]=(1<<nu);
            else an[a]=0;
        }

        vector <pair <int, bool> > sp;
        int l=(1<<(n-1));
        sp.push_back({l, 0});
        sp.push_back({l, 0});
        for(int i=0; i<n; i++)
        {
            if(i!=nu)
            {
                vector <pair <int, bool> > sp2;
                int cu=((x&(1<<i))>0), fo=0, lg=0;
                if((x&(1<<i))!=(y&(1<<i))) fo=1;
                for(int a=0; a<sp.size(); a++) if(sp[a].first==l) fo^=1;
                for(int a=0; a<sp.size(); a++)
                {
                    if(sp[a].first!=l)
                    {
                        for(int b=lg; b<lg+sp[a].first; b++) an[b]+=(cu<<i);
                        lg+=l/2, sp2.push_back(sp[a]);
                    }
                    else
                    {
                        if(fo and sp[a].second==0)
                        {
                            for(int b=lg; b<lg+l/4; b++) an[b]+=(cu<<i);
                            lg+=l/4, cu^=1, sp2.push_back({l/4, 0});
                            for(int b=lg; b<lg+l/2; b++) an[b]+=(cu<<i);
                            lg+=l/2, cu^=1, sp2.push_back({l/2, 1});
                            for(int b=lg; b<lg+l/4; b++) an[b]+=(cu<<i);
                            lg+=l/4, sp2.push_back({l/4, 0});
                            fo=0;
                        }
                        else
                        {
                            for(int b=lg; b<lg+l/2; b++) an[b]+=(cu<<i);
                            lg+=l/2, cu^=1, sp2.push_back({l/2, 0});
                            for(int b=lg; b<lg+l/2; b++) an[b]+=(cu<<i);
                            lg+=l/2, sp2.push_back({l/2, 0});
                        }
                    }
                }
                l>>=1;
                sp.clear();
                for(int a=0; a<sp2.size(); a++) sp.push_back(sp2[a]);
            }
        }
        cout<<"YES\n";
        for(int a=0; a<(1<<n); a++) printf("%d ", an[a]);
    }
    else cout<<"NO";
}


Measured memory_bytes: 3880
#include<bits/stdc++.h>
#define N 2000009
#define ll long long
#define ld long double
#define ff first
#define ss second
#define inf 1000000005
#define mod 1000000007
using namespace std;
vector<int> g[100009];
int n;
pair<ll, ll> dfs(int v, int p = -1) {
    ll white = 1, black = 1;
    for(int i=0;i<g[v].size();i++) {
        int to = g[v][i];
        if(to == p)
            continue;
        pair<ll, ll> child = dfs(to, v);
        white *= (child.first + child.second);
        black *= child.first;
        white %= mod;
        black %= mod;
    }
    return make_pair(white, black);
}
int main() {
    cin>>n;
    for(int i=1;i<n;i++) {
        int x, y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    pair<ll, ll> ans = dfs(1);
    cout<<(ans.first + ans.second) % mod;
}


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

using namespace std;

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	map <ll, ll> was;
	ll ans(0);
	cin >> n;
	was[0] = 1;
	for (ll a, cur(0); n; --n)
	{
		cin >> a;
		cur += a;
		ans += was[cur];
		++was[cur];
	}
	cout << ans;
}


Measured memory_bytes: 12800
s=input();a=101
for i in range(97,123):
  b,t,c=0,s,chr(i)
  while len(set(t))>1:
    r=""
    for i in range(len(t)-1):
      r+=[t[i],c][c in t[i:i+2]]
    t=r
    b+=1
  a=min(a,b)
print(a)

Measured memory_bytes: 9028
#include <iostream>

using namespace std;

int main() {
    long long n,m, x, c[15], a[15][15], s=0, sf=1e9;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int k=1;k<(1<<n);k++)///iau toate submultimile posibile {0,0,0} --> {1,1,1} unde marchez cu 1 daca iau cartea
    {
        s=0;
        long long v[15]={};
        int ok=1; ///pp ca toti alg sunt la niv indicat
        for(int i=0;i<n;i++) ///preiau cartea de pe poz i
        {
            if((k&(1<<i))!=0){///testez daca face parte din combinatia k
                s+=c[i];///adaug costul cartii la costul final
                for(int j=0;j<m;j++)
                {
                    v[j]+=a[i][j];///cat am acumulat din alg j
                }
            }
        }
        for(int i=0;i<m;i++)
        {
            if(v[i]<x)
            {
                ok=0;
            }
        }
        if(ok==1)
        {
            if(sf>s)
            {
                sf=s;
            }
        }
    }
    if(sf==1e9)
    {
        cout<<-1;
    }
    else{
        cout<<sf;
    }

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18;
const int MAX_N=5010;

int N;
int A[MAX_N],sub[MAX_N];
vector<int> G[MAX_N];
ll dp[MAX_N][MAX_N][2];

void dfs(int v,int p){
    sub[v]=1;
    dp[v][0][A[v]<0]=A[v];
    for (int u:G[v]){
        if (u==p) continue;
        dfs(u,v);
        vector<vector<ll>> mrg(sub[v]+sub[u],vector<ll>(2,INF));
        for (int i=0;i<sub[v];++i){
            for (int j=0;j<sub[u];++j){
                for (int k=0;k<2;++k){
                    for (int l=0;l<2;++l){
                        mrg[i+j][k|l]=min(mrg[i+j][k|l],dp[v][i][k]+dp[u][j][l]);
                        if (dp[u][j][l]<0||(!l&&dp[u][j][l]!=INF)){
                            mrg[i+j+1][k]=min(mrg[i+j+1][k],dp[v][i][k]);
                        }
                    }
                }
            }
        }
        sub[v]+=sub[u];
        for (int i=0;i<sub[v];++i){
            for (int j=0;j<2;++j){
                dp[v][i][j]=mrg[i][j];
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for (int i=0;i<N;++i) cin >> A[i];
    for (int i=0;i<N-1;++i){
        int U,V; cin >> U >> V; --U,--V;
        G[U].emplace_back(V);
        G[V].emplace_back(U);
    }
    for (int i=0;i<N;++i){
        for (int j=0;j<N;++j){
            for (int k=0;k<2;++k){
                dp[i][j][k]=INF;
            }
        }
    }
    dfs(0,-1);
    int ans=N;
    for (int i=0;i<N;++i){
        for (int j=0;j<2;++j){
            if (dp[0][i][j]<0||(!j&&dp[0][i][j]!=INF)){
                ans=min(ans,i);
            }
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 393072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;vector<ll>a;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		x--;
		a.push_back(x);
	}
	vector<ll>b;
	while(a.size()!=0){
		bool ch=false;
		for(int i=a.size()-1;i>=0;i--){
			ll now=a[i];
			if(now==i){
				ch=true;
				a.erase(a.begin()+i);
				b.push_back(now);
				break;
			}
		}
		if(ch==false){
			cout << -1;
			return 0;
		}
	}
	reverse(b.begin(),b.end());
	for(int i=0;i<n;i++){
		cout <<b[i]+1<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

vector<vector<int> >v(2);
int n;
int bfs(int x, int y, int count){
	if (y==1){
		return count += accumulate(v[1].begin()+x, v[1].end(), 0);
	}else{
		int a=0,b=0;
		if (x+1<n){
			a = bfs(x+1,y,count+v[y][x]);
		}
		b = bfs(x,y+1,count+v[y][x]);
		return max(a,b);
	}
}

int main(){
	cin>>n;
	rep(i,2)rep(j,n){
		int a; cin >> a;
		v[i].push_back(a);
	}
	cout << bfs(0,0,0) << endl;

}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;
const int NIL = -1;

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

vector<Node> T(100010, {NIL, NIL, NIL});
vector<int> D(100010);

void setDepth(int u, int p){
    D[u] = p;
    if(T[u].l != NIL) setDepth(T[u].l, p + 1);
    if(T[u].r != NIL) setDepth(T[u].r, p);
}

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if(T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for(int c = T[u].l, j = 0; c != NIL; c = T[c].r, j++){
        if(j) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int main(){
    int N;
    cin >> N;
    rep(i, N){
        int id, k;
        cin >> id >> k;
        int c1, c2;
        rep(j, k){
            cin >> c1;
            if(j == 0){
                T[id].l = c1;
                T[c1].p = id;
                c2 = c1;
            } else {
                T[c2].r = c1;
                T[c1].p = id;
                c2 = c1;
            }
        }
    }

    int root;
    rep(i, N){
        if(T[i].p == NIL){
            root = i;
            break;
        }
    }
    
    setDepth(root, 0);

    rep(i, N) print(i);
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

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

  int N;
  cin >> N;

  cout << (N + 1) * N / 2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

const int INF = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    repeat(i, N) cin >> A[i];
    deque<int> deq;
    for (int i = N - 1; i >= 0; --i) {
        int p = upper_bound(deq.begin(), deq.end(), A[i]) - deq.begin();
        if (p == deq.size()) {
            deq.push_back(A[i]);
        } else {
            deq[p] = A[i];
        }

        // for (int p : deq) {
        //     cout << p << " ";
        // }
        // cout << endl;
    }
    int ans = deq.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			int h = scan.nextInt();
			int w = scan.nextInt();
			
			if(h == 0) break;
			
			for(int i = 0; i < h; i++) {
				for(int j = 0; j < w; j++) {
					if(i == 0 || i == h - 1 || j == 0 || j == w - 1) {
						System.out.print('#');
					}else {
						System.out.print('.');
					}
				}
				System.out.println();
			}
		
			System.out.println();
		}
		
	}

}



Measured memory_bytes: 34432
def mapt(fn, *args):
    return tuple(map(fn, *args))

def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    a = Input()
    b = Input()
    c = Input()
    ans = 0
    for i in range(n-1):
        if a[i+1] - a[i] == 1:
            ans += c[a[i]-1]
    ans += sum(b)
    print(ans)
main()

Measured memory_bytes: 9132
/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
const ll inf=(1LL<<60)-1;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
   ll n,k;
   cin>>n>>k;
   string s;
   char t='A';
  cin>>s;
    s[k-1]=s[k-1]+32;
    cout<<s<<endl;
}
int main()
{
    IOS;
    //ll t;
     //cin>>t;
     //while(t--)
    solve();
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<ll> H(N);
  REP(i, N) { cin >> H.at(i); }

  vector<vector<int>> path(N);
  int a, b;
  REP(i, M) {
    cin >> a >> b;
    --a;
    --b;
    path.at(a).push_back(b);
    path.at(b).push_back(a);
  }

  int ans = 0;
  vector<bool> visit(N, false);
  REP(i, N) {
    if (path.at(i).size() == 0 || visit.at(i)) {
      continue;
    }

    visit.at(i) = true;
    ll h = H.at(i);
    bool highest = true;

    for (int const &d : path.at(i)) {
      if (H.at(d) >= h) {
        highest = false;
        break;
      }
    }
    if (highest) {
      for (int const &d : path.at(i)) {
        visit.at(d) = true;
      }
      ++ans;
    }
  }

  REP(i, N) {
    if (!visit.at(i)) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		String ab = "";
		String ba = "";
		
		for(int i = 0; i < b; i++) {
			ab += a;
		}
		
		for(int i = 0; i < a; i++) {
			ba += b;
		}
		
		if(ab.compareTo(ba) < 0) {
			System.out.println(ab);
		}
		else {
			System.out.println(ba);
		}
	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i=0;i<N;i++) {
        cin >> A[i];
        A[i]--;
    }
    vector<ll> loop(N+1);
    loop[0] = 0;
    for (int i=0;i<N;i++){
        loop[i+1] = A[loop[i]];
    }
    if (N>=K) {
        cout << loop[K] + 1 << "\n";
        return 0;
    }
    vector<ll> stop(N,-1);
    stop[0] = 0;
    ll start,end;
    for (int i=0;i<=N;i++){
        if (stop[loop[i]] == -1) {
            stop[loop[i]] = i+1;
        } else {
            start = stop[loop[i]];
            end = i+1;
        }
    }
    K -= start;
    ll res = K % (end - start);
    ll ans = loop[start+res]+1;
    cout << ans << "\n";
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int t;
  cin >> t;
  while(t--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a < b) cout << "No" << endl;
    else if(d < b) cout << "No" << endl;
    else if(b < c) cout << "Yes" << endl;
    else {
      int GCD = __gcd(b, d);
      if(c < b-GCD+a%GCD) cout << "No" << endl;
      else cout << "Yes" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int x= a*2;
    int y = a*4;
    if(b>=x && b<=y && b%2==0){
        cout<<"Yes\n";
    }else {
        cout<<"No\n";
    }

}


Measured memory_bytes: 3644