akhauriyash/Code-Regression huggingface dataset:
n = int(input())
n_card = list(range(1, 14))
card = {'S':n_card.copy(), 'H':n_card.copy(), 'C':n_card.copy(), 'D': n_card.copy()}
for i in range(n):
    s, val = input().split()
    val = int(val)
    card[s].remove(val)
for k in 'SHCD':
    for item in card[k]:
        print(k, item)



Measured memory_bytes: 5596
import itertools
n, m = map(int, input().split())

S = []
for i in range(m):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
P = [int(i) for i in input().split()]
    
A = [0, 1]
ans = 0
for a in itertools.product(A, repeat = n):
    flag = 0
    for j in range(m):
        cnt = 0
        for s in S[j]:
            if a[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int medi_left, medi_right, n; cin >> n;
    vector<int> num(n), original(n);
    REP(i, n){
        cin >> num[i];
        original[i] = num[i];
    }
    whole(sort, num);
    medi_left = num[n / 2 - 1];
    medi_right = num[n / 2];
    REP(i, n){
        if(original[i] < num[n / 2]) cout << medi_right << endl;
        else cout << medi_left << endl;
    }
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI D(N);
  rep(i,N) cin>>D[i];
  int M;
  cin>>M;
  VI T(M);
  rep(i,M) cin>>T[i];
  int ans=1;
  multiset<int> S;
  rep(i,N) S.insert(D[i]);
  rep(i,M){
    if(S.find(T[i])!=S.end()){
      S.erase(S.find(T[i]));
    }else ans=0;
  }
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 11136
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		
      	// 買えるかどうか判定し、結果を出力
      	if(a + b >= c){
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
	}
}

