akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cctype>
#include <utility>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	int a {1};
	for (int n {in()}; n; n--) {
		int b {in()};
		a *= b / __gcd(a, b);
	}
	outl(a);
}


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

int main() {

    int n;

    cin >> n;

    vector<long long int> v(3*n),reverse_v(3*n);

    for(int i=0; i<3*n; i++){
        cin >> v[i];
        reverse_v[3*n-1-i] = v[i];
    }

    priority_queue<long long int> left_q,right_q;

    vector<long long int> _left,_right;

    long long int left_num = 0,right_num = 0;

    for(int i=0; i<n; i++){
        left_q.push(-v[i]);
        left_num += v[i];
        right_q.push(reverse_v[i]);
        right_num += reverse_v[i];
    }

    _left.push_back(left_num);
    _right.push_back(right_num);

    for(int i=n; i< 2*n; i++){
        left_q.push(-v[i]);
        left_num += v[i];
        left_num += left_q.top();
        left_q.pop();
        _left.push_back(left_num);

        right_q.push(reverse_v[i]);
        right_num += reverse_v[i];
        right_num -= right_q.top();
        right_q.pop();
        _right.push_back(right_num);
    }

    long long int ans = -static_cast<long long int>(1e20);

    vector<long long int>::iterator left_itr = _left.begin();
    vector<long long int>::iterator right_itr = _right.end();

    right_itr--;

    while(1){

        ans = max(ans,*left_itr - *right_itr);
        if(right_itr == _right.begin()){
            break;
        }
        left_itr++;
        right_itr--;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8940
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int n;
    cin>>n;
    int k = (n % 1000 == 0 ? 0 : 1000*(n/1000 + 1) - n);

    cout << k << endl;
}

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

int main() {
    string x;

    while (true) {
        
        cin >> x;
        if (x == "0")
            break;
        
        int ans = 0;
        for(auto c : x) {
            ans += c - '0';
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3156
import Control.Monad
import Data.List

pattern :: Int -> [[Int]]
pattern n
  | even n = let h = div n 2 in [replicate (h-1) (-2) ++ [-1, 1] ++ replicate (h-1) 2]
  | odd n = let h = div n 2 in [replicate (h-1) (-2) ++ [-1, -1] ++ replicate h 2, replicate h (-2) ++ [1, 1] ++ replicate (h-1) 2]

f n cs = maximum $ map (sum . zipWith (*) cs) (pattern n)

main = readLn >>= \n -> replicateM n readLn >>= print . f n . sort 

Measured memory_bytes: 60924
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

s = S()

if s[-1]=='s':
    print(s+'es')
else:
    print(s+'s')

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

const ll logx=30;
const ll N=4e5+5;
const ll M=3e5+5;
const ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll dp[N][27];

int main()
{
  ll n;
  cin>>n;
  ll a[n],mini=INF;
  for(ll i=0;i<n;i++){cin>>a[i];}
  for(ll i=-105;i<=105;i++)
  {
    ll sum=0;
    for(ll j=0;j<n;j++)
    {
      sum+=((a[j]-i)*(a[j]-i));
    }
    mini=min(mini,sum);
  }
  cout<<mini<<endl;
}


Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	
	static int n, m, a;
	static int[] h, p, q;
	
	public static void main(String[] args)
	{
		
		Scanner sca = new Scanner(System.in);
		int i, j, k;
		
		while(true)
		{
			n = sca.nextInt();
			m = sca.nextInt();
			a = sca.nextInt();
			if(n == 0) break;
			
			h = new int[m];
			p = new int[m];
			q = new int[m];
			for(i = 0;i < m;i++)
			{
				h[i] = sca.nextInt();
				p[i] = sca.nextInt();
				q[i] = sca.nextInt();
			}
			
			// hでソート
			for(i = m;i > 0;i--)
			{
				for(j = 0; j < (i - 1);j++)
				{
					if(h[j] < h[j + 1])
					{
						int tmp;
						tmp = h[j];    h[j] = h[j + 1];    h[j + 1] = tmp;
						tmp = p[j];    p[j] = p[j + 1];    p[j + 1] = tmp;
						tmp = q[j];    q[j] = q[j + 1];    q[j + 1] = tmp;
					}
				}
			}
			
			for(i = 0;i < m;i++)
			{
				if(a == p[i])
					a = q[i];
				else if(a == q[i])
					a = p[i];
			}
			
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 62624
require 'prime'

# util functions
def gcd(arr) # arr: Array of non-negative integers
  if arr.size < 2
    raise "array (#{arr}) size is less than 2."
  end
  
  def gcd_two(a, b) # assume b <= a
    return a if b % a == 0
    return gcd_two(b % a, a)
  end

  g = arr[0]
  for i in 1..arr.size - 1 do
    g = gcd_two([g, arr[i]].min, [g, arr[i]].max)
  end
  return g
end


# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

str = inputs[0][0]

def rec(str)
  return [str] if str.length == 1

  ret = []
  recres = rec(str[1..-1])
  recres.each do |substr|
    ret << (str[0] + "+" + substr)
    ret << (str[0] + substr)
  end
 
  return ret
end

ans = 0
recres = rec(str)
pd recres
recres.each do |a_i|
  ans += eval a_i
end

puts ans


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

int main() {
	
	int n;
	cin >> n;
	
	if(n < 357){
		puts("0");
		return 0;
	}
	
	int ans = 0;
	
	for(int i = 357; i <= n; i += 2){
		int temp = i;
		bool while_flag = true;
		bool count3 = false;
		bool count5 = false;
		bool count7 = false;
		switch(temp % 100){
			case 33:
				count3 = true;
				break;
			case 35:
				count3 = true;
				count5 = true;
				break;
			case 37:
				count3 = true;
				count7 = true;
				break;
			case 53:
				count5 = true;
				count3 = true;
				break;
			case 55:
				count5 = true;
				break;
			case 57:
				count5 = true;
				count7 = true;
				break;
			case 73:
				count7 = true;
				count3 = true;
				break;
			case 75:
				count7 = true;
				count5 = true;
				break;
			case 77:
				count7 = true;
				break;
			default:
				while_flag = false;
				break;
		}
		temp /= 100;
		while(temp && while_flag){
			switch(temp % 10){
				case 3:
					count3 = true;
					break;
				case 5:
					count5 = true;
					break;
				case 7:
					count7 = true;
					break;
				default:
					while_flag = false;
					break;
			}
			if(!while_flag) break;
			temp /= 10;
		}
		if(while_flag && count3 && count5 && count7){
			// cout << i << endl;
			ans++;
		}
		if(i % 10 == 7){
			i += 4;
		}
		if(i > 800000000){
			ans = 26484;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  
  if(1 <= A && A <= 9 && 1 <= B && B <= 9){
    cout << A*B << endl;
  }
  else {
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 256
n,W=map(int,input().split())
w_list=[0]
v_list=[0]
for i in range(n):
    w,v=map(int,input().split())
    w_list.append(w)
    v_list.append(v)
dp=[]
for i in range(n+1):
    sub_list=[]
    for j in range(100001):
        sub_list.append(0)
    dp.append(sub_list)
for j in range(100001):
    if j==0:
        dp[0][0]=0
    else:
        dp[0][j]=10**10
for i in range(1,n+1):
    for j in range(100001):
        if v_list[i]<=j:
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-v_list[i]]+w_list[i])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i-1][0]+w_list[i])
Max=0
for j in range(100001):
    if dp[n][j]<=W:
        if Max<=j:
            Max=j
print(Max)



Measured memory_bytes: 140876
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> cnt;
    REP(i, N) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    sort(A.begin(), A.end(), greater<int>());

    vector<int> two(31);
    two[0] = 2;
    FOR(i, 1, 30) two[i] = two[i - 1] * 2;

    int ans = 0;
    REV(i, 30, 0) {
        int t = two[i];
        REP(j, A.size()) {
            int a = A[j];
            if (a > t) continue;
            if (a != t - a) {
                if (cnt[a] > 0 && cnt[t - a] > 0) {
                    cnt[a]--;
                    cnt[t - a]--;
                    ans++;
                }
            } else {
                if (cnt[a] >= 2) {
                    cnt[a] -= 2;
                    ans++;
                }
            }
        }
    }

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


Measured memory_bytes: 52736
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;
int main(){
    int a,b,c;
    string ans="NO";
    cin >> a >> b >> c;
    for(int i=1;i<=b;i++){
        if((a*i)%b==c){
            ans = "YES";
        }
    }
    cout << ans <<endl;
}

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

int main() {
  int n, c = 0;
  string s;
  cin >> n >> s;
  for(int i = 0; i < n - 2; i++) {
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      c++;
    }
  }
  cout << c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int n,m;
int h[200000];
int ans=0;
vector<int>vec[200000];
signed main(){
    cin>>n>>m;
    rep(i,n)cin>>h[i+1];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    rep(i,n){
        int l=vec[i+1].size();
        bool gt=true;
        rep(j,l){
            if(h[i+1]<=h[vec[i+1][j]])gt=false;
        }
        if(gt){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 12608
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
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 (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n;
std::cin >> n;
std::multiset<int> a;
for(int i = 0; i < n; i++){
    int temp;
    std::cin >> temp;
    a.insert(temp);
}


int out = 0;
int flag = 0;
while(!a.empty()){
    auto itr = std::next(a.end(), - 1);
    int now = 1;
    while(now <= *itr){
        now = now << 1;
    }
    int anum = *itr;
    a.erase(itr);
    auto check = a.find(now - anum);
    if(check != a.end()){
        out++;
        a.erase(check);
    }
}

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

Measured memory_bytes: 9600
n,m,l = gets.split().map(&:to_i)

a = Array.new()
b = Array.new()

n.times do |i|
  a[i] = gets.split().map(&:to_i)
end

m.times do |j|
  b[j] = gets.split().map(&:to_i)
end

c = Array.new()
n.times do |x|
  c[x] = Array.new(1)
  l.times do |y|
    c[x][y] = 0
    m.times do |z|
      c[x][y] += a[x][z] * b[z][y]
    end
  end
end

c.each do |answer|
  puts answer.join(" ")
end



Measured memory_bytes: 8868
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, k;
  cin >> n >> k;

  llong res = 0;
  REP(i,n){
    if(i == 0){
      res += k;
    }else{
      res *= k - 1;
    }
  }

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



Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	const LL INF = 1LL << 60;

	int n, m;
	scanf("%d%d", &n, &m);
	VV(pll) G(n), rG(n);
	for(int i = 0; i < m; ++i){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		--a;
		--b;
		G[a].emplace_back(b, c);
		rG[b].emplace_back(a, c);
	}
	
	vector<char> reachable(n);
	queue<int> q;
	q.push(n - 1);
	reachable[n - 1] = 1;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(cauto p : rG[u]){
			int v = p.first;
			if(!reachable[v]){
				reachable[v] = 1;
				q.push(v);
			}
		}
	}

	vector<LL> scr(n, -INF);
	scr[0] = 0;
	bool updated = true;
	for(int z = 0; z < n + 5; ++z){
		updated = false;
		for(int i = 0; i < n; ++i){
			if(scr[i] == -INF){ continue; }
			for(cauto p : G[i]){
				int v = p.first;
				LL c = scr[i] + p.second;
				if(scr[v] < c){
					scr[v] = c;
					updated |= reachable[v];
				}
			}
		}
	}
	
	if(updated){ puts("inf"); }
	else{ printf("%lld\n", scr.back()); }
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	ll N, M;
	cin >> N >> M;
	ll res = -1;

	for(ll i=1;i< min(ll(sqrt(M))+2, M+1);i++){
		if(M%i==0){
			ll j = M/i;
			if(i >= N){
				res = max(res, j);
			}
			if(j >= N){
				res = max(res, i);
			}
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    int h, w, a, b;
    scanf("%d %d %d %d", &h, &w, &a, &b);
    rep (i, b) {
        rep (j, a) {
            printf("%d", 0);
        }
        rep (j, w-a) {
            printf("%d", 1);
        }
        printf("\n");
    }
    rep (i, h-b) {
        rep (j, a) {
            printf("%d", 1);
        }
        rep (j, w-a) {
            printf("%d", 0);
        }
        printf("\n");
    }
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>H(N);

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

	int MAXHeight = -1;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (MAXHeight <= H[i]) {
			cnt++;
			MAXHeight = H[i];
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int ac [3][100005];
int fel [3][100005];

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>ac[0][i]>>ac[1][i]>>ac[2][i];
    }
    memset(fel, 0, sizeof(fel));
    for(int i=0; i<3; i++){
        fel[i][0] = ac[i][0];
    }
    
    for(int i =1; i<n; i++){
        for(int j =0; j<3; j++){
            for(int k=0; k<3; k++){
                if(k!=j){
                    fel[j][i] = max(fel[j][i], ac[j][i]+fel[k][i-1]);
                }
            }
        }
    }
    cout<<max(fel[0][n-1], max(fel[1][n-1],fel[2][n-1]))<<"\n";
    
    
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
    int N,A;
    cin>>N>>A;
    if((N%500)<=A)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
}

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

int main()
{
    ll n,w,i,j,k;
    cin>>n>>w;
    ll a[n+1][2];
    for(i=1;i<=n;i++)
     cin>>a[i][1]>>a[i][2];
 ll dp[n+1][w+1];
  for(i=0;i<=n;i++)
  {
      
      for(j=0;j<=w;j++)
      {
          if(i==0||j==0)
          dp[i][j]=0;
          else if(j>=a[i][1])
          dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i][1]]+a[i][2]);
          else
           dp[i][j]=dp[i-1][j];
      }
  }
  cout<<dp[n][w];
}

Measured memory_bytes: 79104
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,m,l;
    cin >> n >> m >> l;
    //行列A
    int matrixA[100][100]={0,0};
    //行列B
    int matrixB[100][100]={0,0};
    //行列C
    long long matrixC[100][100]={0,0};
    //----------------------------------------------
    //行列A-格納
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> matrixA[i][j];
        }
    }
    //行列B-格納
    for (int i=0; i<m; i++) {
        for (int j=0; j<l; j++) {
            cin >> matrixB[i][j];
        }
    }
    //--------------------------------------------
    //行列計算
    for (int i=0; i<n; i++) {
        for (int k=0; k<l; k++) {
            for (int j=0; j<m; j++) {
                matrixC[i][k] += matrixA[i][j]*matrixB[j][k];
            }
        }
    }
    //出力
    for (int i=0; i<n; i++) {
        for (int j=0; j<l-1; j++) {   //行列Cはn*l
            cout << matrixC[i][j] << " ";  //列
        }
        cout << matrixC[i][l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3276
N,M = map(int,input().split())
def gcd(a,b):
    if a >= b:
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    else:
        if a == 0:
            return b
        else:
            return gcd(a,b%a)
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
else:
    flag = True
    L = int((N//gcd(N,M))*M)
    m = L//M
    n = L//N
    for i in range(max(N,M)):
        if i*m <= N-1 and i*n <= M-1:
            if S[i*m] != T[i*n]:
                flag = False
                break
    if flag:
        print(L)
    else:
        print(-1)


Measured memory_bytes: 3444
import bisect
import math
import sys
n=int(input())
ans=0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
for i in b:
    aa=bisect.bisect_left(a,i)
    cc=len(c)-bisect.bisect_right(c,i)
    ans+=aa*cc
print(ans)


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

import sys
from bisect import bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, Q = MAP()
A = [0] * N
for i in range(N):
    A[i] = INT()
B = [0] * M
for i in range(M):
    B[i] = INT()

A.sort()
B.sort()
A = [-INF] + A + [INF]
B = [-INF] + B + [INF]

for i in range(Q):
    q = INT()
    
    # q以下で最大
    al = bisect_right(A, q) - 1
    bl = bisect_right(B, q) - 1
    # q以上で最小
    ar = bisect_left(A, q)
    br = bisect_left(B, q)

    # 両方左
    a = max(q-A[al], q-B[bl])
    # 両方右
    b = max(A[ar]-q, B[br]-q)
    # 左の神社、右の寺
    c = min(q-A[al], B[br]-q) * 2 + max(q-A[al], B[br]-q)
    # 右の神社、左の寺
    d = min(A[ar]-q, q-B[bl]) * 2 + max(A[ar]-q, q-B[bl])

    ans = min(a, b, c, d)
    print(ans)


Measured memory_bytes: 12868
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int prime[] = new int[50000];
		int n;
		int count;
		
		for (int i = 2; i < 50000; i++) {
			for (int j = i; j < 50000; j++) {
				if (0 <= i * j && i * j < 50000) {
					prime[i * j] = 1;
				} else {
					break;
				}
			}
		}
		n = sc.nextInt();
		while (n != 0) {
			count = 0;
			for (int i = 2; i <= n / 2; i++) {
				if (prime[i] == 0 && prime[n - i] == 0) {
					count++;
				}
			}
			System.out.println(count);
			n = sc.nextInt();
		}
	}
}

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

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

Measured memory_bytes: 3856
#include <stdio.h>

int main(void)
{
	int year, month, day;
	int x, y;
	int ju;
	
	while (scanf("%d %d %d", &year, &month, &day) != EOF) {
		ju = (year * 10000) + (month * 100) + day;
		if (ju >= 19890108) {
			printf("heisei %d %d %d\n", (year - 1988), month, day);
		}
		else if (ju >= 19261225) {
			printf("showa %d %d %d\n", (year - 1925), month, day);
		}
		else if (ju >= 19120730) {
			printf("taisho %d %d %d\n", (year - 1911), month, day);
		}
		else if (ju >= 18680908) {
			printf("meiji %d %d %d\n", (year - 1867), month, day);
		}
		else {
			printf("pre-meiji\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4+7;
int n,m;
int Wight[10] = {0,2,5,5,4,5,6,3,7,6},A[10];
vector<string> dp(maxn,"-");
string Max(string a,string b){
    if(a.size() != b.size())return a.size()>b.size()?a:b;
    return a>b?a:b;
}
signed main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)scanf("%d",&A[i]);
    dp[0] = "";
    for(int i=0;i<=n;i++)if(dp[i]!="-")
        for(int j=1;j<=m;j++)if(i+Wight[A[j]]<=n)
            dp[i+Wight[A[j]]] = Max(dp[i+Wight[A[j]]],dp[i]+char(A[j]+'0'));
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 43648
import java.util.*;

public class Main {
	static final long MODULO = 1_000_000_000 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int C = sc.nextInt() - 1;
		int T = sc.nextInt();
		int[] a = new int[K];
		int[] b = new int[K];
		int[] t = new int[K];
		for (int i = 0; i < K; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		// dp[t]=A[1]dp[t-1]+A[2]dp[t-2]+A[3]dp[t-3]
		long[][][] A = new long[6][N][N];
		for (int i = 0; i < K; ++i) {
			for (int j = 0; j < b[i]; ++j) {
				A[t[i]][j][(a[i] - 1) + j] += 1;
			}
			for (int j = 0; j < a[i] - 1; ++j) {
				A[t[i]][b[i] + j][j] += 1;
			}
			for (int j = a[i] + b[i] - 1; j < N; ++j) {
				A[t[i]][j][j] += 1;
			}
		}
		long[][] dp = new long[6][N];
		dp[0][C] = 1;
		for (int i = 1; i <= 5; ++i) {
			for (int j = 0; j < i; ++j) {
				dp[i] = addVec(dp[i], mulVec(A[i - j], dp[j]));
			}
		}
		long[] v = new long[N * 5];
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < N; ++j) {
				v[j + i * N] = dp[i][j];
			}
		}
		long[][] mx = new long[5 * N][5 * N];
		for (int i = N; i < 5 * N; ++i) {
			mx[i - N][i] = 1;
		}
		for (int i = 1; i <= 5; ++i) {
			for (int j = 0; j < N; ++j) {
				for (int k = 0; k < N; ++k) {
					mx[4 * N + j][N * (5 - i) + k] = A[i][j][k];
				}
			}
		}

		v = mulVec(pow(mx, T), v);
		System.out.println(v[0]);
	}

	static long[][] mul(long[][] a, long[][] b) {
		int n = a.length;
		long[][] ret = new long[n][n];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				for (int k = 0; k < n; ++k) {
					ret[i][j] += a[i][k] * b[k][j] % MODULO;
					ret[i][j] %= MODULO;
				}
			}
		}
		return ret;
	}

	static long[] mulVec(long[][] a, long[] v) {
		int n = v.length;
		long[] ret = new long[n];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				ret[i] += a[i][j] * v[j] % MODULO;
				ret[i] %= MODULO;
			}
		}
		return ret;
	}

	static long[] addVec(long[] a, long[] b) {
		int n = a.length;
		long[] ret = new long[n];
		for (int i = 0; i < n; ++i) {
			ret[i] = (a[i] + b[i]) % MODULO;
		}
		return ret;
	}

	static long[][] pow(long[][] a, long n) {
		int len = a.length;
		long[][] ret = new long[len][len];
		for (int i = 0; i < len; ++i)
			ret[i][i] = 1;
		for (; n > 0; n >>= 1, a = mul(a, a)) {
			if (n % 2 == 1) {
				ret = mul(ret, a);
			}
		}
		return ret;
	}

	static void showMatrix(long[][] a) {
		int n = a.length;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				System.out.print(a[i][j] + " ");
			}
			System.out.println();
		}
	}

	static void showVec(long[] a) {
		for (int i = 0; i < a.length; ++i) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 43828
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		List<Integer> p = new ArrayList<>();
		
		for(int i=11;i<=55555;i+=30){
			boolean ok = true;
			for(int j=2;j*j<=i;j++){
				if(i % j==0){
					ok = false;
					break;
				}
			}
			if(ok)
				p.add(i);
		}
		
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			System.out.print(p.get(i)+" ");
		}
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

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

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}

int main() {
    int N; string S;
    cin >> N >> S;
    long long r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') ++r;
        else if (c == 'G') ++g;
        else ++b;
    }
    long long all = r * g * b;
    long long sub = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if (S[i] == S[j]) continue;
            int k = j*2-i;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) continue;
            ++sub;
        }
    }
    cout << all - sub << endl;
}




