akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int DerivCount(int n,int x,int count){ //いくつに分けるか不定の場合
    if(x == 0){
        return count+1;
    }else if(1 <= n && 1 <= x){
        for(int i = 0;i<n;i++){
            count = DerivCount(i,x-(i+1),count);
        }
    }
    return count;
}



int main(){

    int n,m;

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

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

    for(int j=0;j<n+1;j++){
        for(int i=0;i<m+1;i++){
            printf("%d",Ans[j][i]);
            if(i != m){
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2700
#include <iostream>
#include <string.h>
using namespace std;
int arr[27];
int G[27];
char str[55];

void pro()  {
    scanf("%s",str);
    int l=strlen(str);
    for(int i=0;i<26;i++)   G[i]=0;
    for(int i=0;i<l;i++)    G[str[i]-'a']++;
}

int main() {
    int n;scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        pro();
        for (int j=0; j<26; j++) {
            if(i==1)    arr[j]=G[j];
            else    arr[j]=min(arr[j],G[j]);
        }
    }
    for (int i=0; i<26; i++) {
        for (int j=0; j<arr[i]; j++) {
            printf("%c",'a'+i);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

void solve(){
  int n;
  cin >> n;
  int x[n];
  int y[n];
  for (int i = 0 ; i < n; ++i) cin >> x[i] >> y[i];

  set<int> add_max;
  set<int> sub_max;
  add_max.insert(x[0] + y[0]);
  sub_max.insert(x[0] - y[0]);

  int ans = 0;
  for (int i = 1; i < n; ++i) {
    int cur_x = x[i];
    int cur_y = y[i];
    int add = cur_x + cur_y;
    int sub = cur_x - cur_y;
    auto it = add_max.begin();
    auto it2 = add_max.end();
    it2--;
    ans = max(ans,max(abs(add - *it),abs(add - *it2)));
    it = sub_max.begin();
    it2 = sub_max.end();
    it2--;
    ans = max(ans,max(abs(sub - *it),abs(sub-*it2)));
    add_max.insert(add);
    sub_max.insert(sub);
  }
  cout << ans << "\n";

}


signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}





Measured memory_bytes: 25472
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        k: usize,
    }
    let mut a = 0;
    let mut v = vec![false; k];
    let mut ans = 0;
    loop {
        a = (a * 10 + 7) % k;
        ans += 1;
        if a == 0 {
            println!("{}", ans);
            break;
        } else if v[a] {
            println!("{}", -1);
            break;
        }
        v[a] = true;
    }
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >>a>>b>>c;
  if(c >= a-b)cout << c-a+b << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  string S;
  cin >> S;
  if(S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)){
    cout << "Bad";
  } else {
    cout << "Good";
  }
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

template <typename T, class Operator>
struct SegTree
{
	vector<T> tree;
	Operator op;
	T def;
	int s;
	void init(int size, T val, Operator opr)
	{
		s=size;
		op=opr;
		tree.clear();
		tree.resize(4*size,val);
		def=val;
	}

	void add(int pos, T value)
	{
		add(pos,value,0,s,0);
	}

	// [low, hi) は全体の範囲
	void add(int pos, T value, int low, int hi, int i)
	{
		while(1)
		{
			tree[i]=op(tree[i],value);
			if(low+1<hi){
				int mid=(low+hi)/2;
				if(pos<mid){
					i=2*i+1;
					hi=mid;
				}
				else
				{
					i=2*i+2;
					low=mid;
				}
			}
			else
			{
				break;
			}
		}
	}

	// [a,b) を取得
	T get(int a, int b)
	{
		return get(a,b,0,s,0);
	}

	T get(int a, int b, int low, int hi, int i)
	{
		if(hi<=a||b<=low||hi<=low){
			return def;
		}
		if(a<=low&&hi<=b){
			return tree[i];
		}
		int mid=(low+hi)/2;
		return op(get(a,b,low,mid,2*i+1),get(a,b,mid,hi,2*i+2));
	}

	// 補助関数
	bool check(int a, int b, int low, int hi, int i, int v)
	{
		if(hi<=a||b<=low||hi<=low){
			return true;
		}
		if(a<=low&&hi<=b){
			return tree[i]%v==0;
		}
		int mid=(low+hi)/2;
		return check(a,b,low,mid,2*i+1,v)&&check(a,b,mid,hi,2*i+2,v);
	}
};

template<class T>
struct Max
{
	T operator()(T a, T b){
		return max(a,b);
	}
};
const int L=5002;
LL A[L];
int B[L][200];
LL table[L][L];
SegTree<P,Max<P> > tree;

void search(int s,int e){
	if(s>=e)return;
	P p=tree.get(s,e);
	table[s][p.second]+=p.first;
	table[s][e]-=p.first;
	table[p.second+1][p.second]-=p.first;
	table[p.second+1][e]+=p.first;
	search(s,p.second);
	search(p.second+1,e);
}
int main() {
	int N,M;
	cin >> N >> M;
	for(int i=2;i<=N;i++){
		cin >> A[i];
		A[i]+=A[i-1];
	}
	for(int i=1;i<=N;i++){
		for(int j=0;j<M;j++){
			cin >> B[i][j]; 
			//cerr << i << ", " << j << ": " << B[i][j] << endl;
		}
	}
	for(int j=0;j<M;j++){
		tree.init(N+1,P(0,-1),Max<P>());
		for(int i=1;i<=N;i++){
			tree.add(i,P(B[i][j],i));
		}
		search(1,N+1);
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			table[i][j]+=table[i][j-1];
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			table[i][j]+=table[i-1][j];
		}
	}
	LL ret=0;
	for(int i=1;i<=N;i++){
		for(int j=i;j<=N;j++){
			//cerr << table[i][j] -A[j]+A[i] << ", ";
			ret=max(ret,table[i][j]-A[j]+A[i]);
		}
		//cerr << endl;
	}
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 199808
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n,c;
    cin>>n>>c;
    vector<vector<int>> d(c,vector<int>(c));
    rep(i,0,c) rep(j,0,c) cin>>d[i][j];
    
    vector<vector<int>> color(3);
    rep(i,0,n) rep(j,0,n) {
        int x;
        cin>>x;
        x--;
        color[(i+j)%3].push_back(x);
    }
    
    vector<vector<int>> total_cost(3,vector<int>(c));
    rep(i,0,3){
        rep(j,0,c){
            int cnt=0;
            for(int x:color[i]) cnt+=d[x][j];
            total_cost[i][j]=cnt;
        }
    }
    
    int ans=INF;
    rep(i,0,c){
        rep(j,0,c){
            rep(k,0,c){
                if(i==j||j==k||k==i) continue;
                int tmp=total_cost[0][i]+total_cost[1][j]+total_cost[2][k];
                ans=min(ans,tmp);
            }
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1524
XN = input().split()

X = int(XN[0])
N = int(XN[1])

ps = input().split()
p = []

for i in range(N):
    p.append(int(ps[i]))

ans = X
ansisfound = False

if X not in p:
    ansisfound = False

for i in range(len(p)+1):
    if ansisfound:
        break
    if X + i not in p:
        ans = X + i
        ansisfound = True
    if X - i not in p:
        ans = X - i
        ansisfound = True

print(ans)

Measured memory_bytes: 61804
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

int main(){
    int A,B;cin>>A>>B;
    cout<<A*B<<endl;

    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX_H = 1000;
static const int MAX_W = 1000;
static const int MAX_N = 10;
static const int INF = 1 << 30;
typedef pair<int, int> P;

int H, W, N;
char s[MAX_H][MAX_W + 1];
P p[MAX_N];
int dist[MAX_H][MAX_W];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int bfs(int n, int m){
	queue<P> qa;
	fill(dist[0], dist[H], INF);
	qa.push(p[n]);
	dist[p[n].first][p[n].second] = 0;
	while(!qa.empty()){
		P t = qa.front(); qa.pop();
		if(t == p[m]) break;
		for(int i = 0; i < 4; i++){
			int nx = t.first + dx[i];
			int ny = t.second + dy[i];
			if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			if(s[nx][ny] == 'X') continue;
			if(dist[nx][ny] == INF){
				qa.push(make_pair(nx, ny));
				dist[nx][ny] = dist[t.first][t.second] + 1;
			}
		}
	}
	return dist[p[m].first][p[m].second];
}

int main(){
	cin >> H >> W >> N;
	for(int i = 0; i < H; i++){
		cin >> s[i];
		for(int j = 0; j < W; j++){
			if(s[i][j] == 'S'){
				p[0] = make_pair(i, j);
			}else if(s[i][j] >= '1' && s[i][j] <= '9'){
				p[s[i][j] - '0'] = make_pair(i, j);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < N; i++){
		ans += bfs(i, i + 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>

using namespace std;

vector<int> p;
vector<string> dict;


int main()	{
  string input;
  cin >> input;
  int n = input.length();
  long long ans = 0;
  for (int i = 0; i < (1 << (n - 1)); i++)	{
    long long a = 0;
    for (int j = 0; j < n - 1; j++)	{
      	a += input[j] - '0';
    	if (i & (1<<j))	{
          ans += a;
          a = 0;
        }
      	a *= 10;
    }
    ans += a + input[n - 1] - '0';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    scanf("%d",&x);
    int arr[x+1];
    for(int i=0;i<x;i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+x);
    for(int i=0;i<x;i++)
    {
        if(i==x-1)
            printf("%d\n",arr[i]);
        else
            printf("%d ",arr[i]);
    }
    return 0;
}


Measured memory_bytes: 11020
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000
#define f(i,a,b) for(long long i=a;i<b;i++)
#define tc long long t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define up upper_bound
#define lo lower_bound
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long
#define umap unordered_map

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    if(c>b and b>a) cout<<"Yes";
    else{
        while(k>0 and a>=b){
            b*=2;
            k--;
        }
        while(k>0 and b>=c){
            c*=2;
            k--;
        }
        if(c>b and b>a) cout<<"Yes";
        else cout<<"No";

    }
}

Measured memory_bytes: 3592
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader sc = new FastReader();
        long n = sc.nextLong();
        StringBuilder ans = new StringBuilder();
        while (n > 0){
            int j = (int)((n-1)%26);
            n = (n-1)/26;
            ans.append((char) (j+97));
        }
        System.out.println(ans.reverse().toString());
    }
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}


Measured memory_bytes: 32728
void main() {
  problem();
}

void problem() {
  const MAX = 10L.pow(18);
  auto N = scan!int;
  auto A = scan!ulong(N);

  long solve() {
    ulong multi = 1;
    real floatMulti = 1;
    foreach(a; A) {
      floatMulti *= cast(real)a;
      multi *= a;
    }

    return floatMulti > MAX ? -1 : multi;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 8428
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
const int p=998244353;
int read() {
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch)) {
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x) {
	if(x>9)print(x/10);
	putchar(x%10+48);
}
ll ans=2018;
int main() {
   ll l=rd,r=rd;
   for(ll i=l;i<=r;i++)
   {
   	for(ll j=i+1;j<=r;j++)
   {
   		ans=min(ans,i*j%2019);
   		if(ans==0)
   		{
   			puts("0");return 0;
		   }
	   }
	} 
	print(ans),pu;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, a, b;
    cin >> n >> a >> b;

    int ma = min(a, b);
    int mi = (a+b) - n;
    if (mi < 0) {
        mi = 0;
    }

    cout << ma << ' ' << mi << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c;
  while(scanf("%d %d",&a,&b)!=EOF){
  	c = a + b;
  	if(c<10) printf("1\n");
  	else if(c<100) printf("2\n");
  	else if(c<1000) printf("3\n");
  	else if(c<10000) printf("4\n");
  	else if(c<100000) printf("5\n");
  	else if(c<1000000) printf("6\n");
  	else if(c<10000000) printf("7\n");
  }
  return 0;
}

Measured memory_bytes: 2616
#include<iostream>
#include<vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main(){
    int n; 
    cin >> n;
    vector<int>frog(n);
    rep(i,n) cin >> frog[i];
    vector<int>dp(n);
    dp[0] = 0;
    dp[1] = abs(frog[1] - frog[0]);
	for(int i = 2; i < n; i++) dp[i] = min(dp[i-1] + abs(frog[i] - frog[i-1]),dp[i-2] + abs(frog[i] - frog[i-2]));
	cout << dp[n-1] <<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{

    string s, t;
    
    cin >> s >> t;
    
    for(int i = 0; i < s.length(); i++)
    {
        if(i < s.size() && s[i] != t[i])
        {
            cout << "No";
            break;
        }
        if(i == s.size() - 1)
        {
            cout << "Yes";
            break;
        }
    }
    
    
    
}

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

int main(){

  long N,K;
  cin >> N >> K;
  long ans=0;
  for(int j=K+1; j<=N; j++){
      ans += (N/j)*(j-K)+max((long)0,(N-j*(N/j))-K+1);
  }
  if(K==0) ans = N*N;
  cout << ans << endl;

  return 0;
}


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

#define MAX 10000

int *A, *B, C[MAX + 1];

void CountingSort(int n)
{
	
	for (int i = 0; i <= MAX; i++) C[i] = 0;

	for (int j = 0; j < n; j++) C[A[j]]++;

	for (int i = 1; i <= MAX; i++)
		C[i] += C[i - 1];

	for (int j = n - 1; j >= 0; j--) {
		B[C[A[j]] - 1] = A[j];
		C[A[j]]--;
	}
}

int main()
{
	int n;
	scanf("%d", &n);

	A = new int[n];
	B = new int[n];

	for (int i = 0; i < n; i++) 
		scanf("%d", &A[i]);

	CountingSort(n);

	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");

	delete[] A;
	delete[] B;
	return 0;
}

Measured memory_bytes: 16504
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var S = ReadLine();
		var ans = 0;

		for (var i = 1; i < S.Length / 2; i++) {
			if (S.Substring(0, i) == S.Substring(i, i)) {
				ans = i * 2;
			}
		}
		WriteLine(ans);
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}


Measured memory_bytes: 11092
import java.awt.Point;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (true) {
			int W = sc.nextInt();
			if (W == 0) break;
			int H = sc.nextInt();
			boolean[][] f = new boolean[H + 2][W + 2];
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					f[i + 1][j + 1] = sc.nextInt() == 1;
				}
			}
			int ans = 0;
			for (int i = 1; i <= H; ++i) {
				for (int j = 1; j <= W; ++j) {
					if (f[i][j]) {
						fill(f, i, j);
						++ans;
					}
				}
			}
			System.out.println(ans);
		}
	}

	static void fill(boolean[][] f, int r, int c) {
		ArrayList<Point> ps = new ArrayList<Point>();
		ps.add(new Point(r, c));
		f[r][c] = false;
		while (!ps.isEmpty()) {
			ArrayList<Point> next = new ArrayList<Point>();
			for (Point p : ps) {
				for (int i = -1; i <= 1; ++i) {
					for (int j = -1; j <= 1; ++j) {
						int nr = p.x + i;
						int nc = p.y + j;
						if (f[nr][nc]) {
							f[nr][nc] = false;
							next.add(new Point(nr, nc));
						}
					}
				}
			}
			ps = next;
		}
	}

}

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

typedef long long ll;
const ll INF = 1e18;

int main(int argc, char* argv[])
{
  int N, M, X, Y;
  std::cin >> N >> M;

  std::vector< ll > vx(N+1, 0);
  std::vector< ll > vy(M+1, 0);

  std::cin >> vx[N] >> vy[M];

  for (ll i = 0; i < N; i++) {
    std::cin >> vx[i];
  }
  for (ll i = 0; i < M; i++) {
    std::cin >> vy[i];
  }  

  ll x_max = *std::max_element(vx.begin(), vx.end());
  ll y_min = *std::min_element(vy.begin(), vy.end());  

  std::string judge = "War";
  if (x_max < y_min) {
    judge = "No War";
  }

  std::cout << judge << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
  string line;
  map<char, int> m;
  const char tmp = 'a';
  for(int i=0; i<26; i++) {
    m[tmp+i] = 0;
  }
  
  
  while(cin >> line) {
    for(unsigned int i = 0; i<line.length(); i++) {
      if('a' <= line[i] && line[i] <= 'z') {
        m[line[i]] += 1;
      }
      else if('A' <= line[i] && line[i] <= 'Z') {
        m[line[i]+32] += 1;
      }
    }
  }
  for(int i=0; i<26; i++) {
    cout << (char)(tmp+i) << " : " << m[tmp+i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    v.erase(unique(v.begin(), v.end()), v.end());
    vecout(v);
}



Measured memory_bytes: 3608
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const long long MOD = 1e9 + 7;

int main() {
    long long a, b, x;
    cin >> a >> b >> x;
    long long ans = x + (max(x - b, 0ll) / (a - b)) % MOD * (b % MOD);
    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking 
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1ll<<60)
using namespace std;

ll gcd(ll x,ll y){
	return y?gcd(y,x%y):x;
}
int main(){
	int T; scanf("%d",&T);
	while (T--){
		ll a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if (a<b||b>d){
			puts("No"); continue;
		}
		ll G=gcd(b,d); a%=G;
		ll mn=c; mn=mn/G*G+a;
		for (;mn<=c;mn+=G);
		if (mn<b) puts("No");
		else puts("Yes");
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;

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


int main()
{
	int x , y;
	cin >> x >> y;
	if ( x < y ){
		int temp = x;
		x = y;
		y = temp;
	}
	cout << GCD(x,y) <<endl;
	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
//***********//
int main() {
	cin >> N >> M;
	vl C(N);
	for (i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;
		C[a - 1]++; C[b - 1]++;
	}
	for (i = 0; i < N; i++) {
		if (C[i] % 2 == 1) {
			cout << "NO";
			exit(0);
		}
	}
	cout << "YES";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = [int(input()) for _ in range(n)]
L = [0] * n
cnt = 0
i = 0
while True:
    if L[i] == 1:
        print(-1)
        break
    else:
        L[i] = 1
        i = a[i] - 1
        cnt += 1
        if i == 1:
            print(cnt)
            break


Measured memory_bytes: 7852
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var inputs = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            var n = inputs[0];
            var p = inputs[1];
            var time=0;
            var queue = new Queue<Process>(n);
            while (queue.IsFull() == false)
            {
                var temp=Console.ReadLine().Split();
                var process = new Process(temp[0],int.Parse(temp[1]));
                queue.Enqueue(process);
            }

            while (queue.IsEmpty() == false)
            {
                var process = queue.Dequeue();
                if (process.Time > p)
                {
                    time += p;
                    process.Time = process.Time - p;
                    queue.Enqueue(process);
                }
                else
                {
                    time += process.Time;
                    Console.WriteLine("{0} {1}", process.Name, time);
                }
            }

            Console.Read();
        }
    }
    class Process
    {
        public string Name { get; set; }
        public int Time { get; set; }
        public Process(string name, int time)
        {
            Name = name;
            Time = time;
        }
    }
    class Queue<T>
    {
        private T[] array;
        private int top = 0;
        private int back = 0;
        private bool isFull = false;

        public Queue(int capacity)
        {
            array = new T[capacity];
        }
        public void Enqueue(T item)
        {
            array[top++] = item;
            if (top == array.Length)
            {
                top = 0;
            }
            if (top == back)
            {
                isFull = true;
            }
        }
        public T Dequeue()
        {
            isFull = false;
            var temp = array[back++];
            if (back == array.Length) back = 0;
            return temp;
        }
        public bool IsEmpty()
        {
            if (isFull == true) return false;
            return top == back;
        }
        public bool IsFull()
        {
            return isFull;
        }
        
    }

}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<string> svec;

#define IN_LL(in) ll in; cin >> in;
#define IN_STR(in) string in; cin >> in;
#define IN_VEC(in, size) vec in; in.reserve(size); for(ll i = 0; i < (size); ++i) cin >> in[i];
#define IN_SVEC(in, size) svec in; in.reserve(size); for(ll i = 0; i < (size); ++i) cin >> in[i];

#define OUT(out) cout << (out);
#define OUT_VEC(out) for(ll i = 0; i < (out).size(); ++i) cout << (out)[i];

ll func(ll n, string s){
	ll res = 0;
	return res;
}

int main(void){
	int r;
	cin >> r;
	cout << r * 3.141592 * 2 << endl;
	return 0;
}


Measured memory_bytes: 3784
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll n;cin>>n;
    ll r=n<3?1:2;
    for(ll k=2;k*k<=n;k++)
    {
        ll t=n;
        while(t>=k) t % k ? t %=k : t /=k;
        if(t==1)r++;
        if((n-1)%k==0&&(n-1)/k!=k)r++;
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  string s;
  cin >> s;

  auto days = { "", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN" };

  auto it = find(days.begin(), days.end(), s);
  cout << it - days.begin() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>

using namespace std;

int n, m, t[300000];

int main(){
	
	vector<int> ans;
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++)cin >> t[i];
		for (int i = n; i < m+n; i++)cin >> t[i];
		sort(t, t + n + m);
		int Max = t[0];
		for (int i = 0; i < n + m - 1; i++)Max = max(Max, t[i + 1] - t[i]);
		ans.push_back(Max);
	}
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3164
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  double n, k, ans = 0;
  scanf("%lf%lf", &n, &k);
  for (int i = 1; i <= n; i++)
  {
    int cnt = 0, ii = i;
    while (ii < k)
    {
      ii *= 2;
      cnt++;
    }
    ans += (1 / n) * pow(0.5, cnt);
  }
  printf("%.15lf\n", ans);
  return 0;
}


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

using namespace std;

void solve() {
    string s;
    cin >> s;

    uint64_t sum = 0;

    for(auto &c:s) {
        sum += (c-48);
    }
    if(sum % 9 == 0) cout << "Yes\n";
    else cout << "No\n";
}

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

    solve();
    return 0;    
}

Measured memory_bytes: 3772
n,m=gets.split.map &:to_i
a=(1..n).map{}
b=[]
n.times{|i| a[i]=gets.split.map &:to_i}
m.times{|i| b.push(gets.to_i)}
n.times{|i|
s=0
m.times{|j| s+=a[i][j]*b[j]}
p s
}

Measured memory_bytes: 8884
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			int n= sc.nextInt();
			if(n==0)
				return;
			int count =0;
			while(n!=1)
			{
				if(n%2!=0)
					n=n*3+1;
				else
					n/=2;
				count++;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<=b;i++)
template <typename T>
void read(T &x){
    x=0;
    int flag=1;
    char c=getchar();
    while(c=='-'){
        flag=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    x*=flag;
}

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+1>=c)cout<<b+c;
    else cout<<a+b+1+b;
    return 0;
}


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

using namespace std;

int n,m;
int ans=INT_MAX;
vector<vector<pair<int,int> > >grp2;
vector<vector<vector<int> > >dp(80,vector<vector<int> >(80,vector<int>(2*80*80+5,-1)));
int cnt=0;
int slv(int x=0,int y=0,int dif=0){
    cnt++;
    if(x==n-1&&y==m-1){
        return min(abs(dif+grp2[x][y].first-grp2[x][y].second),abs(dif-grp2[x][y].first+grp2[x][y].second));
    }
    if(dp[x][y][dif]!=-1)
        return dp[x][y][dif];
    dp[x][y][dif]=INT_MAX;
    if(x<n-1){
        dp[x][y][dif]=min(dp[x][y][dif],abs(slv(x+1,y,abs(dif+grp2[x][y].first-grp2[x][y].second))));
        dp[x][y][dif]=min(dp[x][y][dif],abs(slv(x+1,y,abs(dif-grp2[x][y].first+grp2[x][y].second))));
    }
    if(y<m-1){
        dp[x][y][dif]=min(dp[x][y][dif],abs(slv(x,y+1,abs(dif+grp2[x][y].first-grp2[x][y].second))));
        dp[x][y][dif]=min(dp[x][y][dif],abs(slv(x,y+1,abs(dif-grp2[x][y].first+grp2[x][y].second))));
    }
    return dp[x][y][dif];
}

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

    cin>>n>>m;
    vector<vector<pair<int,int> > >grp(n,vector<pair<int,int> >(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>grp[i][j].first;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>grp[i][j].second;
        }
    }
    grp2=grp;
    cout<< slv()<<'\n';

    return 0;
}
/***
4 3 2 3
1 4 1 100
1 2 1 10
1 3 20 1
*/


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

int main() {
	string s;
	string t;
	int count{ 0 };
	cin >> s >> t;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i])
			count++;
	}

	cout << count;
}

Measured memory_bytes: 3448
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   string a,b,c;
   cin >> a >> b >> c;

   string res;
   res.push_back(a[0]);
   res.push_back(b[1]);
   res.push_back(c[2]);

   cout << res << endl;
   return 0;
}

Measured memory_bytes: 256
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
t = False
n = stdin.readline().rstrip()
count = 0
for el in range(int(n)):
    tmp = stdin.readline().rstrip().split()
    a = int(tmp[0])
    b = int(tmp[1])
    if a == b:
        count += 1
    else:
        count = 0
    if count >= 3:
        t = True
if t:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 72684
#include <iostream>
#include <vector>
#include <queue>

#define fi first
#define se second
#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	priority_queue<int> pq;
	FOR (i, 0, n) {
	  int foo;
	  cin >> foo;
	  pq.push(foo);
  }
  while (m > 0) {
    int foo = pq.top();
    pq.pop();
    foo >>= 1;
    pq.push(foo);
    m--;
  }
  i64 tot = 0;
  while (!pq.empty()) {
    tot += pq.top();
    pq.pop();
  }
  cout <<tot << '\n';
	return 0;
}

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

