akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int B[9900000];
long cnt=0;
void shellSort(int n);
void insertionSort(int n,int g);
void Answer(int n,int G[1000],int m);
int main(void){
	int i,n,m;
	char str[1000];

	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d",&n);
	for(i=0;i<n;i++){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&m);
		B[i]=m;		
	}
	shellSort(n);
	return 0;
}

void shellSort(int n){
	int i,m,G[1000];
	int tmp=0;
	for(m=0; ;m++){
		if(n>=3*tmp+1) G[m]=3*tmp+1;
		else break;
		tmp=3*tmp+1;
	}
	for(i=m-1;i>=0;i--)
		insertionSort(n,G[i]);
	Answer(n,G,m);
}
void insertionSort(int n,int g){
	int i,j,v;
	for(i=g;i<n;i++){
		v = B[i];
		j = i - g;
		while(j>=0 && B[j]>v){
			B[j+g] = B[j];
			j = j - g;
			cnt++;
			B[j+g] = v;
		}
	}
}
void Answer(int n,int G[1000],int m){
	int i;
	printf("%d\n",m);
	for(i=m-1;i>=0;i--){
		if(i!=m-1) printf(" ");
		printf("%d",G[i]);
	}
	printf("\n%d\n",cnt);
	for(i=0;i<n;i++){
		printf("%d\n",B[i]);
	}	
}

Measured memory_bytes: 4712
MAX = 510000;
MOD = 1000000007;

fac = [0]*(MAX)
finv = [0]*(MAX)
inv = [0]*(MAX)

#テーブルを作る前処理
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,MAX):
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD

#二項係数計算
def COM(n,k):
    if n < k: 
      return 0
    if n < 0 or k < 0:
      return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

N,K  = map(int,input().split())

#青の次が赤or終端である場所の数がi
#i-1個の[青,赤]と1個の[青,終端]
#i個の[青,赤]
#i個の[青,赤][青,赤][青,無] 青i　赤i-1
#N+1-i*2個（青K-i個、赤N-K-i+1個の）をi個のペアの間に挟んでいくやりかたの数
#青はペアの左側にくっつく必要があり、
#i個のポケットにk-i個を0~k-i個入れるやりかたの数
#k-i個の要素のi個の分割→k-i個とi-1個の壁を一列に並べる
#k-i+i-1 C i-1
#同様に赤もi+1個のポケットに N-K-i+1個を入れる
#N-K-i+1+i+1-1 C i
COMinit()


for i in range(1, K+1):
  ans = COM(K-1,i-1)*COM(N-K-i+1+i+1-1,i) % MOD
  print(ans)


