akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		ll c, n, m, s, d;
		cin>>c>>n>>m>>s>>d;
		if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
		--s;
		--d;
		vector<vector<P> > p(n);
		vector<vector<ll> > dir(n, vector<ll>(c + 1, INF * INF));
		REP(i, m) {
			int a, b, f;
			cin>>a>>b>>f;
			--a;
			--b;
			p[a].pb(P(b, f));
			p[b].pb(P(a, f));
		}
		priority_queue<pair<P, ll> > que;
		que.push(pair<P, ll>(P(0, s), c));
		dir[s][c] = 0;
		while(!que.empty()) {
			pair<P, ll> np = que.top();
			que.pop();
			if(dir[np.first.second][np.second] != np.first.first) continue;
			REP(i, p[np.first.second].size()) {
				if(dir[p[np.first.second][i].first][np.second] > dir[np.first.second][np.second] + p[np.first.second][i].second) {
					dir[p[np.first.second][i].first][np.second] = dir[np.first.second][np.second] + p[np.first.second][i].second;
					que.push(pair<P, ll>(P(dir[p[np.first.second][i].first][np.second], p[np.first.second][i].first), np.second));
				}
				if(np.second > 0 && dir[p[np.first.second][i].first][np.second - 1] > dir[np.first.second][np.second] + p[np.first.second][i].second / 2) {
					dir[p[np.first.second][i].first][np.second - 1] = dir[np.first.second][np.second] + p[np.first.second][i].second / 2;
					que.push(pair<P, ll>(P(dir[p[np.first.second][i].first][np.second - 1], p[np.first.second][i].first), np.second - 1));
				}
			}
		}
		ll res = INF * INF;
		REP(i, c + 1) {
			res = min(res, dir[d][i]);
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 200001
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        int n; cin>>n; int ans=0;
        set<int> s;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                s.insert(i);
                int temp=n;
                while(temp%i==0)
                temp=temp/i;
                if(temp%i==1)
                ans++;
                if(i*i!=n)
                {
                    s.insert(n/i);
                    int j = n/i;
                    temp=n;
                    while(temp%j==0)
                    temp=temp/j;
                    if(temp%j==1)
                    ans++;
                }
            }
        }
        n--;
        for(int i=1;i*i<=n;i++)
        {
            if(n%i==0)
            {
                if(s.find(i)==s.end())
                ans++;
                if(i*i!=n)
                {
                    if(s.find(n/i)==s.end())
                    ans++;
                }
            }
        }
        cout<<ans;
    }
}

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

// AとBの正の公約数からいくつか選んだときに得られる集合について，
// その集合に含まれる合成数をその数の素因数の一つに置き換えて得られる集合も
// またAとBの正の公約数からいくつか選んだときに得られる集合となるので，
// 最大サイズを考えるに当たっては，1と素数のみからなる集合を考えれば良い

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

vector<pair<ll, int>> factorize(ll n)
{
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i)
    {
        if (n % i)
            continue;
        res.emplace_back(i, 0);
        while (n % i == 0)
        {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1)
        res.emplace_back(n, 1);
    return res;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}


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

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

  vector<int> l(n);
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
    tmp += l[i];
  }

  sort(l.begin(), l.end());
  if (l[n-1] < tmp - l[n-1])
  cout << "Yes" << endl;
  else
  cout << "No" << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;


int main() {

	int N;
	cin >> N;

	int count = 0;
	float ans = 0.0f;
	if (N % 2 == 0)
	{
		count = N / 2;
	}
	else
	{
		count = N / 2 + 1;
	}
	ans = (float)count / (float)N;

	printf("%.6f", ans);

	return 0;
}

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

fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val frames = Array(n){
        val (f, a, t, x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        Frame(f, a, t, Position(x, y))
    }
    val aPass = frames.indices.drop(1).filter{i -> frames[i].team == 0 && frames[i - 1].team == 0 && frames[i].label != frames[i - 1].label}.map{i -> Pair(frames[i].position.norm(frames[i - 1].position), frames[i].time - frames[i - 1].time)}.maxWith(Comparator { o1, o2 ->  if (o1.first == o2.first) o2.second.compareTo(o1.second) else o1.first.compareTo(o2.first)})
    val bPass = frames.indices.drop(1).filter{i -> frames[i].team == 1 && frames[i - 1].team == 1 && frames[i].label != frames[i - 1].label}.map{i -> Pair(frames[i].position.norm(frames[i - 1].position), frames[i].time - frames[i - 1].time)}.maxWith(Comparator { o1, o2 ->  if (o1.first == o2.first) o2.second.compareTo(o1.second) else o1.first.compareTo(o2.first)})
    println(aPass?.let{"%.10f %.10f".format(sqrt(it.first.toDouble()), it.second / 60.0)} ?: "-1 -1")
    println(bPass?.let{"%.10f %.10f".format(sqrt(it.first.toDouble()), it.second / 60.0)} ?: "-1 -1")
}
data class Position(val x: Int, val y: Int) {
    fun norm(that: Position): Int = (this - that).let{(dx, dy) -> dx * dx + dy * dy}
    fun distance(that: Position): Double = sqrt(norm(that).toDouble())
    operator fun minus(that: Position): Position = Position(x - that.x, y - that.y)
}
data class Frame(val time: Int, val label: Int, val team: Int, val position: Position)