Measured memory_bytes: 20948
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int[] b=new int[a];
        int count=0;
        int answer=0;
        for(int i=0;i<a;i++){
            b[i]=sc.nextInt();
            if(count<=b[i]){
                count=b[i];
                answer++;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21588
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7

#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b, c; cin >> a >> b >> c;

  for (int i = 0; i <= 100; ++i) {
    if (i * a % b == c) flag = true;
    if (flag) break;
  }
      
  // cout << num << endl;
  cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream> 
using namespace std; 
float round(float var) 
{ 
    // 37.66666 * 100 =3766.66 
    // 3766.66 + .5 =3767.16    for rounding off value 
    // then type cast to int so value is 3767 
    // then divided by 100 so the value converted into 37.67 
    float value = (int)(var * 100 + .5); 
    return (float)value / 100; 
} 
  
int main() 
{ 
 	int n = 0;
     
    std::cin>>n; 
    float var = 2 * n * 3.14159265358;
    cout << round(var); 
    return 0; 
} 


Measured memory_bytes: 3788
#include<stdio.h>
#

int main(){

int N,A,odd=1,exp=1;
scanf("%d",&N);
for (int i = 0; i < N; i++){
    scanf("%d",&A);
    if (A%2==0){ odd*=2;}
}

for (int i = 1; i <= N; i++){exp*=3;}

printf("%d",exp-odd);

return 0;

}

Measured memory_bytes: 1732
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
    ll N;
    //N 辺の数 V

    vector<edge> G[100001];
    ll d[100001];
    ll f[100001];
    ll ans=0;
    void dijkstra(int s){
        std::priority_queue<P,vector<P>,std::greater<P>> que;
        std::fill(d,d+N,INF);
        d[s]=0;
        que.push(P(0,s));
        while(!que.empty()){

            P p =que.top();que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(int i=0;i<(signed)G[v].size();i++){
                edge e =G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }
    void dijkstra1(int s){
        std::priority_queue<P,vector<P>,std::greater<P>> que;
        std::fill(f,f+N,INF);
        f[s]=0;
        que.push(P(0,s));
        while(!que.empty()){

            P p =que.top();que.pop();
            int v=p.second;
            if(f[v]<p.first)continue;
            for(int i=0;i<(signed)G[v].size();i++){
                edge e =G[v][i];
                if(f[e.to]>f[v]+e.cost){
                    f[e.to]=f[v]+e.cost;
                    que.push(P(f[e.to],e.to));
                }
            }
        }
    }



int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N-1){
        //DEB(i) END
        int a,b;
        cin>>a>>b;
        edge es;
        es.to=b-1,es.cost=1;
        G[a-1].push_back(es);
        es.to=a-1;
        G[b-1].push_back(es);
    }
    // f fenecc
    dijkstra1(0);
    dijkstra(N-1);
    REP(i,N){
        DEB(f[i])DEB(d[i])END
        if(f[i]<=d[i])ans++;
    }
    (ans>(N-ans))?cout<<"Fennec":cout<<"Snuke";
    return 0;
}

//ARC 078 D - Fennec VS. Snuke


Measured memory_bytes: 8304
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}
// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int n, m, k;
    cin >> n >> m >> k;
    VI a(n + 2);
    VI b(m + 2);
    for (Int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    a[0] = 0;
    a[n + 1] = 1e09 + 7;
    for (Int i = 1; i <= n + 1; ++i) {
        a[i] += a[i - 1];
    }
    b[0] = 0;
    b[m + 1] = 1e09 + 7;
    for (Int i = 1; i <= m; ++i) {
        cin >> b[i];
    }
    for (Int i = 1; i <= m + 1; ++i) {
        b[i] += b[i - 1];
    }

    Int result = 0;
    Int i = 0;
    Int j = m + 1;
    while (1) {
        if (a[i] + b[j] > k) {
            --j;
            if (j == -1) {
                break;
            }
        } else {
            result = Max(result, i + j);
            ++i;
            if (i == n + 2) {
                break;
            }
        }
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 6400
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	string s; int K;
	cin >> s >> K;
	for (int i = 0; i < s.size(); i++) {
		int p = 'z' - s[i] + 1;
		if (s[i] == 'a')continue;
		else if (p <= K) {
			s[i] = 'a';
			K -= p;
		}
		else if (p >= K)continue;
	}
	if (K != 0) {
		int p = s.back() - 'a';
		p += K;
		p %= 26;
		s.back() = 'a' + p;
	}
	cout << s << endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader
import java.util.*

fun main() = arc059d()

@OptIn(ExperimentalStdlibApi::class)
fun arc059d() = SimpleFastIOWithToken_arc059d().exec {
    val s = readString()

    for (c in 'a'..'z') {
        var beforeAppearedIndex = -100
        for (i in s.indices) {
            if (s[i] == c) {
                if (i - beforeAppearedIndex <= 2) return@exec println("${beforeAppearedIndex + 1} ${i + 1}")
                beforeAppearedIndex = i
            }
        }
    }

    println("-1 -1")
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_arc059d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_arc059d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 36556
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,m,i,j,f[2005][2005],max1,l[2005],r[2005],top,zhan[2005];
char s[2005][2005];
int main(){
	//freopen("camp.in","r",stdin);
	//freopen("camp.out","w",stdout);
	n=read();m=read();
	for(i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	max1=max(n,m);
	for(i=1;i<=n;i++)
		for(j=1;j<m;j++){
			if(s[i][j]==s[i][j+1]){
				if(f[i-1][j]>0)
					f[i][j]=f[i-1][j]+1;
				else
					f[i][j]=1;
			}
			else{
				if(f[i-1][j]<0)
					f[i][j]=f[i-1][j]-1;
				else
					f[i][j]=-1;
			}
		}
	for(i=1;i<=n;i++){
		top=1;
		zhan[top]=0;
		for(j=1;j<m;j++){
			f[i][j]=abs(f[i][j]);
			while(f[i][j]<=f[i][zhan[top]])
				top--;
			l[j]=zhan[top];
			top++;
			zhan[top]=j;
		}
		top=1;
		zhan[top]=m;
		for(j=m-1;j>=1;j--){
			while(f[i][j]<=f[i][zhan[top]])
				top--;
			r[j]=zhan[top];
			top++;
			zhan[top]=j;
		}
		for(j=1;j<m;j++)
			max1=max(max1,(r[j]-l[j])*f[i][j]);
	}
	pus(max1,2);
	return 0;
}

Measured memory_bytes: 19840
n=int(input())
if n==0:print(0)
else:
    a=""
    while n!=0:
        k=n%4
        if k==0:a="00"+a
        elif k==1:
            a="01"+a
            n-=1
        elif k==2:
            a="10"+a
            n+=2
        elif k==3:
            a="11"+a
            n+=1
        n//=4
    print(int(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    vi as(3);
    for (int i = 0; i < 3; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    cout << as[0] * as[1] / 2 << endl; 
}

Measured memory_bytes: 256
N=int(input())

M=0

for i in range(1,6):
    if N<10**i:
        if i%2==1:
            M+=N-10**(i-1)+1
            break
        else:
            break

    else:
        if i%2==1:
            M+=9*(10**(i-1))


print(M)




Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int a[10];
bool f=1;
int main()
{
	int n,m,q,t;
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>a[i];
	for(int i=n;;i++)
	{
		t=i;
		while(t!=0)
		{
			q=t%10;
			t=t/10;
			for(int j=0;j<m;j++)
				if(q==a[j])
				{
					f=0;
					break;
				}
			if(f==0)
				break;
		}
		if(f==1){ 
			cout<<i<<endl;
			return 0;
		}
		f=1;
	}
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

const int POOL_SIZE = 11;

ll k;
int digit = 0;

ll nextLunlun(ll num)
{
	// num は lunlun の前提
	if ((int)log10(num) < (int)log10(num + 1))
	{
		return num + 1;
	}

	int a = num % 10;
	num /= 10;
	int b = num % 10;

	int loop_cnt = 0;
	while(num)
	{
		if (a - b < 1 && a * b != 81)
		{
			break;
		}

		a = b;
		num /= 10;
		b = num % 10;		
		loop_cnt++;
	}

	num = num * 10 + a + 1;
	for(int i = 0; i < loop_cnt; ++i)
	{
		num = num * 10 + a;
		a = max(0, a - 1);
	}
	return num;
}

void solve()
{
	cin >> k;
	//cout << nextLunlun(k) << endl;
	//return;

	ll cnt = 1;
	ll i = 1;
	
	while(i <= 3234566667)
	{
		if (cnt == k)
		{
			cout << i << endl;
			return;
		}
		i = nextLunlun(i);
		++cnt;
	}
}

void solve2()
{
	cin >> k;
	deque<ll> q;

	for(int i = 1; i <= 9; ++i)
	{
		q.push_back(i);
	}

	int cnt = 0;
	ll n = 0;
	while(cnt++ < k)
	{
		n = q.front();
		q.pop_front();

		if(n % 10 != 0)
		{
			q.push_back(n * 10 + n % 10 - 1);						
		}

		q.push_back(n * 10 + n % 10);

		if(n % 10 != 9)
		{
			q.push_back(n * 10 + n % 10 + 1);
		}
	}
	cout << n << endl;
}

int main()
{
	fastio;
	solve2();

	return 0;
}

Measured memory_bytes: 1792
n = gets.to_i
arr = [111,222,333,444,555,666,777,888,999]

def what_number_take_part_in(n,arr)
  if n <= 111 ; puts "111" ; return ; end
  
  8.times.with_index do |i|
    if n > arr[i] && n <= arr[i+1] 
      puts arr[i+1]
      break
    end
  end
end

what_number_take_part_in(n,arr)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  int ans = a[n-1] - a[0];
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
xpy = []
xmy = []
for i in range(n):
    x,y = map(int,input().split())
    xpy.append(x+y)
    xmy.append(x-y)
xpy.sort()
xmy.sort()
print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1])))

Measured memory_bytes: 99616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s;
    cin >> s;
    int n = s.size();

    constexpr int M = 2019;

    int p[M] = {}, q[M];

    for (int j = 0; j < M; j++) {
        q[j] = j;
    }

    ll r = 0;
    for (int i = 0; i < n; i++) {
        int c = s[i] - '0';

        for (int j = 0; j < M; j++) {
            q[j] = (q[j] * 10 + c) % M;
        }

        for (int j = 0; j < M; j++) {
            if (q[j] == c) p[j]++;
            if (q[j] == 0) r += p[j];
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;
vector<int> e[114514];
int n;
bool b[114514]={};
int ra[114514]={};
vector<int> r;
void dfs(int s,int p){
    ra[s]=p;
    for(int i=0;i<e[s].size();i++){
        if(ra[e[s][i]]==0)dfs(e[s][i],p+1);
    }
}
void dfs(int s){
    b[s]=true;
    for(int i=0;i<e[s].size();i++){
        if(ra[s]>ra[e[s][i]]){
            dfs(e[s][i]);
            r.push_back(e[s][i]);
        }
    }
}
bool reached[114514]={};
int dfs2(int s,int t){
    int re=1;
    reached[s]=true;
    for(int i=0;i<e[s].size();i++){
        if(!reached[e[s][i]]&&e[s][i]!=t){
            re+=dfs2(e[s][i],t);
        }
    }
    return re;
}
signed main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        e[a-1].push_back(b-1);
        e[b-1].push_back(a-1);
    }
    dfs(0,1);
    dfs(n-1);
    r.push_back(n-1);
    int a=dfs2(0,r[(r.size()+1)/2]);
    cout<<(a>n-a?"Fennec":"Snuke")<<endl;
    return 0;
}


Measured memory_bytes: 12792
import java.io.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
int x[]=new int[5];
for(int i=0;i<5;i++)
{
x[i]=Integer.parseInt(input.readLine());
}
int i=((x[1]%x[3]==0)?x[1]/x[3]:x[1]/x[3]+1);
int j=((x[2]%x[4]==0)?x[2]/x[4]:x[2]/x[4]+1);

System.out.println(x[0]-((i>j)?i:j));
}
}

Measured memory_bytes: 16908
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ').Select(txt => decimal.Parse(txt)).ToList();

        var x = inputs[0] * inputs[1];
        var x2 = Math.Floor(x);
        Console.WriteLine(x2);
    }
}

