akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int[] A= new int[N];

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

        long max=0;
        int index=0;
        for (int i=0; i<N; i++) {
            if (A[i]>max) {
            	max=A[i];
            	index=i;
            }
        }
        
        for (int i=0; i<N; i++) {
            if (A[i]>max) {
            	max=A[i];
            }
        }

        for (int i=0; i<N; i++) {
            if (i==index) {
            	long max2=0;
                for (int j=0; j<N; j++) {
                    if (j!=index && max2<A[j]) {
                    	max2=A[j];
                    }
                }
                System.out.println(max2);
            } else {
            	System.out.println(max);
            }
        }

	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 61380
#include <iostream>
#include <iomanip>
#include <map>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    ll n;
    cin >> n;
    map<int,int> mp;
    repi(i, n + 1, 1)
    {
        ll ii = i;
        for (ll j = 2; j * j <= ii; j++)
        {
            while(ii%j==0){
                mp[j]++;
                ii/=j;
            }
        }
        if(ii != 1)mp[ii]++;
    }
    ll ans = 1;
    for(auto itr = mp.begin();itr != mp.end();itr++){
        ans *= itr->second + 1;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if(a > b)
	{
		cout << "a > b" << endl;
		return 0;
	}
	if(a < b)
	{
		cout << "a < b" << endl;
		return 0;
	}
	cout << "a == b" << endl;
	return 0;
}


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

using namespace std;
const long long inf = 1000000000000000000ll;

int n;
struct node {
	int x,y;
	long long p;
}t[20];

long long ans[20];
long long mn[20];

void dfs(int p,int cnt) {
	if (p == n) {
		long long ret = 0;
		for (int i = 0; i < n; i++) ret += mn[i];
		ans[cnt] = min( ans[cnt], ret );
		return ;
	}

	dfs(p + 1, cnt);

	long long tmp[20];

	// x
	for (int i = 0; i < n; i++) tmp[i] = mn[i];
	for (int i = 0; i < n; i++) mn[i] = min( mn[i], abs(t[i].x - t[p].x) * t[i].p );
	dfs(p + 1, cnt + 1);
	for (int i = 0; i < n; i++) mn[i] = tmp[i];

	// y
	for (int i = 0; i < n; i++) tmp[i] = mn[i];
	for (int i = 0; i < n; i++) mn[i] = min( mn[i], abs(t[i].y - t[p].y) * t[i].p );
	dfs(p + 1, cnt + 1);
	for (int i = 0; i < n; i++) mn[i] = tmp[i];
}

int main() {
	scanf("%d",&n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d%lld",&t[i].x,&t[i].y,&t[i].p);
	}
	for (int i = 0; i <= n; i++) ans[i] = inf;
	for (int i = 0; i < n; i++) {
		mn[i] = min(abs(t[i].x), abs(t[i].y)) * t[i].p;
	}
	dfs(0, 0);
	for (int i = 0; i <= n; i++) {
		printf("%lld\n", ans[i]);
	}
	return 0;
}


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

int main() {
    int t;
   // cin>>t;
   t=1;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll a[n+1];
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        ll dp[n+1];
        for(int i=3;i<=n;i++)
        dp[i]=INT_MAX;
        dp[0]=0;
        dp[1]=0;
        dp[2]=abs(a[1]-a[2]);
        for(int i=3;i<=n;i++)
        {
            for(int j=1;j<=k&&j<i;j++)
            {
                //cout<<i<<" ";
                dp[i]=min((dp[i-j]+abs(a[i]-a[i-j])),dp[i]);
               // cout<<dp[i]<<" ";
            }
            //cout<<endl;
        }
        //cout<<n<<" "<<k<<" ";
        
        cout<<dp[n];
    }
}

Measured memory_bytes: 5204
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

A,B = inputIL()