Measured memory_bytes: 34576
#include <stdio.h>
#include <string.h>
#define R register
#define MN 100005
int n,m,q,x,y,xx,yy,aa[MN],bb[MN];
char a[MN],b[MN];
inline int read(){
	R int x; R bool f; R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
	return f?-x:x;
}
int main(){
	scanf("%s%s",a+1,b+1);
	n=strlen(a+1),m=strlen(b+1);
	for (R int i=1; i<=n; ++i)
		aa[i]=a[i]-'A'+aa[i-1]+1;
	for (R int i=1; i<=m; ++i)
		bb[i]=b[i]-'A'+bb[i-1]+1;
	q=read();while(q--){
		x=read(),y=read(),xx=read(),yy=read();
		(aa[y]-aa[x-1])%3==(bb[yy]-bb[xx-1])%3?
			puts("YES"):puts("NO");
	}return 0;
}

Measured memory_bytes: 1408
n,w = map(int,input().split())
v = [list(map(int,input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(w+1):
    if j < v[i-1][0]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j],dp[i-1][j-v[i-1][0]]+v[i-1][1])
print(dp[n][w])

Measured memory_bytes: 120172
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    if(n<1200){
        std::cout << "ABC" << std::endl;
    }else if(n<2800){
        std::cout << "ARC" << std::endl;
    }else{
        std::cout << "AGC" << std::endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace __gnu_pbds;
using namespace std;
 
const int MAXN = 100000 + 20, MAXM = 20, MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1e9 + 10;
int a[MAXN], d[MAXN];
vector <int> vec[MAXN];
bool ok = 0;

void dfs(int u, int par) {
	int t = 1;
	int cnt = 0;
	for (int i = 0; i < vec[u].size(); i++) {
		if (vec[u][i] != par) {
			dfs(vec[u][i], u);
			t += d[vec[u][i]];	
			if (d[vec[u][i]] % 2 == 1)
				cnt++;
		}
	}	
	
	d[u] = t;
	if (cnt > 1)
		ok = 1;
}

void solve() {
	int n;
	cin >> n;
	
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	
	dfs(1, 0);
	
	if (n % 2 == 1)
		cout << "First" << endl;
	else if (ok == 1)
		cout << "First" << endl;
	else
		cout << "Second" << endl;
		
		
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}

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

int main(){
    int a, b, c;
    int n = 0;
    
    cin >> a >> b >> c;
    for(int i = a ; i <= b ; i++){
        if((c % i) == 0){
            n++;
        }
    }
    cout << n << endl;;
    
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, t;
    cin >> X >> t;
    if(X-t<0) {
        cout << 0 << endl;
    }
    else {
        cout << X-t << endl;
    }
    return 0;
}

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

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int h, w, m; cin >> h >> w >> m;
    vector<pair<int, int>> has;
    vector<int> cntX(h), cntY(w);
    int mx = 0, my = 0, cnt = 0;
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        has.emplace_back(--x, --y);
        cntX[x]++, cntY[y]++;
        mx = max(mx, cntX[x]);
        my = max(my, cntY[y]);
    }
    for (auto [x, y] : has) {
        if (cntX[x] == mx && cntY[y] == my) cnt++;
    }
    cout << mx + my - (cnt == count(cntX.begin(), cntX.end(), mx) * count(cntY.begin(), cntY.end(), my));
    return 0;
}

Measured memory_bytes: 9716
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> ordered_mset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    const ll mod=(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;}
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll man=(ll)1e5+5;
/*........................................................................................................................*/

signed main()
{
    fast;
    ll n;
    cin>>n;
    vector<ll>a(n);
    For(i,n)cin>>a[i];
    sort(all(a));
    ll ans=0;
    map<ll,ll>mp;
    For(i,n)
    {
        ll x=a[i];
        map<ll,ll>cur;
        for(ll p=2;p*p<=x;p++)
        {
            while(x%p==0)
            {
                cur[p]++;
                x/=p;
            }
        }
        if(x>1)
        {
            cur[x]++;
        }
        for(auto y:cur)
        {
            mp[y.fi]=max(mp[y.fi],y.se);
        }
    }
    ll val=1;
    for(auto x:mp)
    {
        For(i,x.se)val=mult(val,x.fi);
    }
    For(i,n)
    {
        ans=add(val*modinv(a[i]),ans);
    }
    cout<<ans<<endl;
    // what(val)
    // for(auto x:mp)cout<<x.fi<<" "<<x.se<<endl;
}   