Measured memory_bytes: 3596
#include<stdio.h>
int max(int *data, int n) {
    int max = data[0];
    for(int i = 0; i < n; i++) {
        if(data[i] > max) {
            max = data[i];
        }
    }
    return max;
}
int min(int *data, int n) {
    int min = data[0];
    for(int i = 0; i < n; i++) {
        if(data[i] < min) {
            min = data[i];
        }
    }
    return min;
}

int main(void) {
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    printf("%d\n", max( a,n )-min( a,n ));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
   
using namespace std;
     
#define PB(x) push_back(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x) make_pair(x);
    
#define debug(x) cerr << #x << '=' << x << endl;
#define debug2(x, y) cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a) for (int x: a) cerr << x << ' '; cerr << endl;
#define debugm(a, n, m) for (int i = 0; i < n; i++, cout << endl)           \
						for (int j = 0; j < m; j++) cout << a[i][j] << ' ';

#define int long long
     
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 1000000007;

int32_t main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	cout << ((n-1)*(n))/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  char a;
  bool x = true;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (i == 0) {
      a = s.back();
      mp[s]++;
      continue;
    }
    mp[s]++;
    if (mp[s] > 1 || a != s.front()) x = false;
    a = s.back();
  }
  dump(x ? "Yes" : "No");
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N+1);
  v.at(0)=0;
  int sum=0;
  for(int i=1;i<=N;i++){
    int W;
    cin >> W;
    sum+=W;
    v.at(i)=v.at(i-1)+W;
  }
  int mi=1e9;
  for(int i=1;i<N;i++){
    int diff=abs(v.at(i)-(sum-v.at(i)));
    if(mi>diff){
      mi=diff;
    }
  }
  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