Measured memory_bytes: 28408
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.numeric;
import std.math;

void main() {
  auto N = readln.chomp.to!int;
  auto Ln = readln.split.to!(int[]).sort;

  auto sizes = new int[1002];
  int count = 0;
  auto last = reduce!(delegate(int a, int b){
    foreach(i; a..b) sizes[i+1] = count;
    count++;
    return b;
  })(0, Ln);
  foreach(i; last..1001) sizes[i+1] = count;
  debug writeln(sizes);

  int total = 0;
  foreach(j; 1..N-1) {
    auto b = Ln[j];
    for(int i=0; i<j; i++) {
      auto a = Ln[i];
      total += sizes[a+b > 1001 ? 1001 : a+b] - j - 1;
    }
  }

  writeln(total);
}


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

int main() {

  int N,realmax=100;
  cin >> N ;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    int max = 0;  
     for (int ii = 0; ii < 50; ii++) {    
        if (A % 2 == 0){
      	  A = A / 2;
     	  max++;
        }else{
      		break;
    	}
     } 
   if( max < realmax ){
    realmax = max;  
    }
  }
  cout << realmax << endl;
}


Measured memory_bytes: 3640
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        int n = int.Parse(Console.ReadLine());
        int a = n / 100;
        int b = (n % 100) / 10;
        int c = (n % 100) % 10;
        
        if(a == 1)
        {
            a = 9;
        }
        else if(a == 9)
        {
            a = 1; 
        }
        
        if(b == 1)
        {
            b = 9;
        }
        else if(b == 9)
        {
            b = 1; 
        }
        
        if(c == 1)
        {
            c = 9;
        }
        else if(c == 9)
        {
            c = 1; 
        }
        
        Console.WriteLine(a * 100 + b * 10 + c);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 998244353;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> s(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cin >> s.at(i).at(j);
  }
  vector<vector<int>> table(h,vector<int>(w,-1));
  queue<pii> q;
  q.push(pii(0,0));
  table.at(0).at(0) = 1;
  bool flag = false;
  int count;
  while(!q.empty()){
    pii tmppair = q.front();
    q.pop();
    int x,y;
    tie(x,y) = tmppair;
    set<pii> se;
    if(x-1 >= 0)se.insert(pii(x-1,y));
    if(x+1 < h)se.insert(pii(x+1,y));
    if(y-1 >= 0)se.insert(pii(x,y-1));
    if(y+1 < w)se.insert(pii(x,y+1));
    for(auto t:se){
      int tx,ty;
      tie(tx,ty) = t;
      if(s.at(tx).at(ty) == '.' && table.at(tx).at(ty) == -1){
        table.at(tx).at(ty) = table.at(x).at(y) + 1;
        q.push(t);
      }
      if(t == pii(h-1,w-1)){
        count = table.at(tx).at(ty);
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  if(!flag) cout << -1 << endl;
  else{
    int count2 = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(s.at(i).at(j) == '#')count2++;
      }
    }
    cout << h * w - count - count2 << endl;
  }
}

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