Measured memory_bytes: 63860
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	int n;
	cin >> n;

	for (int i = 0; i <= 25; i++)
	{
		for (int j = 0; j <= 14; j++)
		{
			if (4 * i + 7 * j == n)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int A, B, K;
  int i, j, k;
  scanf("%d %d %d", &A, &B, &K);
  if(A + K - 1 <= B){
    for(i = A; i <= A + K - 1; i++){
      printf("%d\n", i);
    }
    if(A + K - 1 < B - K + 1){
      for(i = B - K + 1; i <= B; i++){
        printf("%d\n", i);
      }
    }else{
      for(i = A + K; i <= B; i++){
        printf("%d\n", i);
      }
    }
  }else{
    for(i = A; i <= B; i++){
      printf("%d\n", i);
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

#define NMAX 10000

int main(){

	int prime[NMAX+1];
	int N,ans;

	for(int i=0;i<=NMAX;i++){
		prime[i]=1;
	}
	
	prime[0]=0,prime[1]=0;

	for(int i=0;i<=NMAX;i++){
		if(prime[i]==1){
			for(int j=i*2;j<=NMAX;j+=i){
				prime[j]=0;
			}
		}
	}

	while(cin>>N){

		ans=0;
		for(int i=1;i<=N;i++){
			if(prime[i]==1&&prime[N-i+1]==1) ans++;
		}

		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
while(True):
    m,f,r=map(int,input().split())
    if m==f==r==-1:
        exit()
    if m!=-1and f!=-1and m+f>=80:
        print("A")
    elif m!=-1and f!=-1and 65<=m+f<80:
        print("B")
    elif m!=-1and f!=-1and 50<=m+f<65:
        print("C")
    elif m!=-1and f!=-1and 30<=m+f<50 :
        if r<50:
            print("D")
        else:
            print("C")
    else:
        print("F")


Measured memory_bytes: 5596
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
int n;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	
	int x=(c-a)*60+d-b;
	cout<<x-e<<endl;
}

Measured memory_bytes: 3596
import numpy

n, d = map(int, input().split())

l = []
for v in range(n):
    l.append(list(map(int, input().split())))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        if i == j:
            continue
        a = numpy.array(l[i])
        b = numpy.array(l[j])
        c = numpy.linalg.norm(b - a)
        if (c.is_integer()):
            ans += 1

print(ans)


Measured memory_bytes: 14436
import java.util.Scanner


object Main {
  def read(): Canvas = {
    val sc = new Scanner(System.in)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val canvas = Array.ofDim[Boolean](h, w)
    for (y <- 0 until h) {
      val row = sc.next() // 1行読み込み
      for (x <- 0 until w) {
        val c = row.charAt(x)
        canvas(y)(x) = c == '#'
      }
    }
    val canvasList = canvas.map(row => row.toList).toList
    Canvas(w, h, canvasList)
  }

  case class Point(x: Int, y: Int) {
    def +(p: Point) = Point(this.x + p.x, this.y + p.y)
  }

  case class Canvas(w: Int, h: Int, map: List[List[Boolean]]) {
    def isWithin(p: Point): Boolean = 0 <= p.x && p.x < w && 0 <= p.y && p.y < h

    def isBlack(p: Point): Boolean = map(p.y)(p.x)

    def hasBlackNextTo(p: Point): Boolean = {
      val dirs: List[Point] = List(Point(0, 1), Point(0, -1), Point(1, 0), Point(-1, 0))
      dirs.exists(dir => {
        val next = p + dir
        isWithin(next) && isBlack(next)
      })
    }
  }


  def main(args: Array[String]): Unit = {
    val canvas = read()
    // 任意の点に対して、上下左右に点が存在すればよい
    val result = canvas.map.zipWithIndex.forall {
      case (row: List[Boolean], y: Int) =>
        row.zipWithIndex.forall {
          case (isBlack: Boolean, x: Int) =>
            !isBlack || canvas.hasBlackNextTo(Point(x, y))
        }
    }

    println(if (result) "Yes" else "No")
  }
}

Measured memory_bytes: 31084
n = int(input())  
str_list = [input() for _ in range(n)]
AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(n):
  if str_list[i] == 'AC':
    AC +=1
  elif str_list[i] == 'WA':
    WA += 1
  elif str_list[i] == 'TLE':
    TLE += 1
  elif str_list[i] == 'RE':
    RE += 1
print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE)

Measured memory_bytes: 16256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int S, D, M;
	static int[][] P, W;

	public static void main(String[] args) {
		while (sc.hasNext()) {
			S = sc.nextInt();
			D = sc.nextInt();
			M = sc.nextInt();
			W = new int[S][];
			P = new int[S][];
			for (int i = 0; i < S; ++i) {
				int K = sc.nextInt();
				W[i] = new int[K];
				P[i] = new int[K];
				for (int j = 0; j < K; ++j) {
					W[i][j] = sc.nextInt();
					P[i][j] = sc.nextInt();
				}
			}
			int[] dp = new int[M + 1];
			Arrays.fill(dp, -1);
			dp[M] = 0;
			for (int i = 0; i < D; ++i) {
				int F = sc.nextInt();
				for (int j = 0; j < P[F].length; ++j) {
					for (int k = 0; k <= M - P[F][j]; ++k) {
						if (dp[k + P[F][j]] == -1) continue;
						dp[k] = Math.max(dp[k], dp[k + P[F][j]] + W[F][j]);
					}
				}
			}
			int maxW = 0;
			int ansP = 0;
			for (int i = M; i >= 0; --i) {
				if (dp[i] > maxW) {
					maxW = dp[i];
					ansP = M - i;
				}
			}
			System.out.println(maxW + " " + ansP);
		}
	}
}

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

string weather[5] = {"Sunny","Cloudy","Rainy"};

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

	for(int i = 0 ; i < 3 ; i++){
		if(s == weather[i]){
			if(i == 2){
				cout << weather[0] << '\n';
			}else cout << weather[i+1] << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		int d_syurui = sc.nextInt();
		int komugi = sc.nextInt();
		int d_all=0;

		int[] donatu=new int[d_syurui];
		for(int i=0; i<d_syurui; i++){
			String source=sc.next();
				source=source.trim();
				donatu[i] = Integer.parseInt(source);
				d_all+=donatu[i];
		}

		int min=999999999;
		for(int i=0; i<d_syurui; i++){
			if(min>donatu[i]){
				min=donatu[i];
			}
			else{}
		}
		komugi=komugi-d_all;

		int d_kosu=d_syurui+komugi/min;

		System.out.println(d_kosu);

	}
}


Measured memory_bytes: 22740
#!/usr/bin/env ruby
# require 'pry'

# N
# a_1 b_1
# ...
# a_N b_N
# ↑を[[a_1,..a_N],[b_1,..b_N]]にする
# N = gets.to_i
# a, b = N.times.map{gets.split.map(&:to_i)}.transpose

n = gets.to_i
str = ''
n.times do
  str += 'ACL'
end
puts str

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

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main() {
  int number_of_cards, i, answer = 0;
  scanf("%d", &number_of_cards);
  int card[number_of_cards];
  for(i = 0; i < number_of_cards; i++) {
    scanf("%d", &card[i]);
  }
  qsort(card, number_of_cards, sizeof(int), desc);
  for(i = 0; i < number_of_cards; i++) {
    if(i % 2 == 0) {
      answer += card[i];
    } else {
      answer -= card[i];
    }
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
	#include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
	#define debug(x...) { dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals); }
	#define light_debug(x) { dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0; }
#else
	#define debug(x...)
	#define light_debug(x) 
#endif

template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }

template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;


int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	#ifdef DEBUG
		freopen("debug", "w", stderr);
	#endif

	int n; cin >> n;
	int c = 0;
	rep(i, n) {
		int a, b; cin >> a >> b;
		if(a == b) c++;
		else c = 0;
		if(c == 3) { cout << "Yes\n"; return 0; }
	}

	cout << "No\n";
	

	#ifdef DEBUG
		dbg::dout << "\nExecution time: " << clock() << "ms\n";
	#endif

	return 0;
}


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

int main()
{
    int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    if(a+b==c || b+c== a || c+a ==b)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define P           pair<int, int>
#define dint        long double


void solve() {
    int x; cin >> x;
    for(int a=-200; a<=200; a++) {
        for(int b=-200; b<=200; b++) {
            int af = a*a*a*a*a;
            int bf = b*b*b*b*b;
            if(af - bf == x) {
                cout << a << " " << b << endl; return;
            }
        }
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}



Measured memory_bytes: 3608
n=int(input())
s=[list(input()) for _ in range(n)]
dic={}
t=[0]*n
for i in range(n):
	s[i].sort()
	t[i]=str(s[i])
for i in range(n):
	if t[i] in dic:
		dic[t[i]]+=1
	else:
		dic[t[i]]=1
counts=list(dic.values())
count=0
for i in range(len(counts)):
	count+=(counts[i])*(counts[i]-1)/2
print(int(count))

Measured memory_bytes: 45444
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        float sum = 0;
        for(int i = 0; i < n; i++){
            sum = sum + (1 / sc.nextFloat());
        }
        System.out.println(1 / sum);
    }
}

Measured memory_bytes: 22612
#pragma region Imports
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#pragma endregion
#pragma region Macros
#pragma GCC optimize (2)
#define uns unsigned
#define out cout
#define in cin
#define au auto
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define elif else if
#define sz(x) x.size()
#define fl(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define fli(i, a, b, c) for(int (i)=a;(i)<(b);(i)+=(c))
#define fr(i, x) for(int (i)=(x)-1;(i)>=0;(i)--)
#define fb(i, x) for(int (i)=0;(i)<(x);(i)++)
#define fa(i, x) for(auto& (i):(x))
#define ia(a, n) for(int qw=0;qw<(n);qw++)cin>>(a)[qw];
#define oa(a, n) for(int qw=0;qw<(n);qw++)cout<<(a)[qw]<<" ";
#define im(a, n, m) fb(i,(n))fb(j,(m))cin>>(a)[i][j];
#define om(a, n, m) fb(i,(n))fb(j,(m))cout<<(a)[i][j]<<" \n"[j==(m)-1];
#define eb(v, x) (v).emplace_back(x);
#define seb(s, x) (s).emplace(x);
#define pr(x, y) pair<x,y>
#define vr(x) vector<x>
#define mp(x, y) make_pair(x,y)
#define hm(x, y) map<x,y>
#define um(x, y) unordered_map<x,y>
#define stk(x) stack<x>
#define qu(x) queue<x>
#define dq(x) deque<x>
#define pq(x) priority_queue<x>
#define pqm(x) priority_queue<x,vector<x>,greater<(x)>>
#define mem(a, x) memset(a,(x),sizeof(a));
#define fi(x) (x).first
#define se(x) (x).second
#define ql(x) int tc;tc=(x);if(tc==-1)cin>>tc;while(tc--)
#define srt(x) sort((x).begin(),(x).end());
#define pops(y, x) auto (y)=(x).front();(x).pop();
#define ppc(x) __builtin_popcount((x))
#define all(x) (x).begin(),(x).end()
#define sieve(b, n) bool (b)[(n)];mem((b),true);int sq=int(sqrt(n))+1;(b)[0]=(b)[1]=false;fl(i,2,sq)if((b)[i])fli(j,i*i,n,i)(b)[j]=false;
#define dbg(x) cout<<#x<<" "<<(x)<<"\n";
#pragma endregion
#pragma region Typedefs and Consts
typedef long long int ll;
typedef unsigned long long int ull;
typedef string stg;
typedef float flo;
typedef char chr;
typedef vector<int> vi;
const ull mod = 1000000007;
const int imx = INT_MAX;
const int imn = INT_MIN;
const ll lmx = LLONG_MAX;
const ll lmn = LLONG_MIN;
#pragma endregion
#pragma region Functions
inline ull powm(ull x,ull y,bool b=false,ull m=mod){ if(b){ ull t=1;x%=m;while(y>0){ if(y%2)t=(t*x)%m;y=y>>1;x=(x*x)%m; }return t; }else
    { ull t=1;while(y>0){ if(y&2)t*=x;y=y>>1;x*=x; }return t;}}
inline ll gcd(ll a,ll b){a=abs(a);b=abs(b); while(b!=0){ ll c=a%b;a=b;b=c;}return a;}
#pragma endregion

//cout<<"Case #"+to_string(tc+1)+": "+to_string(z)<<endl;
ll d[1<<21];
int a[21][21];
int s[21];
vr(vr(int)) m;
ll f(int n,int v){
  if(v==((1<<n)-1))
    return 1;
  int i=ppc(v);
  if(i==n or (v|s[i])!=(1<<n)-1)
    return 0;
  if(d[v]==-1){
    ll z=0;
    fa(j,m[i])
      if(((v>>j)&1)==0)
      z=(z+f(n,v|(1<<j)))%mod;
    d[v]=z;
  }
  return d[v];
}
int g(vr(int) &x){
  int v=0;
  fa(i,x)
    v|=(1<<i);
  return v;
}
int main() {
  fio
  int n;
  in>>n;
  im(a,n,n)
  fb(i,n){
    vr(int) q;
    fb(j,n)
      if(a[i][j])
        eb(q,j)
    eb(m,q)
   }
  s[n-1]=g(m[n-1]);
  for(int i=n-2;i>=0;i--)
    s[i]=s[i+1]|g(m[i]);
    fb(j,1<<n)
    	d[j]=-1;
  out<<f(n,0);
  return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>
#include <string.h>
int main(void)
{
  char s[4];
  int ans=0,max=0;
  for(int i=0;i<4;i++)
  scanf("%c", &s[i]);
  for(int i=0;i<3;i++){
    if(s[i] == 'S') ans=0;
    else if(s[i]=='R') ans++;
    if(max<ans) max=ans;
  }
  printf("%d", max);
    return 0;
  }

Measured memory_bytes: 1668
use std::collections::HashSet;
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let N = read_line().parse::<i64>().unwrap();
    let A = read_line().split_whitespace().map(|x|x.parse::<i64>().unwrap()).collect::<Vec<i64>>();
    let even = A.into_iter().filter(|x|x % 2 == 0).collect::<Vec<i64>>();
    if even.iter().all(|x|x % 3 == 0 || x % 5 == 0) {
        println!("APPROVED");
    }else{
        println!("DENIED");
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b;
	t = 1;
	while(t--) {
	 cin >> a >> b;
	 cout << a * b - a - b + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
typedef long long int ll;
using namespace std;
ll par[200005];
ll sizee[200005];
#define MAX 200005
void initialize(int n)
{
    for(int i=0;i<=n+3;i++){
        par[i]=i;
        sizee[i]=1;
    }
}
int find_root(int i)
{
    if(par[i]==i)
    {
        return i;
    }
    par[i]=find_root(par[i]);
    return par[i];
}
void unionf(int a ,int b)
{
    int root_a=find_root(a);
    int root_b=find_root(b);
    if(root_a==root_b) return;
    if(sizee[root_a]>sizee[root_b]){
        par[root_b]=root_a;
        sizee[root_a]+=sizee[root_b];
    }
    else{
        par[root_a]=root_b;
        sizee[root_b]+=sizee[root_a];
    }
}

// void display(int n){
//     for(int i=0;i<n;i++) cout<<i<<"  "<<arr[i]<<"   "<<size[i]<<" "<<endl;
// }
vector<ll> v[MAX];

vector<ll> bb[MAX];
int main()
{
    ll t;
    // cin>>t;
    t=1;
    while(t--){
        int n,f,b;
        cin>>n>>f>>b;
        initialize(n);
        
        for(int i=0;i<f;i++){
            int a,b;
            cin>>a>>b;
            unionf(a,b);
            v[a].push_back(b);
            v[b].push_back(a);
        }
        for(int i=0;i<b;i++){
            int a,b; cin>>a>>b;
            bb[a].push_back(b);
            bb[b].push_back(a);
            
        }
        for(int i=1;i<=n;i++){
            ll sz=sizee[find_root(i)];
            sz-=v[i].size();
            // cout<<sz<<endl;
            for(auto j: bb[i]) {
                int x= find_root(i);
                int y= find_root(j);
                if(x==y) sz--;
            }
            // cout<<sz<<endl;
            cout<<sz-1<< " ";
            
        }
    }
}




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

#define N 1000
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  int dp[N+1][N+1];
  char c, fld[N][N];
  int n, ans;
  
  while (cin >> n){
    if (n==0) break;
    // read & init
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
        cin >> c;
        fld[j][i] = c;
        dp[j+1][i+1] = 0;
      }
    }
    for (int i=0; i<=n; i++) dp[i][0] = dp[0][i] = 0;
    // dp
    ans = 0;
    for (int i=1; i<=n; i++){
      for (int j=1; j<=n; j++){
        if (fld[j-1][i-1]=='.'){
          dp[j][i] = MIN(dp[j-1][i-1], MIN(dp[j-1][i], dp[j][i-1])) + 1;
          ans = MAX(ans, dp[j][i]);
        } else {
          dp[j][i] = 0;
        }
//        cout << dp[j][i] << " ";
      }
//      cout << endl;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 7984
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct Edge { int src, dst; };

int main() {
  int n;
  while (cin >> n) {
    vector< vector<Edge> > v(n);
    REP(i,n-1) {
      int a, b; cin >> a >> b; a--; b--;
      v[a].push_back((Edge) { a, b });
      v[b].push_back((Edge) { b, a });
    }

    vll c(n);
    REP(i,n) cin >> c[i];
    sort(RALL(c));

    ll best = 0;
    vint bestV;

    REP(root,n) {
      if (root != 0) continue;
      vint vc(n, -1);
      queue<int> qu;
      int o = 0;
      for (qu.push(root); qu.size();qu.pop()) {
        int p = qu.front();
        if (vc[p] != -1) continue;
        vc[p] = c[o++];
        for(auto e: v[p]) if (vc[e.dst] == -1) qu.push(e.dst);
      }

      ll result = 0;
      REP(i,n) for(auto e: v[i]) result += min(vc[e.src], vc[e.dst]);
      if (result > best) {
        best = result;
        bestV.swap(vc);
      }
    }

    cout << best / 2 << endl;
    REP(i,n) {
      if (i) cout << ' ';
      cout << bestV[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

const ll MAX_N=110;
const ll MAX_V=100100;

ll N,W,w[MAX_N],v[MAX_N];
ll dp[MAX_N][MAX_V];

int main()
{
  cin>>N>>W;
  for(ll i=0;i<N;i++)cin>>w[i]>>v[i];
  for(ll i=0;i<MAX_N;i++)for(ll j=0;j<MAX_V;j++)dp[i][j]=INF;
  dp[0][0]=0;
  for(ll i=0;i<N;i++){
    for(ll sum_v=0;sum_v<MAX_V;sum_v++){
      if(sum_v-v[i]>=0)chmin(dp[i+1][sum_v],dp[i][sum_v-v[i]]+w[i]);
      chmin(dp[i+1][sum_v],dp[i][sum_v]);
    }
  }
  ll res=0;
  for(ll sum_v=0;sum_v<MAX_V;sum_v++){
    if(dp[N][sum_v]<=W)res=sum_v;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 86272
s = str(input())


def solve(query):
    while 1:
        for frag in ["dream", "dreamer", "erase", 'eraser']:
            if query.endswith(frag):
                query = query[:-len(frag)]
                break
        else:
            print("NO")
            break
        if not query:
            print("YES")
            break


solve(s)

Measured memory_bytes: 9308
n = int(input())
T = list(map(int, input().split()))
m = int(input())
drink_list=[]
sum_list = []
for i in range(m):
    drink_list.append(list(map(int, input().split())))    
for i in range(m):
    #元の値を保存しておく
    a = T[drink_list[i][0]-1] 
    T[drink_list[i][0]-1] = drink_list[i][1]
    print(sum(T))
    T[drink_list[i][0]-1] = a
    

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    int64_t yakusu = 0, res = 0;
    for(int i=1; i<n+1; i=i+2){
        yakusu = 0;
        for(int j=1; j<i+1; j++){
            if(i%j==0) yakusu++;
        }
        if(yakusu==8){
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  string s,t="CODEFESTIVAL2016";
  cin >> s;
  int a=0;
  rep(i,s.size()){
    if (a==0){
      if(s[i]=='C') a++;
    }
    if (a==1){
      if (s[i]=='F') a++;
    }
  }
  if (a==2) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=1e9+7;
const ll MAX=300000;
ll fact[MAX+1]={1},inv[MAX+1]={1};


ll modpow(ll a,ll b){
  ll r=1;
  while(b>0){
    if(b%2==1)(r*=a)%=mod;
    (a*=a)%=mod;
    b/=2;
  }
  return r;
}
void cmbinit(){
  rep(i,MAX){
      fact[i+1]=fact[i]*(i+1)%mod;
      inv[i+1]=modpow(fact[i+1],mod-2);
    }
}
ll chose(ll a,ll b){
  return fact[a]*inv[b]%mod*inv[a-b]%mod;
}

int main(){
    int n,k;
    cin>>n>>k;
	cmbinit();
	ll ans=0;
	if(n-1<=k){
		rep(i,n){
			ans+=chose(n,n-i)*chose(n-1,n-i-1)%mod;
			ans%=mod;
		}
	}
	else{
		rep(i,k+1){
			ans+=chose(n,n-i)*chose(n-1,n-i-1)%mod;
			ans%=mod;
		}
	}
	cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
  int a,b,c=0,i,x,y;
  scanf("%d %d",&x,&y);
  for(i=0;i<=x;i++){
    a=i;
    b=x-i;
    if(2*a+4*b==y){
      c=1;
      break;
    }
  }
  if(c==1){
    printf("Yes\n");
  }
  else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include <vector>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;


#define INT_MIN  (-2147483647 - 1)
#define INT_MAX  2147483647

#define MOD 1000000007
#define maxN 100005




int main()
{
	long long N;
	cin >> N;

	vector<long long> nums(N);
	for (int i = 0; i < N; i++)
		cin >> nums[i];

	long long P = 1;
	long long count = 0;
	for (int i = 0; i < N;i++)
	{
		if (nums[i] == P)
			P = nums[i] + 1;
		else if (nums[i] > P)
		{
			count += (nums[i] - 1)/P;
			nums[i] = 1;
			P = max(P, (long long)2);
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i + 3 <= n; i++) {
            String sub = s.substring(i, i + 3);
            if (sub.equals("ABC")) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int Alice = 0, Bob = 0;
    sort(A.begin(), A.end());
    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            Alice += A.at(N - 1 - i);
        }
        else{
            Bob += A.at(N - 1 - i);
        }
    }
    cout << Alice - Bob << endl;
    return 0;
}

Measured memory_bytes: 3596
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let h = nextIntArray()
    let max = 0
    let curr = 0
    for (let i = 0; i < h.length; i++) {
        if (h[i] >= h[i + 1]) {
            curr++
        } else {
            max = Math.max(max, curr)
            curr = 0
        }
    }
    console.log(max)
}
Main()



Measured memory_bytes: 40100
#include <iostream>
 
using namespace std;
 
int gcd(int a,int b){
  if(a % b == 0) 
    return b;
  else 
    return gcd(b, a % b);
}
 
int main() {
  long long int A,B,C,D,cntc,cntd,ans;
  
  cin >> A >> B >> C >> D;
  A--;
  long long int cnt = C*D/gcd(C, D);
 
  cntc = B/C - A/C;
  cntd = B/D - A/D;
  
  ans = cntc + cntd - (B/cnt - A/cnt);
 
  cout << B - A - ans << endl;    
}

Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    val n = in.next.head
    val tree = in.map(_.drop(2).map(_ - 1)).toList
    val res = List.fill(n)(Array.fill(2)(0))
    def solve(start: Int, id: Int): Int =
        if (res(id)(0) != 0) {
            start - 1
        } else {
            res(id)(0) = start
            res(id)(1) = tree(id).foldLeft(start)((_d, _id) => solve(_d + 1, _id)) + 1
            res(id)(1)
        }

    var d = 1
    for (i <- 0 until n if res(i)(0) == 0) {
        d = solve(d, i) + 1
    }
    res.zipWithIndex.foreach{case (x, i) => println(i + 1 + " " + x.mkString(" "))}
}

Measured memory_bytes: 44488
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,cnt=0;
    cin>>n;
    while(n--)
    {
        char x;
        cin>>x;
        if(x=='Y')
        {
            cnt++;
        }
    }
    if(cnt>0)
    {
        cout<<"Four"<<NL;
    }
    else
    {
        cout<<"Three"<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int a, b, c, i, div;
	div = 0;
	scanf("%d%d%d", &a, &b, &c);
	for (i = a; i <= b; i++){
		if (c % i == 0) div++;
	}
	printf("%d\n", div);
	return 0;
}

Measured memory_bytes: 1844
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int Pow2(int x) {
  return x * x;
}

bool IsSquare(int x) {
  int y = (int) sqrt(x);
  return y * y == x;
}

int main() {
  int N, D;
  cin >> N >> D;
  int x[N][D];

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

  int ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int d2 = 0;
      for (int d = 0; d < D; d++) {
        d2 += Pow2(x[i][d] - x[j][d]);
      }
      if (IsSquare(d2)) {
        ans ++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n,m;
    long long k;
    cin>>n>>m>>k;
    vector<long long> a(n+1,0),b(m+1,0);
    for(int i=0;i<n;++i){
        cin>>a[i+1];
        a[i+1]+=a[i];
    }
    for(int i=0;i<m;++i){
        cin>>b[i+1];
        b[i+1]+=b[i];
    }

    int ans=0;
    for(int i=0;i<=n;++i){
        long long rest=k-a[i];
        if(rest<0) continue;
        int temp=upper_bound(b.begin(),b.end(),rest)-b.begin()-1+i;
        ans=ans<temp?temp:ans;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6432
// https://atcoder.jp/contests/arc062/tasks/arc062_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  ll f, s;
  cin >> f >> s;

  rep(i, N - 1) {
    ll fr, sr;
    cin >> fr >> sr;

    if (f * sr == s * fr) continue;

    ll min_n_f = fr * ((f + fr - 1) / fr);  // f を超える最小の fr の倍数
    ll min_n_s = sr * ((s + sr - 1) / sr);

    VL f_cand(0);
    VL s_cand(0);

    if (min_n_f / fr * sr >= s) {
      f_cand = {min_n_f, min_n_f / fr * sr};
    }

    if (min_n_s / sr * fr >= f) {
      s_cand = {min_n_s / sr * fr, min_n_s};
    }

    if (f_cand.size() != 0 &&
        (s_cand.size() == 0 ||
         f_cand[0] + f_cand[1] <= s_cand[0] + s_cand[1])) {
      f = f_cand[0];
      s = f_cand[1];
    } else {
      f = s_cand[0];
      s = s_cand[1];
    }
  }

  cout << f + s << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG other_contests/codefes2017qualb/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

vector<vector<int>> g;
vector<int> color;// 0: not visited, -1: white, 1: black

bool is_bipartite(int k){// 連結であることを前提とする
    bool rev = true;
    rep(i, g[k].size()){
        if(color[g[k][i]] == 0){// unvisited
            color[g[k][i]] = -color[k];
            if(!is_bipartite(g[k][i])){
                return false;
            }
        }else{
            if(color[g[k][i]] == color[k]){
                return false;
            }
        }
    }
    return rev;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll n, m;
    cin >> n >> m;
    g.resize(n);
    color.resize(n);
    rep(i, n){
        color[i] = 0;
    }

    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    color[0] = 1;
    bool bi = is_bipartite(0);
    
    if(bi){
        ll u = 0; 
        ll v = 0;
        rep(i, n){
            if(color[i] == 1) u++;
            else v++;
        }
        ll ans = u * v - m;
        cout << ans << "\n";
    }else{
        ll ans;
        ans = n * (n - 1) / 2 - m;
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 6400
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
struct unionfind{
  private:
  int maxN;
  vector<int> par,treesize;
  public:unionfind(int N) :maxN(N),par(N),treesize(N,1){
    for(int i=0;i<maxN;++i)par[i]=i;
  }
  int root(int x){
    while(par[x]!=x){
      x=par[x]=par[par[x]];
    }
    return x;
  }
  bool unite(int x,int y){
    int px=root(x);
    int py=root(y);
    if(px==py)return false;
    if(treesize[px]>treesize[py])swap(px,py);
    par[px]=py;
    treesize[py]+=treesize[px];
    return true;
  }
  bool parcheck(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return treesize[root(x)];
  }
  void clear(){
    treesize.assign(maxN,1);
    for(int i=0;i<maxN;++i)par[i]=i;
  }
};

int main(){
  ll i,N,M,a,b,ans;
  cin>>N>>M;
  unionfind tree(N);
  pvec v(M);
  stack<ll> st;
  rep(i,M){
    cin>>a>>b;
    v[i]=datas(a-1,b-1);
  }
  ans=N*(N-1)/2;
  st.push(ans);
  while(M--){
    a=v[M].first;b=v[M].second;
    if(tree.root(a)==tree.root(b)){
      st.push(ans);
      continue;
    }
    ans-=tree.size(a)*tree.size(b);
    st.push(ans);
    tree.unite(a,b);
  }
  st.pop();
  while(!st.empty()){
    cout<<st.top()<<endl;
    st.pop();
  }
  return 0;
}

Measured memory_bytes: 4252
#include<cstdio>
char c[5]="RYGB",s[510];
int main(){
	int H,W,d;
	scanf("%d%d%d",&H,&W,&d);
	for(int i=0;i<H;i++,puts(s))
		for(int j=0;j<W;j++)s[j]=c[(i+j)/d%2*2+(i+W-j)/d%2];
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
    int n, minj;
    cin >> n;
    string A[n], B[n], state="Stable";
    for (int i=0; i<n; i++){
        cin >> A[i];
        B[i] = A[i];
    }
    for (int i=0; i<n; i++){
        for (int j=n-1; j>i; j--){
            if (A[j][1] < A[j-1][1]){
                swap(A[j],A[j-1]);
            }
        }
    }
    for (int i=0; i<n; i++){
        if (i == n-1){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    cout << "Stable" << endl;
    for (int i=0; i<n; i++){
        minj = i;
        for (int j=i; j<n; j++){
            if (B[j][1] < B[minj][1]){
                minj = j;
            }
        }
        swap(B[i], B[minj]);
    }
    for (int i=0; i<n; i++){
        if (i == n-1){
            cout << B[i] << endl;
        } else {
            cout << B[i] << " ";
        }
        if (A[i] != B[i]) state="Not stable";
    }
    cout << state << endl;
    return 0;
}


Measured memory_bytes: 3164
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

k = 10**5
pp = [i+1 for i in range(9)]
kkk = [i+1 for i in range(9)]
while True:
    ad = []
    for i in pp:
        po = str(i)[-1]
        if po != "0":
            ad.append(i*10+int(po)-1)
            kkk.append(i*10+int(po)-1)
        if po != "9":
            ad.append(i*10+int(po)+1)
            kkk.append(i*10+int(po)+1)
        kkk.append(i*10+int(po))
        ad.append(i*10+int(po))
        pp = ad
        
    if len(kkk) >= 10**5:
        break
kkk.sort()
n = onem()
print(kkk[n-1])


    








Measured memory_bytes: 57688
#include <iostream>
#include <string>
#include<math.h>
using namespace std;
int main(void){
int A, B, C, D;
cin >> A >> B >> C >> D;
int r1 = max(A, C);
int r2 = min(B, D);
if (r1 >= r2) cout << 0 << endl;
else cout << r2 - r1 << endl;
}

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


int a,b,i,j,k,si;
struct node{
    long long int x,y,z;
}n[1010];

bool cmp(node w, node e){
    return w.x*i+w.y*j+w.z*k>e.x*i+e.y*j+e.z*k;
}

long long int sum[1010],ans;

int main(){
    while(cin>>a>>b){
        for(int q=0; q<a; q++){
            cin>>n[q].x>>n[q].y>>n[q].z;
        }

        si = 0;
        memset(sum,0,sizeof(sum));

        for(i=-1; i<=1; i+=2)
            for(j=-1; j<=1; j+=2)
                for(k=-1; k<=1; k+=2){
                    sort(n, n+a, cmp);
                    for(int u=0; u<b; u++){
                        sum[si]+=n[u].x*i+n[u].y*j+n[u].z*k;
                    }
                    si++;
                }

        for(int q=0; q<si; q++){
            if(q==0)
                ans = sum[q];
            else if(ans < sum[q])
                ans = sum[q];
        }

        cout<<ans<<endl;
    }
    return 0;
}


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

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

  int cnt;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;;
  
}

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

using namespace std;
#define rep(i, n) for (long long i=0; i<(long long)(n); i++)

int main(int, char**) {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	priority_queue<long long> P, Q, R;
	rep(i, a) {
		long long p;
		scanf("%lld", &p);
		P.push(p);
	}
	rep(i, b) {
		long long q;
		scanf("%lld", &q);
		Q.push(q);
	}
	rep(i, c) {
		long long r;
		scanf("%lld", &r);
		R.push(r);
	}
	rep(i, x) {
		R.push(P.top());
		P.pop();
	}
	rep(i, y) {
		R.push(Q.top());
		Q.pop();
	}
	long long ans = 0;
	rep(i, x+y) {
		ans += R.top();
		R.pop();
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int add[3][3] = {
			{0, 1, 2},
			{1, 1, 2},
			{2, 2, 2}
		};

int prod[3][3] = {
			{0, 0, 0},
			{0, 1, 1},
			{0, 1, 2}
		};

int minu[3] = {2, 1, 0};

int P, Q, R;

string str;

int eval(int &pos){
	if(str[pos]=='0'){ pos++; return 0; }
	if(str[pos]=='1'){ pos++; return 1; }
	if(str[pos]=='2'){ pos++; return 2; }
	if(str[pos]=='P'){ pos++; return P; }
	if(str[pos]=='Q'){ pos++; return Q; }
	if(str[pos]=='R'){ pos++; return R; }
	if(str[pos]=='-'){ pos++; return minu[eval(pos)]; }
	if(str[pos++]=='('){
		int a = eval(pos);
		char op = str[pos++];
		int b = eval(pos);
		pos++;
		if(op=='+') return add[a][b];
		if(op=='*') return prod[a][b];
	}
}

int main(){
	while(1){
		cin >> str;
		if(str==".") break;
		int ans=0;
		int pos=0;
		for(P=0; P<3; P++){
			for(Q=0; Q<3; Q++){
				for(R=0; R<3; R++){
					int pos=0;
					int result = eval(pos);
					if(result==2) ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

pair<int, int> ab[100000];

int main()
{
	int N, a, b, ans = 0;
	ll K, sum = 0;

	cin >> N >> K;
	rep(i, N) {
		cin >> a >> b;
		ab[i].first = a;
		ab[i].second = b;
	}

	sort(ab, ab + N);

	rep(i, N) {
		a = ab[i].first;
		b = ab[i].second;

		sum += b;
		if (ans == 0 && sum >= K) ans = a;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
    int N, K; cin >> N >> K;
    int R, S, P; cin >> R >> S >> P;
    string T; cin >> T;

    int ans = 0;
    string te;

    for (int i = 0; i < N; i++) {
        if (i - K >= 0 && T[i] == T[i - K] && te[i - K] != T[i]) {
            ans += 0;
            te += T[i];
        } else {
            if (T[i] == 'r') {
                ans += P;
                te += 'p';
            } else if (T[i] == 'p') {
                ans += S;
                te += 's';
            } else {
                ans += R;
                te += 'r';
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> a1;
  vector<int> an;
  int x, y;
  for (int i = 0; i < M; ++ i) {
    cin >> x >> y;
    if (x > y) swap(x, y);
    if (x == 1) a1.push_back(y);
    else if (y == N) an.push_back(x);
  }
  sort(a1.begin(), a1.end());
  sort(an.begin(), an.end());
  int p = 0, q = 0;
  while (p < a1.size() && q < an.size()) {
    if (a1[p] < an[q]) ++ p;
    else if (a1[p] > an[q]) ++ q;
    else break;
  }
  if (p < a1.size() && q < an.size()) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>

int main()
{
    using namespace std;
    
    int n, i, t, x[1000], y[1000];
    double ans1, ans2, ans3, ans4;
    
    cin >> n;
    
    for (i = 0; i < n; ++i) cin >> x[i];
    for (i = 0; i < n; ++i) cin >> y[i];
    
    ans1 = ans2 = ans3 = ans4 = 0;
    
    for (i = 0; i < n; ++i) { 
        t = abs(x[i] - y[i]);
        ans1 += t;
        ans2 += t * t;
        ans3 += t * t * t;
        if (ans4 < t) ans4 = t;
    }

    cout << fixed << ans1 << endl 
    << sqrt(ans2) << endl
    << cbrt(ans3) << endl
    << ans4 << endl;

    return 0;
}

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

int main(){
    string A, B;
    cin >> A >> B;

    if(A.length() < B.length()) cout << "LESS" <<endl;
    else if(A.length() > B.length()) cout << "GREATER" << endl;
    else{
        string ans = "EQUAL";
        for(int i=0; i< A.length(); i++){
            if(A.at(i) > B.at(i)){
                ans = "GREATER";
                break;
            }
            else if(A.at(i) < B.at(i)){
                ans = "LESS";
                break;
            }

        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256