Measured memory_bytes: 4296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    int n, c = 1; cin >> n;
    rep(i,n) {
        int a;
        cin >> a;
        if(a % 2 == 0) c *= 2;
    }
    int ans = pow(3,n);
    cout << ans - c << endl;
}


Measured memory_bytes: 4024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[1000],b[1000];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int j=1;j<=n;j++)
	{
		cin>>b[j];
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>b[i])
		{
			ans+=a[i]-b[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int n,i,sum=0,min=101;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
        if(a[i]%10!=0 && min>a[i]) min=a[i];
    }
    if(sum%10==0){
        if(min==101) sum=0;
        else sum-=min;
    }
    printf("%d",sum);
    return 0;
}

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

int main(){
  long long N,x,sum;
  cin >> N;
  x=N;
  sum = 0;
  while(x>=1){
    sum = sum + x%10;
    x = x/10;
  }
  if(N%sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
  
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000000)

A, B = map(int, input().split())

def extgcd(a, b, x, y):
    d = a
    if b != 0:
        y, x = extgcd(b, a % b, y, x)
        y -= (a // b) * x
        return x, y
    else:
        return (1, 0)

x, y = extgcd(A, B, 0, 0)
print("{} {}".format(x, y))



Measured memory_bytes: 5604
//##MohK
//1/04/2020 .... 3,20.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll x;
    cin>>x;
    if(x%500==0){
        cout<<(x/500)*1000;
    }
    else {
        ll a=x/500;
        ll b=1000*a;
        ll c=x-(a*500);
        ll d=c/5;
        ll e=d*5;
        cout<<e+b<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
typedef vector<ll> lvec;typedef vector<double> dvec;typedef vector<string> svec;
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll n, m, ac=0, wa=0;
  cin>>n>>m;
  vector<bool>q(n);
  rep(i,n) q[i]=false;
  vector<ll>p(m);
  vector<string>s(m);
  rep(i,m) cin>>p[i]>>s[i];
  rep(i,m){
    if(s[i]=="AC" && !q[p[i]]){
      ac++;
      q[p[i]]=true;
    }
    else if(s[i]=="WA" && !q[p[i]]) wa++;
  }
  rep(i,m){
    if(s[i]=="WA" && !q[p[i]]) wa--;
  }
  cout<<ac<<' '<<wa<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
string make_string(T N)
{
    string ret;
    T now = N;
    while (now > 0)
    {
        T x = now % 10;
        ret += (char)('0' + x);
        now /= 10;
    }
    reverse(all(ret));
    return ret;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    bool check = false;
    loop(i, N - 1)
    {
        ll L = i * C - (N - 1 - i) * D, R = i * D - (N - 1 - i) * C;
        ll X = A + L, Y = A + R;
        if (X <= B && B <= Y)
            check = true;
    }
    if (check)
        putout("YES");
    else
        putout("NO");
    return 0;
}


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

const int M = 20000;

int main() {
  vector<int> primes;

  for(int i = 2; i < M; i++) {
    bool flag = true;

    for(int j = 2; j * j <= i; j++) {
      if(i % j == 0) {
        flag = false;
        break;
      }
    }

    if(flag) {
      primes.push_back(i);
    }
  }
  
  for(int n; cin >> n && n; ) {
    int sum = 0, front = 0, back = 0, count = 0;

    while(true) {
      while(sum < n && front < primes.size()) {
        sum += primes[front++];
      }

      while(sum > n && back <= front) {
        sum -= primes[back++];
      }

      if(sum == n) {
        count++;
        sum -= primes[back++];
      }

      if(front == back) {
        break;
      }
    }

    cout << count << endl;
  }
}

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

using namespace std;

class Node{
//ノードはポインタでもっておこう
public:
  ///ノードの番号
  int num;
  //そのノードの親
  //rootの場合はnullptr
  Node* p=nullptr;
  //そのノードの子
  //葉でなければ少なくとも一つ持つ
  Node* l=nullptr;Node* r=nullptr;
};

//参照とかポインタとか気をつけよ(統一する)
//関数内はスタックに保存される
//xは根のNode
void insert(Node* &root,int k){
  //見ているNode、そのNodeの親を、それぞれx,yで管理する
  //newで確保するとポインタはスタック領域にあるので破棄されるけどnewで確保した領域はヒープ領域にあるから残ってる
  //つまり、その領域をvectorにあげれば良い
  Node* z= new Node;z->num=k;
  Node* y=nullptr;
  Node* x=root;

  while(x!=nullptr){
    y=x;
    if(z->num<x->num){
      x=x->l;
    }else{
      x=x->r;
    }
  }

  if(y==nullptr){
    root=z;
  }else{
    z->p=y;
    if(z->num<y->num){
      y->l=z;
    }else{
      y->r=z;
    }
  }
}

void pre_calc(Node* &n,vector<int>& v){
  if(n==nullptr) return;
  v.push_back(n->num);
  pre_calc(n->l,v);
  pre_calc(n->r,v);
}

void in_calc(Node* &n,vector<int>& v){
  if(n==nullptr) return;
  in_calc(n->l,v);
  v.push_back(n->num);
  in_calc(n->r,v);
}

void tree_print(Node* N){
  vector<int> vin;vector<int> vre;
  //v[0]はrootNode、vin,vreは出力したいものを入れておく
  in_calc(N,vin);
  pre_calc(N,vre);
  int le=vin.size();
  //printするところ
  for(int i=0;i<le;i++){
    cout << " " << vin[i];
  }
  cout << endl;
  for(int i=0;i<le;i++){
    cout << " " << vre[i];
  }
  cout << endl;
}

int main(){
  Node* N=nullptr;
  int n;cin >> n;
  for(int i=0;i<n;i++){
    string s;cin >> s;
    if(s=="insert"){
      int z;cin >> z;
      insert(N,z);
    }else{
      tree_print(N);
    }
  }
}



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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int cnt=0;
    for (int i = 0; i < N-2; i++)
    {
        string x = S.substr(i, 3);
        if(x=="ABC") cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

Mul=1
for i in range(N):
    if A[i]== 0:
        Mul = 0
for i in range(N):
    if Mul * A[i] > 10**18:
        Mul = -1
        break
    Mul = Mul * A[i]
print(Mul)

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

const uint64_t M = 1'000'000'007;
vector<int> edges[100000];
uint64_t dp[100000][2];

uint64_t solve(int node, int color){
    if(dp[node][color]) return dp[node][color];
    dp[node][color] = 1;
    for(auto to:edges[node]){
        uint32_t p = solve(to, 0);
        if(!color) p += solve(to, 1);
        p %= M;
        dp[node][color] *= p;
        dp[node][color] %= M;
    }
    return dp[node][color];
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n;
    cin >> n;
    for(int i=0;i<n-1;i++){
        int x, y;
        cin >> x >> y;
        edges[x-1].push_back(y-1);
        edges[y-1].push_back(x-1);
    }

    queue<int> q;
    unordered_set<int> checked;
    q.push(0);
    checked.insert(0);
    while(!q.empty()){
        int f = q.front();
        q.pop();
        for(int to:edges[f]){
            if(!checked.count(to)){
                checked.insert(to);
                q.push(to);
                edges[to].erase(find(edges[to].begin(), edges[to].end(), f));
            }
        }
    }

    cout << (solve(0, 0) + solve(0, 1)) % M << endl;

    return 0;
}

Measured memory_bytes: 18340
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;

int main(){
    ll N;
    cin >> N;
    vector<ll> A;
    vector<ll> resi;
    ll res = 0;
    for(ll i = 0; i < N; ++i){
        ll tmp1, tmp2;
        cin >> tmp1;
        A.push_back(tmp1);
        tmp2 = tmp1 - (i + 1);
        resi.push_back(tmp2);
    }
    sort(resi.begin(), resi.end());
    ll median;
    if(resi.size() % 2 == 0) median = (resi[resi.size()/2] + resi[resi.size()/2 - 1]) / 2;
    else median = resi[resi.size()/2];
    ll ans = 0;
    for(ll j = 0; j < N; ++j){
        ans += abs(A[j] - (median + j + 1));
    }
    cout << ans << endl;
}

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

int main()
{
	long long i,j,k,n,tab[100010];
	map <long long,long long> mp;
	cin>>n;
	mp.clear();
	for (i=1;i<=n;i++)
	{
		cin>>tab[i];
		mp[tab[i]]++;
	}
	long long sum=0;
	for (i=1;i<=n;i++)
	{
		if (mp[tab[i]]==0) continue;
		if (mp[tab[i]]%2==1) sum++;
		
		mp[tab[i]]=0;
	}
	cout<<sum<<"\n";
}

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

typedef long long ll;

queue<char> qa;
queue<char> qb;
queue<char> qc;

string sa, sb, sc;
void pushData() {
    
    int i;
    for (i = 0; i < sa.length(); i++)
        qa.push(sa[i]);
    
    for (i = 0; i < sb.length(); i++)
        qb.push(sb[i]);
    
    for (i = 0; i < sc.length(); i++)
        qc.push(sc[i]);
    
}

int main() {
    
    cin >> sa >> sb >> sc;
    
    
    pushData();
    
    char turnIndex = 'a';
    
    while (1) {
        if (turnIndex == 'a') {
            
            if (qa.empty()) {
                cout << "A"; break;
            }
            turnIndex = qa.front();
            qa.pop();
            
            
            
        }
        else if (turnIndex == 'b') {
            if (qb.empty()){
                cout << "B"; break;
            }
            
            turnIndex = qb.front();
            qb.pop();
            
            
            
        }else if (turnIndex == 'c'){
            if (qc.empty()){
                cout << "C"; break;
            }
            
            turnIndex = qc.front();
            qc.pop();
            
            
        }
    }
    
    
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}



int main() {
	int a,b; cin >> a >> b;
	if(b%a==0) cout << a+ b << endl;
	else cout << b - a << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int n;
    ll a[100010],x;
    cin>>n>>x;
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    for(int i=1;i<n;i++){
        if(a[i]+a[i-1]>x){
            ans+=a[i]+a[i-1]-x;
            a[i]-=a[i]+a[i-1]-x;
            if(a[i]<0) a[i]=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int A, B, C;
    int a, b, c;
    cin >> a >> b >> c;
    int dpA[n];
    int dpB[n];
    int dpC[n];
    if (n == 1)
        cout << max({ a, b, c }) << endl;
    else
    {
        dpA[0] = a;
        dpB[0] = b;
        dpC[0] = c;
        for (int i = 1; i < n; i++)
        {
            cin >> a >> b >> c;
            dpA[i] = max({ dpB[i - 1] + a, dpC[i - 1] + a, dpA[i - 1] });
            dpB[i] = max({ dpC[i - 1] + b, dpA[i - 1] + b, dpB[i - 1] });
            dpC[i] = max({ dpB[i - 1] + c, dpA[i - 1] + c, dpC[i - 1] });
        }
        cout << max({ dpA[n - 1], dpB[n - 1], dpC[n - 1] }) << endl;
    }
}


Measured memory_bytes: 4772
using System;

class Program{
    static void Main(string[] args){
        long M = 1000000007;
        
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int C = int.Parse(str[1]);
        str  = Console.ReadLine().Split(' ');
        long[] A = new long[N+1];
        long[] B = new long[N+1];
        for(int i=0;i<N;i++){
            A[i] = long.Parse(str[i]);
        }
        str  = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            B[i] = long.Parse(str[i]);
        }
        
        int tableSize = 401;
        long[,] table = new long[tableSize,tableSize];
        for(int j=0;j<tableSize;j++){
            table[0,j] = 1;
            for(int i=1;i<tableSize;i++){
                table[i,j] = table[i-1,j] * ((long) j) % M;
            }
        }
        for(int i=0;i<tableSize;i++){
            for(int j=1;j<tableSize;j++){
                table[i,j] += table[i,j-1];
                table[i,j] %= M;
            }
        }
        
        
        
        long[,] dp = new long[N, C+1];
        for(int i=0;i<N;i++){
            for(int j=0;j<C+1;j++){
                dp[i,j] = 0;
            }
        }
        dp[N-1,0]=(table[0,B[N-1]]-table[0,A[N-1]-1])%M;
        for(int j=1;j<C+1;j++){
            dp[N-1,j] = (M+table[j,B[N-1]]-table[j,A[N-1]-1])%M;
        }
        
        for(int i=N-2;i>-1;i--){
            for(int j=0;j<C+1;j++){
                for(int k=0;k<=j;k++){
                    dp[i,j] += ((M+table[k,B[i]]-table[k,A[i]-1]) * dp[i+1,j-k] % M)% M;
                    dp[i,j] %= M;
                }
            }
        }
        Console.WriteLine(dp[0,C]%M);
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<string,int> psi;
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll p[n], mini=1000000, c=0;
    for(ll i=0;i<n;i++)
    {
        cin>>p[i];
        mini=min(mini,p[i]);
        if(mini==p[i])
            c++;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 1792
import itertools
n, m, x = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(n)]

ans = 10 ** 10
for bb in itertools.product([0, 1], repeat = n):
	comp = [0 for _ in range(m)]
	price = 0
	for i in range(n):
		if bb[i] == 1:
			for j in range(m):
				comp[j] += books[i][j + 1]
			price += books[i][0]
	if len([y for y in comp if y < x]) == 0:
		ans = min(ans, price)
if ans == 10 ** 10:
	print(-1)
else:
	print(ans)

Measured memory_bytes: 9224
using System;
using System.Collections.Generic;

namespace B_Card_Game_for_Three_ABC_Edit
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var cardsOfA = ReadCards();
            var cardsOfB = ReadCards();
            var cardsOfC = ReadCards();

            var nextPlayer = ' ';
            char winner;
            while (true) 
            {
                if ((cardsOfA.Count == 0) && (nextPlayer == 'a'))
                {
                    winner = 'A';
                    break;
                }
                if ((cardsOfB.Count == 0) && (nextPlayer == 'b'))
                {
                    winner = 'B';
                    break;
                }
                if ((cardsOfC.Count == 0) && (nextPlayer == 'c'))
                {
                    winner = 'C';
                    break;
                }

                switch (nextPlayer)
                {
                    case 'a':
                        nextPlayer = cardsOfA[0];
                        cardsOfA.RemoveAt(0);
                        break;
                    case 'b':
                        nextPlayer = cardsOfB[0];
                        cardsOfB.RemoveAt(0);
                        break;
                    case 'c':
                        nextPlayer = cardsOfC[0];
                        cardsOfC.RemoveAt(0);
                        break;
                    default:
                        nextPlayer = cardsOfA[0];
                        cardsOfA.RemoveAt(0);
                        break;
                }
            } 

            Console.WriteLine(winner);
        }

        private static List<char> ReadCards()
        {
            var cards = new List<char>();
            var inputs = Console.ReadLine().ToCharArray();
            foreach (var c in inputs)
            {
                cards.Add(c);
            }
            return cards;
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
int n, d, r = 0;
vector<vector<int>> x;

bool calc(int u, int v){
	db sum = 0;
	for(int i = 0; i < d; i++){
		sum += abs(x[u][i] - x[v][i]) * abs(x[u][i] - x[v][i]);
	}
	for(int i = 1; i*i <= sum; i++){
		if(i*i == sum) return true;
	}
	return false;
}

int main() {
	cin >> n >> d;
	x = vector<vector<int>> (n, vector<int>(d));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++){
			cin >> x[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j) continue;
			r += calc(j, i);
		}
	}
	cout << r / 2 << "\n";
	return 0;
}


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

#define pb      push_back
#define all(v)  v.begin(),v.end()
#define endl    "\n"
#define FAST    ios_base::sync_with_stdio(0);cin.tie(0);

typedef long long     ll;
typedef long double   ld;
typedef pair<int,int> ii;

const int    inf = 2e9;
const ll     INF = 4e17;
const int    mod = 1e9+7;
const double eps = 1e-9;

const int N = 1e5+2;
bool mark[N];
vector<int> v;

int main() {
	mark[0] = mark[1] = true;
	for(ll i = 2; i < N; i++) {
		if(mark[i]) continue;
		for(ll j = i*i; j < N; j+=i)
			mark[j] = true; 
	}

	for(int i = 1; i < N; i+=2) {
		if(!mark[i] && !mark[(i+1)>>1])
			v.push_back(i);
	}
	int q, sz = v.size();
	scanf("%d", &q);
	while(q--) {
		int l, r, ans = 0;
		scanf("%d %d", &l, &r);
		int idx1 = lower_bound(all(v), l) - v.begin();
		int idx2 = upper_bound(all(v), r) - v.begin();
		printf("%d\n", idx2 - idx1);
	}
	return 0;
}



Measured memory_bytes: 768
s = input()+chr(ord("a")-1)
ans = -1
for i in range(len(s)):
    t = s[:~i]
    dif = set(map(chr,range(ord(s[~i])+1,123))) - set(t)
    if dif:
        ans = t + min(dif)
        break
print(ans)

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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  dumpv(N, h);
  int cnt = 0;
  while (1) {
    int end = 1;
    int flag = 1;
    for (int i = 0; i < N; i++) {
      if (h[i]) {
        end = 0;
        if (flag) {
          flag = 0;
          cnt++;
        }
        h[i]--;
      } else {
        flag = 1;
      }
    }
    dumpv(cnt, end, h);
    if (end)
      break;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
ll x; long double n;
int main() {
	cin >> x >> n;
	cout << (ll)(x*n) << endl;
	return 0;
}

Measured memory_bytes: 3728
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [False] * 1000
    ls2 = [False] * 1000
    ls3 = [False] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <map>
#include <cinttypes>

const int MOD_BY = 1000000007;

int add(int a, int b) {
	return a + b - (a + b >= MOD_BY ? MOD_BY : 0);
}

int sub(int a, int b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

int mul(int a, int b) {
	int r = 0;
	while (b > 0) {
		if (b & 1) r = add(r, a);
		a = add(a, a);
		b >>= 1;
	}
	return r;
}

int pou(int a, int b) {
	int r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int64_t gcd(int64_t a, int64_t b) {
	if (a < 0) a = -a;
	if (b < 0) b = -b;
	if (a == 0 && b == 0) return 1;
	if (a == 0) return b;
	if (b == 0) return a;
	while (b > 0) {
		int64_t r = a % b;
		a = b;
		b = r;
	}
	return a;
}

struct ayaneru {
	int64_t x, y;

	ayaneru() : x(0), y(0) {}

	ayaneru(int64_t hoge, int64_t fuga) {
		int64_t g = gcd(hoge, fuga);
		x = hoge / g;
		y = fuga / g;
		if (x < 0) {
			x = -x;
			y = -y;
		}
		if (x == 0 && y < 0) y = -y;
	}

	ayaneru are() const {
		return ayaneru(y, -x);
	}

	bool zero() const {
		return x == 0 && y == 0;
	}

	bool operator<(const ayaneru& o) const {
		if (x != o.x) return x < o.x;
		return y < o.y;
	}
};

struct asumisu {
	int kore, chokkaku;

	asumisu(int k = 0, int c = 0) : kore(k), chokkaku(c) {}
};

template<typename A, typename B>
bool in(const std::map<A, B>& m, const A& key) {
	return m.find(key) != m.end();
}

int main(void) {
	int N;
	std::vector<ayaneru> iwasi;
	int zeroCount = 0;
	int kotae;
	if (scanf("%d", &N) != 1) return 1;
	iwasi.reserve(N);
	for (int i = 0; i < N; i++) {
		int64_t A, B;
		if (scanf("%" SCNd64 "%" SCNd64, &A, &B) != 2) return 1;
		iwasi.push_back(ayaneru(A, B));
	}

	std::map<ayaneru, asumisu> risuto;
	for (std::vector<ayaneru>::iterator itr = iwasi.begin(); itr != iwasi.end(); itr++) {
		const ayaneru& i = *itr;
#if 0
		printf("iwasi %d %d\n", (int)i.x, (int)i.y);
#endif
		ayaneru op = i.are();
		if (i.zero()) {
			zeroCount++;
		} else if (in(risuto, i)) {
			risuto[i].kore++;
		} else if (in(risuto, op)) {
			risuto[op].chokkaku++;
		} else {
			risuto[i] = asumisu(1, 0);
		}
	}

	kotae = 1;
	for (std::map<ayaneru, asumisu>::iterator itr = risuto.begin(); itr != risuto.end(); itr++) {
		const asumisu& a = itr->second;
#if 0
		printf("itr %d %d\n", a.kore, a.chokkaku);
#endif
		int kore = a.kore == 0 ? 0 : pou(2, a.kore);
		int chokkaku = a.chokkaku == 0 ? 0 : pou(2, a.chokkaku);
		int delta = add(kore, chokkaku);
		if (a.kore != 0 && a.chokkaku != 0) delta = sub(delta, 1);
		kotae = mul(kotae, delta);
	}
	kotae = add(sub(kotae, 1), zeroCount);

	printf("%d\n", kotae);
	return 0;
}


Measured memory_bytes: 18292
line = list(input())
count, count_max = 0, 0
for b in line:
    if b == 'A' or b == 'T' or b == 'G' or b == 'C':
        count += 1
    else:
        count = 0
    if count > count_max:
        count_max = count
    
print(count_max)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
N = int(input())
S = []

def kakui(X):
    x = [0] * 6
    for i in [5,4,3,2,1,0]:
        x[i] = X // (10**i)
        X = X % (10**i)
    return(x)
def sum(x):
    sum = 0
    for i in range(6):
        sum += x[i]
    return sum

for A in range(1, N):
    B = N - A
    
    S.append(sum(kakui(A))+sum(kakui(B)))
print(min(S))




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


int main(){
  int A, B;
  cin >> A >> B;
  for(int ii=0; ii<=2000; ii++){
    if((int)((double)ii*0.08) != A) continue;
    if((int)((double)ii*0.10) != B) continue;
    cout << ii << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] c = new int[h][w];
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int color = 0;
		for (int i = 0; i < h * w; i++) {
			int y = i / w;
			int x = (y % 2 == 1) ? (w - (i % w) - 1) : i % w;
			while (color < a.length && a[color] == 0) color++;
			c[y][x] = color + 1;
			a[color]--;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				sb.append(c[i][j]);
				sb.append(" ");
			}
			sb.append("\n");
		}

		System.out.print(sb.toString());
	}
}


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

int main() {
    int a,b;
    cin >> a >> b;
    int cnt = 0;
    int keta = b;
    while(keta>0){
        keta /= 10;
        cnt++;
    }
    int c = a*pow(10, cnt)+b;
    int ans = c;
    ans = sqrt(ans);
    ans *= ans;
    if(ans == c) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int MAXN = 3003;
int n;
int a[MAXN];

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

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

    printf("%d\n", ans - n);

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, k; cin >> n >> k;
    vector<double>v(n);
    vector<double>m(1001);
    double d = 0;
    for(int a = 1; a < 1001; a++){
        d += a;
        m[a] = d/a;
    }
    
    for(int i = 0 ; i < n; i++){
        int x; cin >> x;
        v[i] = m[x];
    }
    double sum = 0;
    //get sum up to of v[i] -> v[k];
    for(int i = 0; i < k; i++) sum+=v[i];
    //copy sum value.
    double ans = sum;
    for(int i = 1; i <= n-k; i++){
        sum -= v[i-1];
        sum += v[i+k-1];
        ans = max(ans, sum);
    }
    printf("%.9f",ans);
	return 0;
}

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

using namespace std;

long long C(int K) {
	long long sum = 0;
	for (int i = 1; i <= K; i++)
		for (int j = 1; j <= K; j++)
			for (int k = 1; k <= K; k++)
				sum += gcd(i, gcd(j, k));
	return sum;
}

int main() {
	int K;
	cin >> K;
	cout << C(K);
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,i,j,n,m,l,r;
    cin>>s;
    l=(s[0]-48)*10+s[1]-48;
    r=(s[2]-48)*10+s[3]-48;
    if(((l>=0 && l<100) && (r>0 && r<13)) && ((l>0 && l<13) && (r>=0 && r<100)))
    {
        cout<<"AMBIGUOUS\n";
    }
    else if((l>=0 && l<100) && (r>0 && r<13))
    {
        cout<<"YYMM\n";
    }
    else if((l>0 && l<13) && (r>=0 && r<100))
    {
        cout<<"MMYY\n";
    }
    else
    {
        cout<<"NA\n";
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateAlgorithm
{
    class Program
    {
        public const long Inf = (long)1e18;
        public const double eps = 1e-6;
        public const string alfa = "abcdefghijklmnopqrstuvwxyz";
        public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const int MOD = 1000000007;
        
        // c ot i
        static int ToInt(char c) => c - '0';

        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            long a = long.Parse(str[0]);
            long b = long.Parse(str[1]);
            long n = long.Parse(str[2]);
            long ans = b / n - a / n;
            if (a % n == 0) ans++;
            Console.WriteLine(ans);
        }

        #region  範囲

        public static bool InRange<T>(T begin, T end, T value) where T : IComparable<T> 
            => value.CompareTo(begin) >= 0 && value.CompareTo(end) <= 0;

        #endregion

        #region MIN,MAX

        /// <summary>
        /// 最大値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MaxValue<T>(params T[] vals) => vals.Max();

        /// <summary>
        /// 最小値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MinValue<T>(params T[] vals) => vals.Min();
        #endregion
    }

    #region IO

    /// <summary>
    /// IO
    /// </summary>
    public class IO
    {
        public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine();
        public static int ReadInt() => int.Parse(ReadStr());

        public static long ReadLong() => long.Parse(ReadStr());

        public static decimal ReadDecimal() => decimal.Parse(ReadStr());
        public static double ReadDouble() => double.Parse(ReadStr());
        public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator);
        public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse);
        public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse);

        public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse);
        public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse);        
    }

    #endregion    
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int w, h; cin >> w >> h&&w;) {
		static char c[21][21];
		int n = 1;
		static int pi[11], pj[11];
		rep(i, 0, h)rep(j, 0, w) {
			cin >> c[i][j];
			if (c[i][j] == '*') {
				pi[n] = i;
				pj[n] = j;
				n++;
			}
			else if (c[i][j] == 'o')
				pi[0] = i, pj[0] = j;
		}
		static const int di[] = { 1,0,-1,0 };
		static const int dj[] = { 0,1,0,-1 };
		static int d[11][21][21];
		memset(d, 0x3f, sizeof(d));
		rep(i, 0, n) {
			d[i][pi[i]][pj[i]] = 0;
		}
		auto inrange = [&](int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; };
		rep(k, 0, n) {
			using P = pair<int, int>;
			queue<P> q;
			q.push(P(pi[k], pj[k]));
			for (int ci, cj; !q.empty();) {
				tie(ci, cj) = q.front(); q.pop();
				for (int i = 0; i < 4; i++) {
					int ni = ci + di[i], nj = cj + dj[i];
					if (!inrange(ni, nj))continue;
					if (c[ni][nj] == 'x')continue;
					if (d[k][ni][nj] != INF)continue;
					d[k][ni][nj] = d[k][ci][cj] + 1;
					q.emplace(ni, nj);
				}
			}
		}
		static int dp[1 << 11][11];
		memset(dp, 0x3f, sizeof(dp));
		dp[1][0] = 0;
		dump(n);
		for (int mask = 0; mask < (1 << n); mask++) {
			rep(i, 0, n) {
				rep(j, 0, n) {
					if (mask >> j & 1)continue;
					if (dp[mask][i] == INF || d[i][pi[j]][pj[j]] == INF)continue;
					dump(mask);
					chmin(dp[mask | (1 << j)][j], dp[mask][i] + d[i][pi[j]][pj[j]]);
				}
			}
		}
		int ans = INF;
		rep(i, 0, n)
			chmin(ans, dp[(1 << n) - 1][i]);
		cout << (ans == INF ? -1 : ans) << endl;
	}
	return 0;
}

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

					#define mp make_pair
					#define pb push_back
					#define sqr(x) (x) * (x)
					#define sors(s) sort(s.begin(), s.end())
					#define F first
					#define S second

					using namespace std;
					typedef long long ll;
					ll n, s, a[222], b[222];
					int main()
					{
						cin >> n;
						for(int i = 1; i < n; i++)
							cin >> b[i];
						b[n] = 1e9;
						s += b[1];
						for(int i = 1; i < n; i++)
							s += min(b[i], b[i+1]);
						cout << s;		
					}

Measured memory_bytes: 256