#define ll long long
// #define endl '\n'

// void max_self(ll &a, ll b){a = max(a, b);}
// void min_self(ll &a, ll b){a = min(a, b);}

void solve(){
	string s; cin>>s;
	ll cnt = 0, ans = 0;
	for(char i : s){
		if(i == 'W'){
			ans += cnt;
		}else{
			cnt++;
		}
	}
	cout<<ans<<endl;
}

int main(){
	// cout<<fixed<<setprecision(6);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3764
N = int(input())
dp = [[[[0 for _ in range(4) ]for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
MOD = 10 ** 9 + 7

dp[0][0][0][0] = 1 
A, G, C, T = 0, 1, 2, 3

for i in range(N):
    for c1 in range(4): 
        for c2 in range(4): 
            for c3 in range(4): 
                for c in range(4): 
                    if (c, c1, c2) in [(A,G,C), (G,A,C), (A,C,G)]:
                        continue
                    if (c, c2, c3) == (A,G,C):
                        continue
                    if (c, c1, c3) == (A,G,C):
                        continue
                    dp[i+1][c][c1][c2] += (dp[i][c1][c2][c3] % MOD)

ans = 0
for c1 in range(4):
    for c2 in range(4):
        for c3 in range(4):
            ans += dp[N][c3][c2][c1]

print(ans % MOD)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;
int N, Q;

inline int64_t gO(int x, int y, int pow, int rotate) {
	if(pow == 0){
		return 0;
	}
	int hpow = 1 << (pow - 1);
	int seg = (x < hpow) ? ( (y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2);
	seg = (seg + rotate) & 3;
	const int rotateDelta[4] = {3, 0, 0, 1};
	int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
	int nrot = (rotate + rotateDelta[seg]) & 3;
	int64_t subSquareSize = int64_t(1) << (2 * pow - 2);
	int64_t ans = seg * subSquareSize;
	int64_t add = gO(nx ,ny ,pow - 1, nrot);
	ans += (seg == 1||seg == 2) ? add : (subSquareSize - add - 1);
	return ans;
}

struct query{
	int id, l, r;
    int64_t billa;
    inline void cO() {
	    billa = gO(l, r, 19, 0);
	}
};

inline bool cmp(query a, query b) {
	return a.billa < b.billa;
}

void compute(query QQ[], int a[]) {
    int curL = QQ[0].l, curR = QQ[0].l - 1;
    int diff = 0; 
    int cnt[N+1] = {0}, ANS[Q] = {0};
    for(int i = 0; i < Q; i++) {
        while(curL < QQ[i].l) {
            cnt[a[curL]]--; 
            if(cnt[a[curL]] == 0) diff--;
            curL++;
        }

        while(curL > QQ[i].l) {
            --curL;
            cnt[a[curL]]++;
            if(cnt[a[curL]] == 1) diff++;
        }

        while(curR < QQ[i].r) {
            ++curR;
            cnt[a[curR]]++;
            if(cnt[a[curR]] == 1) diff++;
        }

        while(curR > QQ[i].r) {
            cnt[a[curR]]--;
            if(cnt[a[curR]] == 0) diff--;
            curR--;
        }

        ANS[QQ[i].id] = diff;
    }
    for(int i = 0; i < Q; i++) cout << ANS[i] << "\n";
}

void solve() {
    int L, R; cin >> N >> Q;
    query QQ[Q]; int a[N+1];
    for(int i = 1; i <= N; i++) cin>>a[i];
    for(int i = 0; i < Q; i++) {
        cin >> L >> R;
        QQ[i].l = L; QQ[i].r = R; QQ[i].id = i;
        QQ[i].cO();
    }
    sort(QQ, QQ + Q, &cmp);
    compute(QQ, a);   
}

int main() {
    fast 
    // input output
    int t = 1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 21276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()    //昇順
#define rall(x)       (x).rbegin(), (x).rend()  //降順
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(n);
    repin(l, n);
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = i; j < n; j++) {
            for (ll k = j; k < n; k++) {
                ll a = l[i];
                ll b = l[j];
                ll c = l[k];
                if (a != b && b != c && c != a) {
                    if (a + b > c && b + c > a && c + a > b) {
                        ans++;
                    }
                }
            }
        }
    }
    out(ans);
}

Measured memory_bytes: 3644
import numpy as np

N, M, X = map(int, input().split())

ca = []
for _ in range(N):
  ca.append( list(map(int, input().split())))
ca.sort(key=lambda x:-x[0])
ca = np.array(ca)
#
ans = 10000000
skill = [0]*(M+1)


def DFS(n):
  global ans,skill
  if skill[0] >= ans:
    return
  if min(skill[1:]) >= X:
    ans = min(ans, skill[0])
    return
  if n >= N:
    return
  DFS(n+1)
  skill = skill + ca[n]
  DFS(n+1)
  skill = skill - ca[n]
  return
#

DFS(0)
if ans == 10000000:
  print(-1)
else:
  print(ans)
#

Measured memory_bytes: 27212
n, y = map(int,input().split())

ans = [-1,-1,-1]
for i in range(n,-1,-1):
    if i*10000 > y:
        continue
    else:
        yt = y-i*10000
        nt = n-i
        for j in range(min(yt//5000+1,nt+1)):
            yn = yt - j*5000
            nn = nt - j
            if nn*1000 == yn:
                ans = [i,j,nn]
                break
        if ans != [-1,-1,-1]:
            break
ans = map(str,ans)
a = " ".join(ans)
print(a)

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

using namespace std;

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

	int n; cin >> n;

	vector<int> input(n);
	for (int i = 0; i < n; ++i) cin >> input[i];
	auto cp = input;
	sort(cp.begin(), cp.end());

	int B = cp[n / 2 - 1], B1 = cp[n / 2];
	for (int i = 0; i < n; ++i) cout << ((input[i] > B) ? B : B1) << endl;

	return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>
int main(void){
    int a,num[100000]={},i,max,min;
    long int sum;
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&num[i]);
    }
    max=num[0];
    min=num[0];
    sum=0;
    for(i=0;i<a;i++){
        if(max<num[i]){max=num[i];}
        if(min>num[i]){min=num[i];}
        sum+=num[i];
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 1000
//DEEPANSHU RAWAT
//BTECH/10530/18
 
#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 998244353
using namespace std;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    */
    lld n,k,count=0;
    cin>>n>>k;
    while(n>0)
    {
        n=n/k;
        count++;
    }
    cout<<count<<e;
}

Measured memory_bytes: 256
# ARC081C - Make a Rectangle (ABC071C)
from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(
        {k: v for k, v in Counter(lst).items() if v >= 2}.items(), reverse=True
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Measured memory_bytes: 18592
#[allow(unused)]
use std::io::Write;
use std::cmp;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (n, w_limit): (usize, usize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    let mut w: Vec<usize> = Vec::new();
    let mut v: Vec<usize> = Vec::new();
    for _ in 0..n {
        let (w_i, v_i): (usize, usize) = {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_right().to_owned();
            let mut ws = s.split_whitespace();
            let a = ws.next().unwrap().parse().unwrap();
            let b = ws.next().unwrap().parse().unwrap();
            (a, b)
        };
        w.push(w_i);
        v.push(v_i);
    }

    let mut dp = vec![vec![0; w_limit + 1]; n + 1];

    for i in 0..n {
        for j in 0..(w_limit + 1) {
            // i番目を選んだとき
            if j >= w[i] {
                dp[i + 1][j] = cmp::max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            }
            // 選ばなかったとき
            dp[i + 1][j] = cmp::max(dp[i + 1][j], dp[i][j])
        }
    }

    // debugln!("{:?}", dp);

    println!("{}", dp[n][w_limit]);
}


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

int main() {
	int n, x, ans = 1;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		if (ans < x)
			ans *= 2;
		else
			ans += x;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int n,i,j;
scanf("%d",&n);
int a[15][10]={};
for(i=0;i<n;i++){
    int b,f,r,v;
    scanf("%d%d%d%d",&b,&f,&r,&v);
    a[4*(b-1)+f-1][r-1]+=v;
}
for(i=0;i<15;i++){
    for(j=0;j<20;j++){
        if(i%4==3)
        printf("#");
        else if(j%2==0)
        printf(" ");
        else
        printf("%d",a[i][(j-1)/2]);
    }
    printf("\n");
}

return 0;
}

Measured memory_bytes: 2728
#include <iostream>
#include <vector>
#include <cmath>
typedef long long ll;
using namespace std;

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

int main() {
    int n;
    ll x, y;
    cin >> n >> x;
    vector<ll> v;
    for(int i=0; i<n; i++) {
        cin >> y;
        v.push_back(abs(x-y));
    }

    ll ans = v.front();
    for(int i=1; i<n; i++) ans = gcd(ans, v[i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 998244353
#define endl "\n"
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
int32_t main()
{
	fastio();
	int n;
	cin>>n;
	int a[n+1],b[n];
	f(i,0,n+1)
	cin>>a[i];
	f(i,0,n)
	cin>>b[i];
	int ans=0,bk=0;
	f(i,0,n)
	{
		if(a[i]<b[i])
		{
			ans+=a[i];
			int dd=b[i]-a[i];
			if(a[i+1]<=dd)
			{
				ans+=a[i+1];
				a[i+1]=0;
			}
			else
			{
				ans+=dd;
				a[i+1]-=dd;
			}
		}
		else
		{
			ans+=b[i];
			a[i]-=b[i];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
import fractions
from functools import reduce

N, X = map(int, input().split(' '))
city = list(map(int, input().split(' ')))
for i in range(N):
    city[i] = abs(city[i] - X)
    
def gcd(numbers):
    return reduce(fractions.gcd, numbers)

if N == 1:
    ans = city[0]
else:
    ans = gcd(city)

print(ans)

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

int main()
{
	string in,out;
	string sample="ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
	cin>>in;
	
	for(int i=0;i<in.size();i++){
		for(int j=0;j<26;j++){
			if(in[i]==sample[j+3])
				{cout<<sample[j];}
		}
	}
	cout<<endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<'\n'

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll d = c-a-b;
    if(d>0&&d*d>4*a*b)COUT("Yes");
    else COUT("No");
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int main() {
	int n;
	std::cin>>n;
	std::cout<<n+n*n+n*n*n<<std::endl;
	return 0;
}

Measured memory_bytes: 3628
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());

  int64_t result = 0;
  if (N % 2 == 0) {
    int64_t i = 0;
    for (int64_t j = 0; j < (N - 2) / 2; ++j) {
      result -= A[i++] * 2;
    }
    result -= A[i++];
    result += A[i++];
    for (int64_t j = 0; j < (N - 2) / 2; ++j) {
      result += A[i++] * 2;
    }
  } else {
    int64_t result_1 = 0;
    {
      int64_t i = 0;
      for (int64_t j = 0; j < (N - 3) / 2; ++j) {
        result_1 -= A[i++] * 2;
      }
      result_1 -= A[i++];
      result_1 -= A[i++];
      for (int64_t j = 0; j < (N - 1) / 2; ++j) {
        result_1 += A[i++] * 2;
      }
    }

    int64_t result_2 = 0;
    {
      int64_t i = 0;
      for (int64_t j = 0; j < (N - 1) / 2; ++j) {
        result_2 -= A[i++] * 2;
      }
      result_2 += A[i++];
      result_2 += A[i++];
      for (int64_t j = 0; j < (N - 3) / 2; ++j) {
        result_2 += A[i++] * 2;
      }
    }
    result = max(result_1, result_2);
  }

  cout << result << endl;
  return 0;
}


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

#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, h;
  vi v, dp;
  cin >> n >> h;
  v.pb(h);
  dp.pb(1);
  int i = 1;
  int mx = 0;
  while (cin >> h) {
    v.pb(h);
    dp.pb(1+(v[i-1] < h ? 0 : dp[i-1]));
    if (dp[mx] < dp[i]) mx = i;
    i++;
  }
  cout << dp[mx]-1 << ende;
  return 0;
}


Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

  private static int gcd(int a,int b){
      if((a%b)==0) return b;
      return gcd(b,a%b);
    }

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
             int tmp;
             int count = 0;

            for(int i=1;i<a+1;i++){
              for(int j=1;j<a+1;j++){
                tmp = gcd(i,j);
                for(int k=1;k<a+1;k++){
                  count += gcd(k,tmp);
                  }
                }
              }
              System.out.println(count);
            }

          }


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

int dp[105][100005];

signed main() {
	int n, m; cin >> n >> m;
	vector<int> w(n + 1), v(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++) {
		if (j < w[i]) dp[i][j] = dp[i - 1][j];
		else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
	}
	cout << dp[n][m] << '\n';
}

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

int main() {
  string S,T;
  cin >> S >> T;
  int cnt = 0;
  rep(i,3) {
    if(S[i] == T[i]) cnt++;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<climits>
#include<queue>
using namespace std;
#define  INF INT_MAX

struct edge{ int to,cost; };
typedef pair<int,int> P;//firstは最短距離、secondは頂点の番号
vector<edge> G[3003];
int d[3003];

int n,m,k;

int solve(int s){
  int ret=0;
  for(int i=0;i<G[s].size();i++){
    edge e=G[s][i];
    int a=(((e.cost+d[e.to]-d[s])*10/2)+5)/10;//一番長い距離への差を算出
    ret=max(ret,a+d[s]);
    //cout << "最高地..."<<ret << " 謎の値..." <<a << endl;
  }
  return ret;
  
}

void dijkstra(int s){
  // greater<P>を指定することでｆｉｒｓｔが小さい順に取り出せるようにする
  priority_queue<P, vector<P>, greater<P> > que;
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e=G[v][i];
      //cout << "before : basyo:"<< e.to << " cost:" << d[e.to] << endl;
      if(d[e.to] > d[v] + e.cost){
	d[e.to]=d[v] + e.cost;
	que.push(P(d[e.to],e.to));
      }
      //cout << "after  : basyo:"<< e.to << " cost:" << d[e.to] << endl;
    }
  }
  // cout << s << "..."<< d[s] << endl;
}

main(){
  cin >> n >> m >> k;
  for(int i=0;i<m;i++){
    int a,b,l;
    edge bl;
    cin >> a >> b >> bl.cost;
    bl.to=b;
    G[a].push_back(bl);
    bl.to=a;
    G[b].push_back(bl);
  }
  fill(d,d+n+1,INF);
  for(int i=0;i<k;i++){
    int s;
    cin >> s;
    dijkstra(s);
  }
  //  cout << "koko" << endl;
  vector <int> md;
  int mx=0;
  /*for(int i=1;i<=n;i++){
    if(mx==d[i]) md.push_back(i);
    if(mx<d[i]){
      md.clear();
      md.push_back(i);
      mx=d[i];
    }

    //   cout << i << "..." << d[i] << endl;
    }
  int res=0;
  for(int i=0;i<md.size();i++)
    res=max(res,solve(md[i]));
  */
  int res=0;
  for(int i=1;i<=n;i++)
    res=max(res,solve(i));
  cout << res << endl;

  //  cout << q.top() ;
  
}

Measured memory_bytes: 3808
using System;
using System.Linq;
class Program
{
	public static void Main()
	{
		while (true)
		{
			var line = Console.ReadLine().Split(' ');
			var a = int.Parse(line[0]);
			var b = int.Parse(line[1]);
			if (a == 0 && b == 0)
			{
				break;
			}
			for (var i = 0; i < a; i++)
			{
				for (var j = 0; j < b; j++)
				{
					Console.Write("#");
				}
				Console.WriteLine();
			}
			Console.WriteLine();
			
		}
	}
}


Measured memory_bytes: 17740