double w[1010][1010], D[1010];
bool vis[1010];
struct point {
	long long x, y;
	point operator -(const point &p)const {
		return { x - p.x,y - p.y };
	}
	double SZ() {
		return sqrt(x*x + y*y);
	}
}P[1010];
long long R[1010];
int n;
void Input(point &a) {
	scanf("%lld%lld", &a.x, &a.y);
}
int main() {
	int i, j;
	Input(P[0]);
	Input(P[1]);
	scanf("%d", &n);
	for (i = 2; i <= n + 1; i++) {
		Input(P[i]);
		scanf("%lld", &R[i]);
	}
	n++;
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= n; j++) {
			double t = (P[j] - P[i]).SZ() - R[i] - R[j];
			w[i][j] = max(0.0, t);
		}
	}
	for (i = 1; i <= n; i++)D[i] = 1e18;
	while (1) {
		double Mn = 1e18;
		int pv = -1;
		for (i = 0; i <= n; i++) {
			if (!vis[i] && Mn > D[i]) {
				Mn = D[i];
				pv = i;
			}
		}
		if (pv == -1)break;
		vis[pv] = true;
		for (i = 0; i <= n; i++) {
			D[i] = min(D[i], D[pv] + w[pv][i]);
		}
	}
	printf("%.15f\n", D[1]);
}