if (B-1) % (A-1) == 0:
  print((B-1)//(A-1))
else:
  print(((B-1)//(A-1))+1)


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

int main()
{
	int N, M;
	double X, Y;
	cin >> N >> M >> X >> Y;

	vector<double>vX(N), vY(M);

	for (vector<double>::iterator it = vX.begin(); it != vX.end(); ++it)
		cin >> *it; sort(vX.begin(), vX.end());
	for (vector<double>::iterator it = vY.begin(); it != vY.end(); ++it) {
		cin >> *it;

	}sort(vY.begin(), vY.end());


	if (vY[0] == X) {
		cout << "War";
		return 0;
	}
	if (vY[0] <= vX[N - 1]) {
		cout << "War";
		return 0;
	}
	if (X > vY[0]||Y<vY[0]) {
		cout << "War";
		return 0;
	}
	cout << "No War";
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
//typedef pair<ll,ll> p; 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll> m;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    ll ans=0;
    
    for(auto it=m.begin();it!=m.end();it++)
    {
        ll p=it->second;
        if(p>=2)
        {
         ans=ans+ p*(p-1)/2;   
        }
        
    }
    //cout<<ans<<" "<<endl;
    for(ll i=0;i<n;i++)
    {
        if(m[a[i]]>=2)
        {
            ll p=m[a[i]];
            ll q=ans - (p*(p-1)/2);
            p=p-1;
            q=q + (p*(p-1)/2);
            
            cout<<q<<endl; 
        }
        else
        {
            cout<<ans<<endl;
        }
    }
  
    
    
    
    
    
}

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

using namespace std;

long cntn(long n,long a,long b){
  return b/n - (a-1)/n;
}

int main() {
  long a,b,c,d;
  cin >> a>>b>>c>>d;
  long ans=0;

  long prod = c*d;
  
  long u = b-a+1;

  ans = u - cntn(c,a,b) - cntn(d,a,b);
    
  long r = d % c;
  while(r!=0){
    d = c;
    c = r;
    r = d % c;
  }

  
  ans += cntn(prod/c,a,b);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

ans = 0
for i in range(1, N + 1):
    n = N // i
    ans += i * n * (n + 1) // 2
print(ans)

Measured memory_bytes: 10364
#include <stdio.h>

int main()
{
  int N, A[100], i, f, a, c = 0, j = 0;

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

  f = 1;
  while(f){
    f = 0;
    for(i = N - 1; i >= j + 1; i--){
      if(A[i] < A [i - 1]){
	a = A[i];
	A[i] = A[i - 1];
	A[i - 1] = a;
	c++;
	f = 1;
      }
    }
    j++;
  }

  for(i = 0; i < N; i++){
    printf("%d", A[i]);
    if(i != N - 1) printf(" ");
  }
  printf("\n%d\n", c);

  return 0;
}

Measured memory_bytes: 604
#include "bits/stdc++.h"
using namespace std;

#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rep1(i,N) for(int i=1;i<=(int)N;++i)

using int64 = long long;
using i64 = long long;

const int inf = 1 << 30;
const i64 inf64 = 1ll << 60;

const int mod = 1e9 + 7;

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
   return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

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

// Doubling
struct LowestCommonAncestor {
   const int LOG;
   const vector<vector<int>>& g;
   int root;
   vector<int> dep;
   vector<vector<int>> table;

   LowestCommonAncestor(const vector<vector<int>>& g, int root = 0) : g(g), dep(g.size()), LOG(0), root(root) {
      int k = 0;
      for (; (1 << k) <= g.size(); ++k) {}
      const_cast<int&>(LOG) = k + 1;
      table.assign(LOG, vector<int>(g.size(), -1));
   }

   void dfs(int u, int par, int d) {
      table[0][u] = par;
      dep[u] = d;
      for (auto& v : g[u]) if (v != par) dfs(v, u, d + 1);
   }

   void build() {
      dfs(root, -1, 0);
      for (int k = 0; k + 1 < LOG; ++k) {
         for (int i = 0; i < g.size(); ++i) {
            if (table[k][i] < 0) table[k + 1][i] = -1;
            else table[k + 1][i] = table[k][table[k][i]];
         }
      }
   }

   int query(int u, int v) {
      if (dep[u] > dep[v]) swap(u, v);
      for (int k = 0; k < LOG; ++k) {
         if ((dep[v] - dep[u]) >> k & 1) v = table[k][v];
      }
      if (u == v) return u;
      for (int i = LOG - 1; i >= 0; --i) {
         if (table[i][u] != table[i][v]) {
            u = table[i][u];
            v = table[i][v];
         }
      }
      return table[0][u];
   }
};

int main() {
   int n; cin >> n;
   vector<vector<int>> g(n);
   rep(i, n) {
      int k; cin >> k;
      rep(j, k) {
         int u; cin >> u;
         g[i].emplace_back(u);
         g[u].emplace_back(i);
      }
   }

   LowestCommonAncestor lca(g);
   lca.build();
   int Q; cin >> Q;
   rep(i, Q) {
      int u, v; cin >> u >> v;
      cout << lca.query(u, v) << endl;
   }
}


Measured memory_bytes: 18652
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
struct Kruskal{

  struct UnionFind{
    Int n;
    vector<Int> r,p;
    UnionFind(){}
    UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    Int find(Int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(Int x,Int y){
      return find(x)==find(y);
    }
    void unite(Int x,Int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };
  
  struct edge{
    Int from,to,cost,used;
    edge(){}
    edge(Int from,Int to,Int cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  Int n;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(Int sz):n(sz){}
  
  void add_edge(Int u,Int v,Int c){
    edges.emplace_back(u,v,c);
  }

  void input(Int m,Int offset=0){
    Int a,b,c;
    for(Int i=0;i<m;i++){
      cin>>a>>b>>c;
      add_edge(a+offset,b+offset,c);
    }
  }
  
  Int build(){
    sort(edges.begin(),edges.end());
    UnionFind uf(n+1);
    Int res=0;
    for(auto &e:edges){
      if(!uf.same(e.from,e.to)){
	res+=e.cost*uf.r[uf.find(e.from)]*uf.r[uf.find(e.to)];
	uf.unite(e.from,e.to);
	e.used=1;
      }
    }
    return res;
  }
};
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  Kruskal G(n);
  G.input(n-1);
  cout<<G.build()<<endl;
  return 0;
}



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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 2 * N;

int n;
int h[N], e[M], ne[M], idx;
int fd[N], sd[N];

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

void dfs(int u, int fa, int d[], int dist)
{
	d[u] = dist;
	for (int i = h[u]; ~i; i = ne[i])
	{
		int j = e[i];
		if (j == fa) continue;
		
		dfs(j, u, d, dist + 1);
	}
}

int main()
{
	memset(h, -1, sizeof h);
	
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i ++ )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		add(a, b), add(b, a);
	}
	
	dfs(1, -1, fd, 0);
	dfs(n, -1, sd, 0);
	
	int f = 0, s = 0;
	for (int i = 1; i <= n; i ++ )
		if (fd[i] <= sd[i]) f ++ ;
		else s ++ ;
	
	if (f >= s + 1) puts("Fennec");
	else puts("Snuke");
	return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

typedef pair<int,int> pint;

template<typename T> class SegmentTree
{
 public:
    using Func=function<T(T,T)>;
    int sz;
    vector<T> data;
    Func func;
    T e;

    SegmentTree(int n,Func func,T e):func(func),e(e){
        sz=1;
        while(sz<n) sz*=2;
        data.assign(2*sz-1,e);
    }
    void update(int k,int x){
        k+=sz-1; data[k]=x;
        while(k>0){
            k=(k-1)/2;
            data[k]=func(data[2*k+1],data[2*k+2]);
        }
    }
    T get(int l,int r){
        // [l,r)
        T resL=e,resR=e;
        for(l+=sz-1,r+=sz-1;l<r;l/=2,r/=2){
            if((l&1)==0) resL=func(resL,data[l]);
            if((r&1)==0) resR=func(resR,data[--r]); 
        }
        return func(resL,resR);
    }
    T operator[](int k){ return data[k+sz-1]; }
};

const int INF=1e18;

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

    int N,M; cin>>N>>M;
    vector<int> l(M),r(M),c(M);
    for(int i=0;i<M;i++) cin>>l[i]>>r[i]>>c[i];

    vector<pair<pint,int>> v;
    for(int i=0;i<M;i++){
        v.push_back({{r[i],l[i]},c[i]});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<M;i++){
        r[i]=v[i].first.first;
        l[i]=v[i].first.second;
        c[i]=v[i].second;
        // cout<<l[i]<<' '<<r[i]<<' '<<c[i]<<endl;
    }

    SegmentTree<int> seg(N+1,[](int a,int b){return min(a,b);},INF);
    seg.update(1,0);
    for(int i=0;i<M;i++){
        int mn=seg.get(l[i],r[i]+1);
        if(mn!=INF) seg.update(r[i],min(seg[r[i]],mn+c[i]));
        // for(int i=1;i<=N;i++) cout<<(seg[i]==INF? -1:seg[i])<<' '; cout<<endl;
    }
    cout<<(seg[N]==INF? -1:seg[N])<<endl;
    return 0;
}

Measured memory_bytes: 7408
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = null;
		List<String> list = new ArrayList<String>();
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				String str = stdIn.next();
				StringBuilder ans = new StringBuilder();
				for(int i = 0; i < str.length(); i++){
					if( str.charAt(i) == '@' ){
						int x = Integer.parseInt(Character.toString(str.charAt(i+1)));
						while( x-- > 0 ){
							ans.append(Character.toString(str.charAt(i+2)));
						}
						i += 2;
					} else {
						ans.append(Character.toString(str.charAt(i)));
					}
				}
				list.add(ans.toString());
			}
			
			for(String s : list){
				System.out.println(s);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 11000
#include <stdio.h>

int a[105];
int ans[10005];

int main() {

	int temp;

	int K, T;

	scanf("%d %d",&K,&T);

	temp = K;

	int i, j;

	for (i = 0; i < T; i++) {
		scanf(" %d",&a[i]);
	}

	int idx = -1;
	int ma = -1;
	j = -1;
	while (1) {
		if (K == 0) { break; }
		idx = -1;
		ma = 0;
		for (i = 0; i < T; i++) {
			if (ma < a[i] && (j == -1 || ans[j] != i+1)) {
				ma = a[i];
				idx = i;
			}
		}
		j++;
		if (idx == -1) { 
			ans[j] = ans[j - 1]; 
		}
		else {
			ans[j] = idx + 1;
		}
		a[ans[j] - 1]--;
		K--;
	}
	int answer = 0;
	for (i = 0; i < temp - 1; i++) {
		if (ans[i] == ans[i + 1]) { answer++; }
	}
	printf("%d\n",answer);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Online
#define nowtime (double)clock()/CLOCKS_PER_SEC
void tie()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
}
int main()
{
	tie();
	#ifndef Online
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int x;
	cin>>x; 
	cout<<!x<<endl;
	#ifndef Online
	fclose(stdin);
	fclose(stdout);
	#endif
	return 0;
}


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

using namespace std;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<long long> h(n), cost(n, INF);
    cost[0] = 0;
    for (auto &_h : h) cin >> _h;
    for (int i = 0; i < n; ++i) {
        for (int j = min(k, i); j > 0; --j) {
            chmin(cost[i], cost[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << cost[n - 1] << endl;
}

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

#include<algorithm>
#define str(a) to_string(a)
#define int long long
#define pb push_back
#define N 1000001

vector<int> adj[N];
unordered_map<int, int> outdegree;
vector<int> dp;

int LongestPath(int source) {
	if (outdegree[source] == 0) {
		return dp[source] = 0;
	}
	if (dp[source] != -1)
		return dp[source];
	int mx = INT_MIN;
	for (int neighbor : adj[source]) {
		mx = max(mx, LongestPath(neighbor));
	}
	dp[source] = 1 + mx;
	return dp[source];
}

int32_t main()
{
// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n, m; cin >> n >> m;
	dp.assign(n + 1, -1);

	while (m--) {
		int x, y; cin >> x >> y;
		adj[x].pb(y);		// Directed acyclic graph
		outdegree[x]++;
	}

	for (int i = 1; i <= n; i++) {
		if (outdegree.find(i) == outdegree.end())
			outdegree[i] = 0;
	}

	int ans = INT_MIN;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, LongestPath(i));
	}
	cout << ans << endl;


}









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

int main() {
  int n; std::cin >> n;
  std::vector<std::string> a(n);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  // int n = 5;
  // std::vector<std::string> a{"7.5", "2.4", "17.000000001", "17", "16.000000000"};

  /* ピリオドをすべての文字列に加える */
  for (int i = 0; i < n; i++)
    if (a[i].find('.') == std::string::npos) // ピリオドの有無
      a[i].push_back('.');                   // ピリオドを末尾に加える
  
  /* key:val = (c2, c5):cnt */
  std::map<std::pair<int, int>, int> p;

  /* aの素因数2と5の数を数える */
  for (int i = 0; i < n; i++) {
    // a[i].length() => 文字列の長さ
    // a[i].find('.') => .(ピリオド)が存在すればその位置, なければstd::string::npos

    // std::cout << a[i] << " " <<  a[i].length() - a[i].find('.') - 1 << std::endl;
    /* 小数点以下の数 */
    int d_cnt = a[i].length() - a[i].find('.') - 1;
    int c2 = -d_cnt; // 2の数を-d_cntで初期化
    int c5 = -d_cnt; // 5の数を-d_cntで初期化
    
    /* 文字を数字に変換 */
    a[i].replace(a[i].find('.'), 1, ""); // .(ピリオド)を削除 str.replace(開始位置, 長さ, 置き換え後の新たな文字列)
    long long a_ll = std::stoll(a[i].c_str()); // long longに変換
    
    /* 2の数を取得 */
    while (a_ll%2 == 0) {
      ++c2;
      a_ll /= 2;
    }
    /* 5の数を取得 */
    while (a_ll%5 == 0) {
      ++c5;
      a_ll /= 5;
    }

    /* mapに key:val = (c2, c5):数 保持 */
    p[std::pair<int, int>(c2, c5)]++; // keyが存在しない場合は0が追加される
  }

  /* チェック */
  // for (auto itr = p.begin(); itr != p.end(); ++itr)
  //   // std::cout << "(" << (*itr).first.first << ", " << (*itr).first.second << ")" 
  //   //           <<  " " << (*itr).second << std::endl;
  //   std::cout << "(" << itr->first.first << ", " << itr->first.second << ")" 
  //             <<  " " << (*itr).second << std::endl;
  
  long long cnt = 0;
  for (auto itr_1 = p.begin(); itr_1 != p.end(); ++itr_1) {
    int c2_1 = itr_1->first.first;
    int c5_1 = itr_1->first.second;
    int cnt_1 = itr_1->second;

    if (c2_1 >= 0 && c5_1 >= 0)
      cnt += (long long)cnt_1 * (cnt_1-1)/2;

    // if (itr_1->first.first >= 0 && itr_1->first.second >= 0)
    //   cnt += itr_1->second*(itr_1->second-1)/2;

    for (auto itr_2 = std::next(itr_1, 1); itr_2 != p.end(); ++itr_2) {
    int c2_2 = itr_2->first.first;
    int c5_2 = itr_2->first.second;
    int cnt_2 = itr_2->second;
      if (c2_1 + c2_2 >= 0 && c5_1 + c5_2 >= 0)
        cnt += (long long)cnt_1 * cnt_2;
      // if (itr_1->first.first + itr_2->first.first >= 0 && itr_1->first.second + itr_2->first.second >= 0)
      //   cnt += itr_1->second * itr_2->second;
    }

  }
  std::cout << cnt << std::endl;


  return 0;
}

Measured memory_bytes: 9572
#include <bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long n = 0;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int i;
      cin >> i;
      cout << ((n >> i) & 1LL) << endl;
    }
    if (t == 1){
      int i;
      cin >> i;
      n |= (1LL << i);
    }
    if (t == 2){
      int i;
      cin >> i;
      n &= ~(1LL << i);
    }
    if (t == 3){
      int i;
      cin >> i;
      n ^= (1LL << i);
    }
    if (t == 4){
      cout << (~n == 0) << endl;
    }
    if (t == 5){
      cout << !(n == 0) << endl;
    }
    if (t == 6){
      cout << (n == 0) << endl;
    }
    if (t == 7){
      cout << __builtin_popcountll(n) << endl;
    }
    if (t == 8){
      cout << n << endl;
    }
  }
}


Measured memory_bytes: 3104
import sys
input = sys.stdin.readline
import math


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    k, a, b = input_list()
    # 交換レートが同じなら叩き続けたほうがいい 交換には手数２回消費つまりA + 3 <= B
    if b-a <= 2:
        print(k+1)
    else:
        bis = a
        k -= a-1
        if k % 2 == 1:
            bis += 1
            k -= 1
        bis += (b-a)*(k//2)
        print(bis)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 62124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll N;
    cin >> N;
    ll L;
    cin >> L;
    ll sum=0;
    for(ll i=0;i<N;i++){
        sum+=L+i;
    ;}
    if(L>=0){
        cout<<sum-L<<endl;
    }
    else if(L+N-1<=0){
        cout<<sum-(L+N-1)<<endl;
    }
    else cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	ll n, k; cin >> n >> k;
	vector<int> hash(n);
	for(auto &x : hash)
		cin >> x;
	vector<int> s;
	vector<int> ord(n+1,-1);
	int c = 1,l=0;
	{
		int v = 1;
		while(ord[v] == -1){
			ord[v] = (int)s.size();
			s.push_back(v);
			v = hash[v-1];
		}
		c = (int)s.size() - ord[v];
		l = ord[v];
	}
	if(k < l){
		cout<<s[k]<<"\n";
	}
	else{
		k-=l;
		k%=c;
		cout<<s[l+k]<<"\n";
	}
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 5788
using System;

namespace _174_c
{
    internal class Repsept
    {
        private static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

            long seven = 7;
            for (var i = 0; i <= 1000000; i++)
            {
                var remainder = seven % k;
                if (remainder == 0)
                {
                    Console.WriteLine(i + 1);
                    return;
                }

                seven = remainder * 10 + 7;
            }

            Console.WriteLine(-1);
        }
    }
}

Measured memory_bytes: 27512
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a = b = 0
for i, list_ in enumerate(list(itertools.permutations([i for i in range(1, n + 1)]))):
    if tuple(p) == list_:
        a = i + 1
    if tuple(q) == list_:
        b = i + 1
print(abs(a - b))


Measured memory_bytes: 13732
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if((a*100 + b*10 + c) % 4 == 0)
        cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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() {
  int a,b;
  cin >> a >> b;
  if (a>b) cout << a-b << endl;
  else cout << 0 << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


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

  vector<int> a(n,-1);

  REP(i,m){
    int s,c;
    cin >> s >> c;
    s--;
    if(a[s]==-1){
      a[s]=c;
    }else if(a[s] != c){
      cout << -1 << endl;
      exit(0);
    }
  }

  if(n !=1 && a[0]==0){
    cout << -1 << endl;
    exit(0);
  }else if(n !=1 && a[0]==-1){
    a[0]=1;
  }

  int ans = 0;
  REP(i,n){
    ans *= 10;
    if(a[i]==-1){      
    }else{
      ans += a[i];
    }
  }

  cout << ans << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
 
ll a[110000];
ll b[110000];
int main(){
    ll n,k,ans=1e11;;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    rep(i,0,101){
        ll tmp=0;
        rep(j,0,n)tmp+=(i-a[j])*(i-a[j]);
        ans=min(ans,tmp);
    }
    cout<<ans;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

const int Z = 1e9+7;

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

    int n;
    cin >> n;
    int c[n];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(c, c+n);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + 1ll * (n + 1 - i) * c[i]) % Z;
    }

    for (int i = 0; i < n - 1; i++) {
        ans = 4ll * ans % Z;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long int
float distance(int x1, int y1, int x2, int y2) 
{ 
    // Calculating distance 
    return sqrt(pow(x2 - x1, 2) +  
                pow(y2 - y1, 2) * 1.0); 
} 
int factorial(int n) 
{ 
    // single line to find factorial 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
}

signed main()
{
	int n;
	cin>>n;
	cout<<n*n;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   string s;cin>>s;
   int n = s.size();
   set<char>set;
   rep(i,n)set.insert(s[i]);
   cout<<(set.size()==n?"yes":"no");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long x,s,ans;
map<long long,int> mp;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	mp[0]=1;
	for(int i=0;i<n;i++){
		cin>>x;
		ans+=mp[s+=x];
		mp[s]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


int main(){
    int N,K;
    cin >> N >> K;
    string s;
    cin >> s;

    vector<int> Nums;
    int now = 1; //今見ている数
    int cnt = 0; //nowがいくつ並んでいるか
    for(int i = 0; i < N; i++){
        if(s[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now; //0と1を切り替える時の計算
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);

    //1-0-1-0-1-0って感じの配列が欲しい
    //1-0-1-0みたいに0で終わってたら、適当に１つ足す
    if(Nums.size() % 2 == 0) Nums.push_back(0);


    int Add = 2 * K + 1;

    int ans = 0;

    //1-0-1の1から始めるので、偶数番目だけ見る
    for(int i = 0; i < Nums.size(); i += 2){
        int tmp = 0;

        int left = i;
        int right = min(i + Add, (int)Nums.size());
        for(int j = left; j < right; j++){
            tmp += Nums[j];
        }
        ans = max(tmp,ans);
    }



    cout << ans << endl;
}



Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

#define PRINT_VECTOR_MAX 100
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)min(v.size(),PRINT_VECTOR_MAX); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)min(v.size(),PRINT_VECTOR_MAX); i++) {for (ll j = 0; j < (ll)min(v[i].size(),PRINT_VECTOR_MAX); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();
int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

void Main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	cout << max(0,min(b,d) - max(a,c)) << endl;
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    const string t = "CODEFESTIVAL2016";
    int n = t.size();

    string s;
    cin >> s;
    int ans = 0;
    for(int i=0; i<n; ++i){
        if(s[i] != t[i])
            ++ ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll a,b;cin >> a >> b;
	
	if(abs(a-b) > 1)cout << "Alice" << endl;
	else cout << "Brown" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.lang.Math.pow

fun main(args: Array<String>) {
    abc105c()
}

/*
    2^n   0  1 2  3  4   5  6
    val 0 1 -2 4 -8 16 -32 64
    sum 0 1 -1 3 -5 11 -21 43
 */
fun abc105c() {
    val n = readLine()!!.toInt()

    if (n == 0) return println("0")

    var value = 0L
    val answer = StringBuilder()
    var i = 0
    while (value != n.toLong()) {
        val pow = pow((-2).toDouble(), (i + 1).toDouble()).toLong()
        if ((n - value) % pow != 0L) {
            answer.append("1")
            value += pow((-2).toDouble(), i.toDouble()).toLong()
        } else {
            answer.append("0")
        }
        i++
    }

    println(answer.reverse().toString())
}


Measured memory_bytes: 31784
s = input()
if s[0] == "A" and s[2:-1].count("C")==1:
    c = s[2:-1].index('C')
    if (s[1]+s[2:c+2]+s[c+3:]).islower():
        print('AC')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 61864
A, B = map(int, input().split())

result = ''
if (A == 1 and B != 1):
  result = 'Alice'
elif (B == 1 and A != 1):
  result = 'Bob'
elif (A > B):
  result = 'Alice'
elif (B > A):
  result = 'Bob'
elif (B == A):
  result = 'Draw'

print(result)


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



int main() 
{
  ll H,W;
  cin >> H >> W;
  vector<string> str(H);
  string queue;
  rep(i,W)
  {
    queue += "a";
  }
  rep(i,H)
  {
    rep(j,W)
    {
      cin >> queue.at(j);
    }
    str.at(i) = queue;
  }
  rep (i,W + 2)
  {
    cout << '#';
  }
  cout << endl;
  rep (i,H)
  {
    cout << '#' << str.at(i)  << '#' << endl;
  }
  rep (i,W + 2)
  {
    cout << '#';
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;

  cin >> N >> A >> B;

  int plan1 = A * N;
  int plan2 = B;

  if (plan1 <= plan2) {
    cout << plan1 << endl;
  } else {
    cout << plan2 << endl;
  }
}

Measured memory_bytes: 3572
#include<stdio.h>
char a[28] = {"abcdefghijklmnopqrstuvwxyz"};
char b[27] = {};
char c[100] = {};
int i, j;
int d;

int main(){
	scanf("%s", c);
	for (i = 0; i < 100; i++){
		for (j = 0; j < 28; j++){
			if (c[i] == a[j]){
				b[j]++;
			}
		}
		}
	for (i = 0; i < 27; i++){
		if (b[i] % 2 == 0||b[i]%2==2){
			d++;
		}
		else{
		}
	}
	if (d == 27){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;


int root(int n) {
    int res = 0;
    while(res * res * res * res * res <= n) res ++;
    return res - 1;
}
int five(int x) {
    return (x * x * x * x * x);
}
void solve(int z) {
    int x;
    cin >> x;
    int a = 0 , b = 0 ;
    for(int i = 0 ; i < 1000 ; i ++) {
        int m = x + five(i);
        int n = x - five(i);
        int temp = root(m);
        int tempn = root(n);
        if(five(temp) == m) {
            a = temp;
            b = i;
            break;
        }
        else if(five(tempn) == n) {
            a = tempn;
            b = -i;
            break;
        }
    }
    cout << a << ' ' << b;
}

/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    
    return 0;
}
 



Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int R;
    cin >> R;
    cout << 3 * R * R << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, ab, ac, ad, ae, af, ag, ah, ai, aj;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	cin >> f;
	cin >> g;
	cin >> h;
	cin >> i;
	cin >> j;
	cin >> k;
	cin >> l;
	cin >> m;
	cin >> n;
	cin >> o;
	cin >> p;
	cin >> q;
	cin >> r;
	s = a * 3600 + b * 60 + c;
	t = d * 3600 + e * 60 + f;
	u = g * 3600 + h * 60 + i;
	v = j * 3600 + k * 60 + l;
	w = m * 3600 + n * 60 + o;
	x = p * 3600 + q * 60 + r;
	y = t - s;
	z = v - u;
	aa = x - w;
	ab = y / 3600;
	ac = (y % 3600) / 60;
	ad = (y % 3600) % 60;
	ae = z / 3600;
	af = (z % 3600) / 60;
	ag = (z % 3600) % 60;
	ah = aa / 3600;
	ai = (aa % 3600) / 60;
	aj = (aa % 3600) % 60;
	cout << ab << " " << ac << " " << ad << endl;
	cout << ae << " " << af << " " << ag << endl;
	cout << ah << " " << ai << " " << aj << endl;
	return 0;
}

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

typedef long long ll;
string s;
int n;


bool solve(){
	cin >> n;
	if(n == 0){
		return false;
	}
	int flag = 0;
	int a =0, b= 0;
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> s;
		if(s == "lu"){
			a = 1;
		}else if(s == "ru"){
			b = 1;
		}else if(s == "ld"){
			a = 0;
		}else{
			b = 0;
		}
		if(!flag && a == 1 && b == 1){
			ans++;
			flag = 1;
		}else if(flag && a == 0 && b == 0){
			ans++;
			flag = 0;
		}
	}
	cout << ans << endl;
	return true;
}



int main(){
	while(solve());
}


Measured memory_bytes: 3144
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        x: usize,
        a: [(i32, [usize; m]); n],
    }
    // annotate for rust-analyzer
    let n: usize = n;
    let m: usize = m;
    let x: usize = x;
    let a: Vec<(i32, Vec<usize>)> = a;

    let mut ans = -1;
    for ib in 0..(1 << n) {
        let mut tmp = vec![0usize; m];
        let mut sum = 0;
        for i in 0..n {
            if ib >> i & 1 == 1 {
                for j in 0..m {
                    tmp[j] += (a[i].1)[j];
                }
                sum += a[i].0;
            }
        }
        if tmp.iter().all(|&f| f >= x) && (ans == -1 || ans > sum) {
            ans = sum;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for(int i = 0; i < n; i++) cin >> x[i];
    for(int i = 0; i < m; i++) cin >> y[i];
    ll sumx, sumy;
    sumx = sumy = 0;
    for(int i = 0; i < n; i++) {
        sumx += i * x[i] - (n-1-i) * x[i];
        sumx %= MOD;
    }
    for(int i = 0; i < m; i++) {
        sumy += i * y[i] - (m-1-i) * y[i];
        sumy %= MOD;
    }
    ll ans = sumx * sumy % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin>>a;
  vector<char> s(a.size());
  for(int i=0;i<a.size();i++){
    s[i]=a[i];
  }
  map<char,int>cnt;
  for(char x:s){
    if(cnt.count(x))cnt.at(x)++;
    else cnt[x]=1;
  }
  if(cnt.size()==a.size())cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 256
def solve(A, B, C):
    cur = "a"
    A = list(A)
    B = list(B)
    C = list(C)
    A.reverse()
    B.reverse()
    C.reverse()
    while True:
        if cur == "a":
            temp = A
        elif cur == "b":
            temp = B
        else:
            temp = C
        if not temp:
            print(cur.upper())
            break
        else:
            cur = temp.pop()



a = input()
b = input()
c = input()
solve(a, b, c)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	string S;
	cin >> S;
	int zero = 0;
	int one = 0;
	for(int i=0; i<S.size(); i++){
		if(S[i] == '0') zero++;
		else one++;
	}
	cout << min(zero,one)*2 << endl;

	return 0;
}


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

const int INF = 1e9L + 5;

int main()
{
  int n, k;
  scanf("%d%dd", &n, &k);
  vector<int> a(n);
  for(int& i : a)
  {
    scanf("%d", &i);
  }
  vector<int> dp(n, INF);
  dp[0] = 0;
  for(int i = 1; i < n; i++)
  {
    for(int j = i - 1, cnt = 0; j >= 0 and cnt < k; j--, cnt++)
    {
      dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    }
  }
  cout << dp[n - 1];
  
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] R = new Integer[n];
		for(int i=0;i<n;i++) {
			R[i] = in.nextInt();
		}

		long maxv = -10000000000L;//R[j] - R[i]の最大値
		long minv = R[0];//以前のR[j]の最小値

		for(int j=1;j<n;j++) {
			maxv = Math.max(maxv,R[j]-minv);
			minv = Math.min(minv, R[j]);
		}
		System.out.println(maxv);
	}
}



Measured memory_bytes: 105348
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    SP = ii2ss(N)
    D = []
    for i, sp in enumerate(SP):
        s, p = sp.split(' ')
        p = int(p)
        D.append((i+1, s, p))
    D.sort(key=lambda v: v[2])
    D.reverse()
    D.sort(key=lambda v: v[1])
    for i, s, p in D:
        print(i)

main()


Measured memory_bytes: 38384
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

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

    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val s = a.distinct()
    if (s.size == n) println("YES")
    else println("NO")
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 63176