int main(){
	double L, a, b, c;
	cin >> L;
	
	a = L/3;
	b = L/3;
	L -= (a+b);
	c = L;
	
	cout << fixed << setprecision(10) << a*b*c << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    if(a<=9 && b <= 9) cout << a*b << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
  int a,b;
  int c = 0;
  double d = 0;
  cin >> a;
  for(int i = 0;i <= 50000;i++){
    d = i * 1.08;
    if((int)d == a){
      b = i;
      i = 50001;
      c = 1;
    }
  }
  if(c == 0){
    cout << ":(" << endl;
  }
  else{
    cout << b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

class tree;

class tree
{
    int id;
    int parentid = -1;
    int depth = 0;
    string status = "root";
    vector<int> children;

public:
    tree()
    {
        int n, v;
        cin >> id >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> v;
            children.push_back(v);
        }
    }

    void printtree()
    {
        printf("node %d: parent = %d, depth = %d, ", id, parentid, depth);
        cout << status << ", [";
        for (auto itr = children.begin(); itr != children.end(); itr++)
        {
            if (itr == children.begin())
                cout << *itr;
            else
                cout << ", " << *itr;
        }
        cout << "]\n";
    }

    int getid()
    {
        return id;
    }

    int setdepth(tree a[])
    {
        if (parentid == -1){
            depth = 0;
            return depth;
    }
        else{

            depth = a[parentid].setdepth(a) + 1;
          return depth;
        }
    }

    void setparent(int p)
    {
        parentid = p;
    }

    void getchildren(tree a[])
    {
        int next, vs;
        vs = children.size();
        for (auto itr = children.begin(); itr != children.end(); itr++)
        {
            next = *itr;
            a[next].setparent(id);
        }
    }

    void treesearch()
    {

        if (parentid != -1)
        {
            if (children.size() == 0)
                status = "leaf";
            else
                status = "internal node";
        }
    }
};

void babblesort(int n, tree a[])
{
    int flag = 1;
    while (flag)
    {
        flag = 0;
        for (int j = n - 1; j > 0; j--)
        {
            if (a[j].getid() < a[j - 1].getid())
            {
                swap(a[j], a[j - 1]);
                flag = 1;
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    tree nodes[n];
    babblesort(n, nodes);
    for (int i = 0; i < n; i++)
    {
        nodes[i].getchildren(nodes);
    }
    
    for (int i = 0; i < n; i++)
    {
        nodes[i].treesearch();
    }


       for (int i = 0; i < n; i++)
    {
         nodes[i].setdepth(nodes);
        nodes[i].printtree();
    }
    return 0;
}



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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(auto& i : p) cin >> i;
    for(auto& i : q) cin >> i;

    vector<int> v(n);
    REP(i, n) v[i] = i + 1;

    int a = 0, b = 0, c = 0;

    do{
        bool samep = true, sameq = true;
        REP(i, n){
            samep &= (p[i] == v[i]);
            sameq &= (q[i] == v[i]);
        }
        if(samep) a = c;
        if(sameq) b = c;
        c++;
    }while(next_permutation(all(v)));

    cout << abs(a - b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

constexpr ll jo5(ll n) { return n * n * n * n * n; }

int main() {
  ll X;
  cin >> X;

  for (ll a = -200; a < 200; a++) {
    const ll jo5a = jo5(a);
    for (ll b = -200; b < 200; b++) {
      const ll jo5b = jo5(b);
      if (jo5a - jo5b == X) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  cout << X << endl;
  return 0;
}


Measured memory_bytes: 3544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
 
 
public class Main {
 
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
 
        try {
            while ((line = br.readLine()) != null) {
                line.trim();
                 
                String[] words = line.split("\\s");
                ArrayList<Integer> num = new ArrayList<Integer>();
                for(String s : words) num.add(Integer.parseInt(s));
                 
                Collections.sort(num);
                Collections.reverse(num);
 
                String str = num.toString();
                str = str.replaceAll("[\\[\\],]", "");
                System.out.println(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}

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

using namespace std;

int main()
{
    int a, b;
    int x;

    cin >> x >> a >> b;

    if (abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[10000005];
int main() {
	int n,m,k;
	scanf("%d",&n);
	for(int i=2;i<=n;i++) {
		for(int j=i*2;j<=n;j+=i) 
		s[j]++;
	}
	long long tot = 0;
	for(int i=2;i<=n;i++) {
		tot+=1LL*(s[i]+2)*i;
	}
	printf("%lld\n",tot+1);
}


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

int main() {
  string S;
  cin >> S;
  bool a = 0;
  int cnt,N = S.size();
  for(int i=0; i<N-1; i++){
    if(i == N-2 && S.at(i) == S.at(i+1) && a == 0){
        break;
    }
    else if(i == N-2 && (S.at(i) != S.at(i+1) || a == 1)){
      cnt++;
      break;
    }
    else if(S.at(i) == S.at(i+1) && a == 0){
      i++;
      a = 1;
      cnt++;
    }
    else if(a == 0){
      cnt++;
    }
    else if(a == 1){
      a = 0;
      cnt++;
    }
  }
  cout << cnt+1;
}

Measured memory_bytes: 640
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

vector<pii> parent_dist(100001, make_pair(0, 0));

pii find_root(LL idx) {
	if (parent_dist[idx].first == 0) {
		return make_pair(idx,0);
	}
	else {
		pii to_parent = parent_dist[idx];
		pii to_root = find_root(to_parent.first);
		parent_dist[idx] =make_pair(to_root.first,to_root.second+to_parent.second);
		return parent_dist[idx];
	}
}

int main() {
	LL N, M;
	cin >> N >> M;

	bool flag = true;

	REP(hogehoge, M) {
		LL L, R, D;
		cin >> L >> R >> D;

		pii L_root = find_root(L);
		pii R_root = find_root(R);

		if (L_root.first == R_root.first) {
			if (R_root.second - L_root.second == D) {
				//yattaze.
			}
			else {
				flag = false;
			}
		}
		else {
			parent_dist[R_root.first] = make_pair(L_root.first, D+(L_root.second-R_root.second));
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1792