Measured memory_bytes: 8064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;

int n;
vector<int> adj[MaxN + 1];

int sta[MaxN + 1];
int lab[MaxN + 1];

int dfs(int u, int prev)
{
	sta[u] = 0;

	int mask = 0;
	for (int v : adj[u])
		if (v != prev)
		{
			int sv = dfs(v, u);
			mask |= sv & sta[u];
			sta[u] |= sv;
		}

	if (sta[u] == 0)
		sta[u] = 1, lab[u] = 0;
	else
	{
		int l = 0;
		while (1 << l <= mask)
			++l;
		while (sta[u] >> l & 1)
			++l;

		lab[u] = l;
		sta[u] >>= l, sta[u] <<= l;
		sta[u] |= 1 << l;
	}

	return sta[u];
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		int u = getint(), v = getint();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, 0);

	cout << *max_element(lab + 1, lab + n + 1);
	cout << endl;

	return 0;
}

Measured memory_bytes: 11008
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

type con struct {
	a int
	b int
}

func conunt(d int, a []int) int {
	ans := 0
	for i := 0; i < len(a); i++ {
		if a[i] == d {
			ans++
		}
	}
	return ans
}

func test(s []int) {
	s[0] = 5
}

type dim struct {
	x []int
	y []int
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	a := make([]int, n)
	d := make([]dim, 0)
	for i := 0; i < n; i++ {
		a[i] = iScan()
		x := make([]int, a[i])
		y := make([]int, a[i])
		for j := 0; j < a[i]; j++ {
			x[j] = iScan()
			y[j] = iScan()
		}
		var p dim
		p.x = x
		p.y = y
		d = append(d, p)
	}

	best := 0
	for i := 0; i < (1 << n); i++ {
		//fmt.Println(i)
		flag := false
		for j := 0; j < n; j++ {
			if (1<<j)&i != 1<<j {
				//fmt.Println(i, j, "気にしない")
				continue
			} else {
				//fmt.Println(i, j, "きにする")
				for r := 0; r < len(d[j].x); r++ {
					caseb := ((d[j].y[r] << (d[j].x[r] - 1) & i) == (d[j].y[r] << (d[j].x[r] - 1)))
					if d[j].y[r] == 1 {
						//rの人は正直なはず
						if ((1 << (d[j].x[r] - 1)) & i) == 1<<(d[j].x[r]-1) {
							caseb = true
						} else {
							caseb = false
						}
					}
					if d[j].y[r] == 0 {
						//rの人は嘘つきなはず
						if ((1 << (d[j].x[r] - 1)) & i) == 1<<(d[j].x[r]-1) {
							caseb = false
						} else {
							caseb = true
						}
					}
					//fmt.Println(caseb)
					if caseb {

					} else {
						flag = true
					}
				}
			}
			if flag {
				break
			}
		}
		if flag == false {
			cou := 0
			//fmt.Println("fi", i)
			for r := 0; r < n; r++ {
				if (i & (1 << r)) == (1 << r) {
					cou++
				}
			}
			if best < cou {
				best = cou
			}
		}
	}
	fmt.Println(best)
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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 rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    string S;
    string T;
    cin >> S;
    cin >> T;
    vector<string> ans;
    bool judge=false;
    rep(i,S.size()-T.size()+1){
        ll count=0;
        string tmp="";
        rep(j,T.size()){
            if(T[j]==S[i+j] || S[i+j]=='?'){
                count++;
            }
        }
        if(count==T.size()){
            judge=true;
            tmp+=S;
            //cout << tmp << endl;
            rep(j,T.size()){
                if(tmp[i+j]=='?'){
                    tmp[i+j]=T[j];
                }
            }
            //cout << tmp << endl;
            rep(i,tmp.size()){
                if(tmp[i]=='?'){
                    tmp[i]='a';
                }
            }
            ans.PB(tmp);        
        }
    }
    //cout << ans << endl;
    if(judge==false){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    
    sort(all(ans));
    cout << ans[0] << endl;
}

Measured memory_bytes: 3676
var
	M,L,R,ans,ll,rr:int64;
    k,i,x,y,xl,yl,limx,limy,xx,yy,id,ie:Longint;
    dp:array[1..64,1..2,1..2]of int64;
begin
	read(L,R);
    M:=1000000007;
    ll:=1;
    rr:=2;
    for k:=1 to 62 do begin
    	if(rr<=L)or(R<ll)then begin
        	ll:=ll*2;
            rr:=rr*2;
        	continue;
        end;
        for i:=1 to 64 do for xx:=1 to 2 do for yy:=1 to 2 do dp[i,xx,yy]:=0;
        if L<=ll then if rr-1<=R then dp[1,2,2]:=1 else dp[1,2,1]:=1 else if rr-1<=R then dp[1,1,2]:=1 else dp[1,1,1]:=1;
        for i:=1 to k-1 do begin
        	x:=(L>>(k-1-i))mod 2;
            y:=(R>>(k-1-i))mod 2;
            for xl:=1 to 2 do begin
            	if xl=1 then limx:=x else limx:=0;
                for yl:=1 to 2 do begin
                	if yl=1 then limy:=y else limy:=1;
                    for yy:=0 to limy do begin
                    	for xx:=limx to yy do begin
                        	if(xl=2)or(xx>limx)then id:=2 else id:=1;
                            if(yl=2)or(yy<limy)then ie:=2 else ie:=1;
                            dp[i+1,id,ie]:=(dp[i+1,id,ie]+dp[i,xl,yl])mod M;
                        end;
                    end;
                end;
            end;
        end;
        ll:=ll*2;
        rr:=rr*2;
        ans:=(ans+dp[k,1,1]+dp[k,1,2]+dp[k,2,1]+dp[k,2,2])mod M;
    end;
    writeln(ans);
end.

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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    if (s.at(k - 1) == 'A') s.at(k - 1) = 'a';
    else if (s.at(k - 1) == 'B') s.at(k - 1) = 'b';
    else s.at(k - 1) = 'c';
    cout << s << endl;
}


Measured memory_bytes: 256