akhauriyash/Code-Regression huggingface dataset:
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (decltype(k) i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
void err() {
    std::cout << "No" << '\n';
    exit(0);
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    i32 n; std::cin >> n;
    vec<i32> a(n);
    vec<diag_pair<i32>> ai(n);
    for (i32 i=0; i<n; i++) {
        i32 x; std::cin >> x, x--;
        ai.at(i) = {x, i};
        a.at(i) = x;
    }
    std::sort(ALL(ai));

    vec<i32> ans(n*n, -1), left, right;
    for (auto&& p: ai) {
        i32 x, i; std::tie(x, i) = p;
        ans.at(x) = i;
        LOOP (i) left.push_back(i);
        LOOP (n-1-i) right.push_back(i);
    }
    std::reverse(ALL(left));
    std::reverse(ALL(right));

    for (i32 i=0; i<n*n; i++) if (ans.at(i)==-1) {
        auto&& v = left.empty() ? right : left;
        ans.at(i) = v.back(); v.pop_back();
    }

    vec<i32> ckd(n);
    for (i32 i=0; i<n*n; i++) {
        i32 x = ans.at(i);
        if (ckd.at(x)++==x && a.at(x)!=i) err();
    }

    std::cout << "Yes" << '\n';
    for (i32 i=0; i<n*n; i++) std::cout << (i ? " " : "") << ans.at(i) + 1; std::cout << '\n';
}


Measured memory_bytes: 3320
#include <stdio.h> 
 
int main() {
  int x,i,n;
 
  scanf("%d",&n);
   
  for(i=1; i<=n; i++) {
    x = i;
     
    if(x %3 == 0) {
      printf(" %d",i);
    } else if(x % 10 == 3) {
      printf(" %d",i);
    } else { 
      while(x != 0) {
    x /=10;
    if(x % 10 == 3) {
      printf(" %d",i);
      break;
    }
      }
    }
     
  }
  printf("\n");
  return 0;
}




Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int hh[1000*1000],ww[1000*1000];
int main(void){
	int n,m;
	while(cin>>n>>m){
		if(n==0)break;
		int h[n+1],w[m+1];
		memset(h,0,sizeof(h));
		memset(w,0,sizeof(w));
		for(int i=0;i<n;i++){
			cin>>h[i];
		}
		for(int i=0;i<m;i++){
			cin>>w[i];
		}
		int sumw=0,sumh=0;
		memset(hh,0,sizeof(hh));
		memset(ww,0,sizeof(ww));
		for(int i=0;i<n;i++){
			sumh=0;
			for(int j=i;j<n;j++){
				sumh += h[j];
				hh[sumh]++;
			}
		}
		for(int i=0;i<m;i++){
			sumw=0;
			for(int j=i;j<m;j++){
				sumw += w[j];
				ww[sumw]++;
			}
		}
		int ans=0;
		//int m = max(n*n,m*m);
		for(int i=0;i<1000*1000;i++){
			ans += hh[i]*ww[i];
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 10920
H,W = map(int,input().split())

s = [list(input()) for x in range(H)]

flg = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            #上
            if 0 < i:
                if s[i-1][j] == '#':
                    flg = False
            #左
            if 0 < j:
                if s[i][j-1] == '#':
                    flg = False
            #右
            if j < W-1:
                if s[i][j+1] == '#':
                    flg = False
            #下
            if i < H-1:
                if s[i+1][j] == '#':
                    flg = False
            if flg:
                print('No')
                exit()
            flg = True
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e5+10;
int N;
int H[Maxn],Dp[Maxn];
int main()
{
	cin>>N;
	for(int i=1;i<=N;i++) cin>>H[i];
	Dp[1]=0,Dp[2]=abs(H[2]-H[1]);
	for(int i=3;i<=N;i++) Dp[i]=min(Dp[i-1]+abs(H[i]-H[i-1]),Dp[i-2]+abs(H[i]-H[i-2]));
	cout<<Dp[N]<<endl;
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    char c;
    cin >> c;

    if(c >= 'A' && c <= 'Z')
        cout << 'A';
    else
        cout << 'a';

    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main(){
int i,j,k,r=0,d=0;
char c;
while(cin>>i){
cin>>c>>j>>c>>k;
if(i*i+j*j==k*k)r++;
if(i==j)d++;
}
cout<<r<<endl;
cout<<d<<endl;
return 0;
}

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

int main() {
  int N, K;
  string S;
  
  cin >> N >> K;
  cin >> S;
  
  char offset = 'A' - 'a';
  
  S[K - 1] -= offset;
  
  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;
 
int main()
{
    NFS
 	string s;
 	cin>>s;
 	deque<char> st;
 	for(int i=0;i<s.length();i++)
 	{
 		st.push_back(s[i]);		
 	}
 	int q,k=0;
 	cin>>q;
 	while(q--)
 	{
 		int t;
 		cin>>t;
 		if(t==1)
 			if(k==0)k=1;else k=0;
 		else
 		{
 			int f;char c;
 			cin>>f>>c;
 			if(k==0){
 			if(f==1)
 				st.push_front(c);
 			else
 				st.push_back(c);
 			}else
 			{
 				if(f==1)
 					st.push_back(c);
 				else
 					st.push_front(c);
 			}
 		}
 	}
 	s="";
 	deque <char> :: iterator it; 
    for (it = st.begin(); it != st.end(); ++it) 
        s+=*it;
 	if(k==0)
 	{
 		 cout<<s;
 	}
 	else
 	{
 		reverse(s.begin(),s.end());
 		cout<<s;
 	}
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
using namespace std;
int main(){
int A, B, K;
cin >>A >>B >>K;
if(B-A < 2*K){
  for(int i=A; i<=B; i++){
    cout << i << endl;
  }
}else{
  for(int i=A; i<A+K; i++){
    cout << i << endl;
  }
  for(int i=B-K+1; i<=B; i++){
    cout << i << endl;
  }
}
return 0;
}


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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

void sputs(){}
template <class Head, class... Tail>
void sputs(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) == 0) { cout << endl; }
  else { cout << " "; }
  sputs(std::move(tail)...);
}

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

struct UnionFind {/*{{{*/
  vector<int> data;  // size defined only for root node
  int count;

  UnionFind(int size) : data(size, -1), count(size){ }

  bool merge(int x, int y) {
    x=root(x); y=root(y);
    if (x!=y) {
      if (data[y]<data[x]) swap(x, y);
      data[x]+=data[y]; data[y]=x;
      count--;
    }
    return x != y;
  }
  int root(int x) {
    return (data[x]<0 ? x : data[x]=root(data[x]));
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int size(int x) {
    return -data[root(x)];
  }
};/*}}}*/

signed main() {
  int n,m;cin>>n>>m;/*{{{*/
  UnionFind uf(n);
  vector<int> a(n);
  rep(i, n) {
    cin>>a[i];
  }
  dump(a);
  
  rep(i, m){
    int x,y;cin>>x>>y;
    uf.merge(x,y);
  }

  map<int, vector<int>> Z;
  rep(i,n){
    Z[uf.root(i)].pb(a[i]);
  }
  dump(Z);/*}}}*/

  int k = sz(Z);  // 連結成分の数
  if (k==1) {
    cout << 0 << endl;
    return 0;
  }
  dump(k);
  int ans = 0;
  vi tmp;
  each(el, Z){
    vi cands = el.second;
    sort(all(cands));
    ans += cands[0];
    rep(i, 1, sz(cands)) tmp.pb(cands[i]);
  }
  sort(all(tmp));
  if (sz(tmp)<2*(k-1)-k) {
    cout << "Impossible" << endl;
    return 0;
  }
  rep(i, 2*(k-1)-k) ans+=tmp[i];
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 12800
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        var T = input[0];
        var X = input[1];

        Console.WriteLine(T/X);
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N,M; cin >> N >> M;

    vector<int> k(M);
    vector<vector<int>> s(M);
    rep(i,M){
        cin >> k[i];
        s[i].resize(k[i]);
        for(int j=0;j<k[i];j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(M);
    rep(i,M) cin >> p[i];

    int ans = 0;
    for(int sw = 0; sw < (1<<N); sw++){
        vector<bool> on(M,true);

        for(int i=0;i<M;i++){
            int cnt=0;
            for(int j=0;j<k[i];j++){
                int b = s[i][j];
                if(sw & (1<<b)){
                    cnt++;
                }
            }
            if(cnt%2==p[i]) on[i] = true;
            else on[i] = false;
        }

        bool ok=true;
        for(int i=0;i<M;i++) if(on[i]==false)  ok = false;
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 200000
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define d double
void solve(){
	ll n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	ll ans=0;
	if(p==2 || p==5){
		for(int i=0;i<n;i++){
			if((s[i]-'0')%p==0) ans+=(i+1);
		}
		cout<<ans<<endl;
	}
	else{
		map<ll,ll> mp;
		mp[0]++;
		int mul=1,t=0;
		for(int i=n-1;i>=0;i--){
			t=(t+(s[i]-'0')*mul)%p;
			ans+=mp[t];
			mp[t]++;
			mul=mul*10%p;
		}
		cout<<ans<<endl;
	}
 
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 1028
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N;
LL M;
vector<int>graph[114514];

int col[114514];

bool dfs(int v, int c)
{
	if (col[v] >= 0)
	{
		return col[v] == c;
	}
	col[v] = c;
	for (int nx : graph[v])
	{
		if (!dfs(nx, !c))
		{
			return false;
		}
	}
	return true;
}

int main(void)
{
	cin >> N >> M;
	for (int i = 0; i < M; ++i)
	{
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	memset(col, 0xff, sizeof(col));
	bool res = dfs(0, 0);
	LL sum = 0;
	if (res)
	{
		LL b = 0, w = 0;
		for (int i = 0; i < N; ++i)
		{
			if (col[i])b++;
			else w++;
		}
		sum = b * w;
	}
	else
	{
		sum = N * (N - 1) / 2;
	}
	LL ans = sum - M;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
typedef long long LL;
const int INF = int(1e9);
 
double A,B,C,D,E,F;
double Ai,Bi;
double maxx1 = -1,maxx2 = 1;
 
int main()
{
    cin>>A>>B>>C>>D>>E>>F;
    Ai = A*E; Bi = B*E;
    double tan,kefan,sum;
 
    for(int a = 0;a*A*100<=F;a++)
    for(int b = 0;b*B*100<=F-a*A*100;b++)
    for(int c = 0;c*C<=F-a*A*100-b*B*100;c++)
    for(int d = 0;d*D<=F-a*A*100-b*B*100-c*C;d++)
    {
        tan = c*C+d*D;
        sum = A*a*100+B*b*100+tan;
        kefan = Ai*a+Bi*b;
        if(kefan<tan||sum>F)continue;
 
        if(sum!=0&&tan/sum>maxx2/maxx1){
            maxx1 = sum;
            maxx2 = tan;
        }
    }
    cout<<int(maxx1)<<" "<<int(maxx2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(time(NULL));

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20, bs = 29;

ll bc[300];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n;
	string st;
	cin >> n >> st;

	ll uno = 0, dos = 0, mult = 1;
	string mys = "";
	for(char el: st) {
		if(mys.empty()) {
			mys += el;
			uno++;
		} else if(mys.size() == 1) {
			if(el == mys[0]) {
				uno++;
			} else {
				mys += el;
				dos++;
				mult = mult * uno % MOD;
				uno--;
			}
		} else {
			if(mys.find(el) == string::npos) {
				mult = mult * dos % MOD;
				if(!--dos) {
					mys.pop_back();
					if(!uno) mys.pop_back();
				}
			} else if(el == mys[0]) {
				uno++;
			} else {
				if(!uno) swap(mys[0], mys[1]), uno++;
				else mult = mult * uno % MOD, uno--, dos++;
			}
		}
		//LOG << mys << ' ' << uno << ' ' << dos << ' ' << mult << '\n';
	}

	//LOG << mult << '\n';
	for(ll i = 1; i <= n; i++)
		mult = mult * i % MOD;
	cout << mult << '\n';
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define f(i,n) for(int i=0;i<n;i++)
#define r (i*10+q[j])
#define pa pair<int,int>
typedef long long ll;

bool cmp(pa a,pa b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

int main()
{
    vector<pa>t;
    vector<pa>::iterator it;
    int n,x,y;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>x>>y;
        t.push_back(pa(x,y));
    }
    sort(t.begin(),t.end(),cmp);
    int sum=0;
    for(it=t.begin();it!=t.end();it++)
    {
        sum+=it->first;
        if(sum>it->second)
        {
            cout<<"No";
            return 0;
        }
        /*cout<<it->first<<" "<<it->second<<endl;*/
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  long long t;
  long long sum = 0;
  long long i,j,h;
  long long m,n,k,g;
  long long a,b,c;

  scanf("%lld", &t);

  for(i = 1;i <= t;i++){
    for(j = 1;j <= t;j++){
      for(h = 1;h <= t;h++){
        a = i; b = j; c = h;

        if(a == 1 || b == 1 || c == 1){
          sum += 1;
          continue;
        }

        if(a == b && b == c){
          sum += a;
          continue;
        }

        if(a > b){
          m = a; n = b;
          do{
            k = m % n;
            m = n; n = k;
          }while(k != 0);
        }

        else{
          m = b; n = a;
          do{
            k = m % n;
            m = n; n = k;
          }while(k != 0);
        }

        if(m == 1){
          sum += 1;
          continue;
        }

        if(m == c){
          sum += c;
          continue;
        }

        if(m > c){
          g = m; n = c;
          do{
            k = g % n;
            g = n; n = k;
          }while(k != 0);
        }

        else{
          g = c; n = m;
          do{
            k = g % n;
            g = n; n = k;
          }while(k != 0);
        }

        sum += g;

      }
    }
  }

  printf("%lld\n", sum);
  return 0;
}


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

const int INF = 1001001001;

int main(){
	int a[3][3];
	rep(i,3)rep(j,3) cin >> a[i][j];
	int n;cin >> n;
	int b[n];
	rep(i,n) cin >> b[i];

	int x[3][3]={0};

	rep(i,3)rep(j,3)rep(k,n){
		if(a[i][j] == b[k]){
			x[i][j] = 1;
		}else{
			continue;
		}
	}
	int ans = 0;
	rep(i,3)if(x[i][0]==1&&x[i][1]==1&&x[i][2]==1) ans = 1;

	rep(j,3)if(x[0][j] ==1&& x[1][j]==1&&x[2][j]==1) ans = 1;

	if(x[0][0] == 1&&x[1][1]==1&&x[2][2]==1) ans = 1;

	if(x[0][2]==1&&x[1][1]==1&&x[2][0]==1) ans = 1;

	if(ans==0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
S=input()
leftblack=0
rightwhite=0
for i in range(0,N):
    if S[i]==".":
        rightwhite+=1
ans=leftblack+rightwhite
for i in range(0,N):
    if S[i]=='.':
        rightwhite-=1
    else:
        leftblack+=1
    test=leftblack+rightwhite
    if ans>test:
        ans=test

print(ans)


Measured memory_bytes: 40176
#include <iostream>
#include <vector>

int N, M, Q;
std::vector<int> a, b, c, d;

int dfs(std::vector<int>& A, int x) {
    if (A.size() == N) {
        int d_sum = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) d_sum += d[i];
        }
        return d_sum;
    }

    int res = 0;
    for (int i = x; i <= M; i++) {
        std::vector<int> v(A);
        v.push_back(i);
        res = std::max(res, dfs(v, i));
    }
    return res;
}

int main() {
    std::cin >> N >> M >> Q;

    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for (int i = 0; i < Q; i++) {
        std::cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    std::vector<int> v;
    std::cout << dfs(v, 1) << "\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<string> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}

	for (int i = 0; i < n; i++) {

		if (i != 0) {
			if (w[i][0] != w[i - 1].back()) {
				cout << "No" << endl;
				return 0;
			}
			for (int j = 0; j < i; j++) {
				if (w[i] == w[j]) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    int res = 0;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        v.push_back(t);
    }
    vector<int> c(1000001, 0);
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        int r = 0;
        bool skip = false;
        if (c[v[i]] == 0) {
            r++;
        } else {
            skip = true;
        }
        if (i > 0 && v[i - 1] == v[i]) {
            r = 0;
            skip = true;
        }
        if (i < n - 1 && v[i + 1] == v[i]) r = 0;
        if (skip) continue;
        int e = v[i];
        while (e <= 1000000) {
            c[e] = 1;
            e += v[i];
        }
        res += r;
    }
    cout << res << endl;
}


Measured memory_bytes: 7944
s = input()
t = input()
if len(s) == len(t):
  a = 0
  for i in range(len(t)):
    if s[i] == t[i]:
      a+=1
  print(len(s)-a)
  exit(0)
g = []
for i in range(len(s)-len(t)):
  n = 0
  for j in range(len(t)):
    if s[i+j]==t[j]:
      n+=1
  g.append(len(t)-n)
print(min(g))

Measured memory_bytes: 67788
# include <bits/stdc++.h>
# pragma GCC optimize("Ofast")

# define pb push_back
# define ll long long
# define fi first
# define se second
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
# define FILE

using namespace std;

const int N = 2e5 + 7;

string s;

int main()
{
    /// Author: Dilshod--Imomov
    speed;
    #ifdef FILEx
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // FILE
    cin >> s;
    string ans = "Yes";
    for ( int i = 1; i < s.size(); i += 2 ) {
        if ( s[i] == 'R' ) {
            ans = "No";
            break;
        }
    }
    for ( int i = 0; i < s.size(); i += 2 ) {
        if ( s[i] == 'L' ) {
            ans = "No";
            break;
        }
    }
    cout << ans;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		String[] Ain = br.readLine().split(" ");
		int[]A = new int[N+1];
		for(int a=0;a<N;a++) {
			A[a+1] = Integer.parseInt(Ain[a]);
		}
		
		int[]done = new int[N+1];
		
		int count = 0;
		for(int i = 1;i<N+1;i++) {
			if(done[i] == 0) {
				done[i] = 1;
				if(i == A[A[i]]) {
					count++;
					done[A[i]] = 1;
				}
			}
		}
		
		System.out.println(count);	
	}
}


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

using namespace std;

int main(void) {
  int N, i, tmp;
  int max, max_index, max2, max2_index;
  vector<int> A;
  cin >> N;
  cin >> tmp;
  max = tmp;
  max_index = 0;
  cin >> tmp;
  if(tmp > max) {
    max2 = max;
    max2_index = max_index;
    max = tmp;
    max_index = 1;
  } else {
    max2 = tmp;
    max2_index = 1;
  }
  for(i = 2; i < N; i++) {
    cin >> tmp;
    if(tmp >= max) {
      max2 = max;
      max2_index = max_index;
      max = tmp;
      max_index = i;
  	} else if(tmp >= max2) {
      max2 = tmp;
      max2_index = i;
  	}
    A.push_back(tmp);
  }
  for(i = 0; i < N; i++) {
    if(i != max_index) {
      cout << max << endl;
    } else {
      cout << max2 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2548
using System;

namespace abc139A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();
            string C = A.Substring(0, 1);
            string D = B.Substring(0, 1);
            string E = A.Substring(1, 1);
            string F = B.Substring(1, 1);
            string G = A.Substring(2, 1);
            string H = B.Substring(2, 1);
            int I = 0;
            if (C == D)
                I = I + 1;
            else
                I = I + 0;
            if (E == F)
                I = I + 1;
            else
                I = I + 0;
            if (G == H)
                I = I + 1;
            else
                I = I + 0;
            Console.WriteLine(I.ToString());
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main(){
string s;
cin >> s;
if(s[2]==s[3] && s[4]==s[5]){
cout << "Yes" << endl;
return 0;
}else{
cout << "No" << endl;
return 0;
}
}

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

int main(){
  string s;
  cin >> s;
  int ans=1000;
  
  for(int i=0;i<s.size()-2;i++){
    int a;
    a=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    ans = min(ans,abs(753-a));
  }
   
  
  cout << ans << endl;
  
}
    
    
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;

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

  return n*n;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b;a>=c;a--)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))
#define ctz(x) __builtin_ctz(x)
#define clz(x) __builtin_clz(x)
#define popcount(x) __builtin_popcount(x)
#define parity(x) __builtin_parity(x)

//=======binarysearch===========
int bs(vector<int>&a,int que){
 auto it=lower_bound(a.begin(),a.end(),que);
 if(*it==que){
    return it-a.begin();
 }
 return -1;
}
//========binarysearch=========


bool isprime(int x)
{
  if ( x == 2 ) return true;
  if ( x  < 2 ) return false;
  for ( int i = 2; i * i <= x; i++ )
    if ( x % i == 0 ) return false;


  if(x==0) return false;
  return true;
}


int main(){
  
  int a,b;

  cin>>a>>b;

  if(a*b==15){
    cout<<"*";
  }else if(a+b == 15){

    cout<<"+";
  }else if(a*b!= 15 && a+b!=15){
    cout<<"x";
  }



}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

const int N = 5e5 + 2;
int fact[N];
inline int mul(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a % mod * b % mod + mod) % mod;
}
inline int add(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a % mod + b % mod + mod) % mod;
}
inline int sub(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a % mod + b % mod + mod) % mod;
}
void initfact()
{
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i < N; i++)
    fact[i] = (fact[i - 1] % mod * i % mod) % mod;
}
int pwmd(int n, int m)
{
  int res = 1;
  while (m > 0)
  {
    if (m & 1)
      res = (res % mod * n % mod) % mod;
    m /= 2;
    n = (n % mod * n % mod) % mod;
  }
  return res;
}

int c(int n, int r)
{
  if (r > n)
    return 0;

  int ans = 1;
  ans = (ans % mod * fact[n] % mod) % mod;
  ans = (ans % mod * pwmd(fact[r], mod - 2) % mod) % mod;
  ans = (ans % mod * pwmd(fact[n - r], mod - 2) % mod) % mod;

  return ans;
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  initfact();
  int j = 1;
  int ans = 0LL;
  for (int i = 0; i <= n; i++)
  {
    ans = add(ans, mul(j, mul(c(n, i), mul(c(m - i, n - i), fact[n - i]))));
    j = -j;
  }
  cout << mul(ans, mul(c(m, n), fact[n]));
  return 0;
}


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

int main() {
	int N,A,B;
	cin >> N >> A >> B;
	if (A < B) {
		cout << A<<' ';
	}
	else cout << B<<' ';
	if (A+B<=N) {
		cout << 0;
	}
	else cout << A + B - N;
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        Console.WriteLine(getAns(k, a, b) ? "OK" : "NG");
    }
    static bool getAns(int k, int a, int b)
    {
        for (int i = a; i <= b; i++)
            if (i % k == 0) return true;
        return false;
    }
}


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

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int main() {
  string n;
  cin >> n;
  cout << stringcount(n, '2') << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;
typedef struct _data
{
	char s[3];
	int q;
} data;

int q_cmp(const void *a, const void *b)
{
	return ((data*)a)->q - ((data*)b)->q;
}

int main()
{
	char ac[3] = "AC";
	char wa[3] = "WA";
	int N, M;
	scanf("%d%d", &N, &M);
	data set[M+1];
	int i = 1;
	while (i <= M)
	{
		scanf("%d", &set[i].q);
		scanf("%s", set[i].s);
		i++;
	}
	// int n = sizeof(set) / sizeof(data);
	// qsort(set, n, sizeof(data), q_cmp);
	// printf("-------\n");
	i = 1;
	int log[N];
	int Wa[N];
	while (i <= N)
	{
		log[i] = i;
		Wa[i] = 0;
		i++;
	}
	int cnt = 0;
	int ans = 0;
	i = 1;
	while (i <= M)
	{
		if (log[set[i].q] != 0 && strcmp(set[i].s, ac) == 0)
		{
			cnt += Wa[set[i].q];
			log[set[i].q] = 0;
			ans++;
		}
		if (log[set[i].q] != 0 && strcmp(set[i].s, wa) == 0)
		{
			Wa[set[i].q]++;
		}
		i++;
	}
	printf("%d %d", ans, cnt);
	return (0);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k; cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	int ans=0;
	int dp[n][3];
	for(int i=0;i<n;i++){
		if(i==0){
			dp[i][0]=a[i][0]; dp[i][1]=a[i][1]; dp[i][2]=a[i][2];
		}else{
			dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
			dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
		}
		if(i==n-1){
			ans=max({dp[i][0],dp[i][1],dp[i][2]});
		}
	}
	cout<<ans<<endl;
	
}

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

int main() {
	string s;
  	cin >> s;
 if(s=="Sunny")cout << "Cloudy"<<endl;
  else if(s =="Cloudy")cout << "Rainy"<<endl;
  else if(s =="Rainy")cout << "Sunny"<<endl;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a!=1&&b!=1){
    cout << "1" << endl;
  }
  else{
    if(a!=2&&b!=2){
      cout << "2" << endl;
    }
    else{
      cout << "3" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3684
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
int n;
int main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int i;
	string s;
	cin>>s;
	int ans=0;
	for(i=0;i<s.size();i++)
	{
		ans=ans+(s[i]-'0');
	}
	if(ans%9==0)
		cout<<"Yes"<<endl;
	else 	
		cout<<"No"<<endl;
}


Measured memory_bytes: 3748
#[macro_use]
mod utils {
    macro_rules! input {
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }
    macro_rules! input_inner {
        ($next:expr) => {};
        ($iter:expr, ) => {};

        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
        ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }
    macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };
        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };
        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };
        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };
        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }
}

fn main() {
    input! {
        h:usize, w:usize, k:usize,
        s: [chars;h]
    }
    let s = {
        let mut x = vec![0; w];
        for i in 0..w {
            for j in 0..h {
                if s[j][i] == '1' {
                    x[i] |= 1 << j;
                }
            }
        }
        x
    };
    let mut res: Option<u32> = None;
    'AA: for i in 0..1 << h - 1 {
        let mut g = vec![0; h];
        for j in 0..h - 1 {
            g[j + 1] = g[j];
            if i >> j & 1 == 1 {
                g[j + 1] += 1;
            }
        }
        let mut sum = vec![0; h];
        let mut r = 0;
        for j in 0..w {
            let mut ss = vec![0; h];
            for p in 0..h {
                ss[g[p]] += s[j] >> p & 1
            }
            if *ss.iter().max().unwrap() > k {
                continue 'AA;
            }
            if ss.iter().zip(sum.iter()).any(|(a, b)| a + b > k) {
                r += 1;
                sum = ss;
            } else {
                for p in 0..h {
                    sum[p] += ss[p];
                }
            }
        }
        r += (i as u32).count_ones();
        res = Some(std::cmp::min(res.unwrap_or(r), r));
    }
    println!("{}", res.unwrap());
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var n = ReadInts()[0];
        var vals = ReadInts();
        int cnt = 0;
        var result = Coloc(ref cnt, vals);


        Console.WriteLine(result && cnt == n ? "Yes" : "No");
        Console.ReadLine();
    }

    static bool Coloc(ref int cnt, int[] vals)
    {
        vals = (int[])vals.Clone();
        Array.Sort(vals, IntDisComparetor.Instance);

        var slimes = new List<int>(vals.Length);
        slimes.Add(vals[0]);
        vals[0] = int.MaxValue;
        for (int slimeNum = 1; slimeNum < vals.Length;)
        {
            cnt++;
            var index = 0;
            for (int i = 0; i < slimeNum; i++)
            {
                var item = slimes[i];
                index = Utils.FindFirstIndex(vals, p => p < item, index + 1);
                if (index < 0)
                    return false;

                slimes.Add(vals[index]);
                vals[index] = int.MaxValue;
            }
            slimes.Sort(IntDisComparetor.Instance);
            slimeNum = slimes.Count;
        }
        return true;
    }

    #region Utils
    static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    #endregion
}

static class Utils
{
    public static int FindFirstIndex<T>(IList<T> source, Func<T, bool> func, int start)
    {
        for (int i = start; i < source.Count; i++)
        {
            if (func(source[i]))
            {
                var ret = source[i];
                return i;
            }
        }
        return -1;
    }
}

class IntDisComparetor : IComparer<int>
{
    public static IComparer<int> Instance { get; } = new IntDisComparetor();
    private IntDisComparetor()
    {

    }
    public int Compare(int x, int y)
    {
        return Comparer<int>.Default.Compare(y, x);
    }

}


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

int main(){
	int a;
	cin>>a;
	long long int sum = a;
	long long int cur = a;
	for(int i=0;i<2;i++){
		cur = cur*a;
		sum += cur;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
using namespace std;
#define ran 111111
int n,k;
vector<int> e[ran];
bool g[ran];int f[ran];

int L[ran],R[ran];bool ff[ran];
void dfs(int x,int fat){
	ff[x] = false;
	for(vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++){
		int y = *it;
		if(y == fat)continue;
		dfs(y,x);
		if(!ff[y])continue;
		if(!ff[x]){
			L[x] = L[y] - 1;
			R[x] = R[y] + 1;
			ff[x] = true;
		}else{
			if((bool)(L[x] % 2) != (bool)((L[y]-1) % 2)){
				puts("No");
				exit(0);
			}
			L[x] = max(L[x], L[y]-1);
			R[x] = min(R[x], R[y]+1);
			if(L[x] > R[x]){
				puts("No");
				exit(0);
			}
		}
	}
	if(g[x]){
		if(ff[x] && !(L[x] <= f[x] && f[x] <= R[x] && bool(f[x] % 2) == bool(L[x]%2))){
			puts("No");
			exit(0);
		}
		L[x] = R[x] = f[x];
		ff[x] = true;
	}
}
void dfs2(int x,int fat){
	f[x] = L[x];
	R[x] = L[x];
	for(vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++){
		int y = *it;
		if(y == fat)continue;
		if(!ff[y]){
			L[y] = L[x] - 1;
			R[y] = R[x] + 1;
			ff[y] = true;
		}else{
			L[y] = max(L[y], L[x] - 1);
			R[y] = min(R[y], R[x] + 1);
		}
		dfs2(y,x);
	}
}
int main(){
	int x,y;
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		g[i] = false;
	}
	for(int i=1; i<n; i++){
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	scanf("%d",&k);
	while(k--){
		scanf("%d%d",&x,&y);
		f[x] = y;
		g[x] = true;
	}
	dfs(1,1);
	dfs2(1,1);
	puts("Yes");
	for(int i=1; i<=n; i++)
		printf("%d\n",f[i]);
	return 0;
}

Measured memory_bytes: 14336
h, w = map(int, input().split())

ans = 0

if h==1 or w==1:
  ans += 1
elif h%2==1 and w%2==1:
  ans += (h//2+1)*(w//2+1)
  ans += (h//2)*(w//2)
elif h%2==0 and w%2==1:
  ans += (w//2+1)*h//2
  ans += (w//2)*(h//2)
elif h%2==1 and w%2==0:
  ans += (w//2)*(h//2+1)
  ans += (w//2)*(h//2)
else:
  ans += w*h//2

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,t,r=1;
  string s;
  cin>>n>>s;
  t=s.size();
  for(int i=1;i<t;++i){
    if(s[i]!=s[i-1])r++;
  }
  cout<<r;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()


Measured memory_bytes: 128880
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] d = nextIntArray(sc, N);

		sc.close();

		Arrays.sort(d);

		int arc = d[N / 2];
		int abc = d[N / 2 - 1];

		out.println(arc - abc);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


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

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

  int add, sub, mul, res;
  add = A + B;
  sub = A - B;
  mul = A * B;

  if(add > sub){
    res = add;
  } else {
    res = sub;
  }
  if(res < mul){
    res = mul;
  }

  cout << res << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> A(100001);
  rep(i, n) {
    int a; cin >> a;
    A[a]++;
  }

  int ans = 1;
  rep(i, 99999) ans = max(ans, A[i]+A[i+1]+A[i+2]);
  cout << ans << endl;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void){
    int n, k, temp, ans=0;
    scanf("%d %d", &n, &k);

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

    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            if(fruit[i]>fruit[j]){
                temp = fruit[i];
                fruit[i] = fruit[j];
                fruit[j] = temp;
            }
        }
    }

    for(int i=0; i<k; i++){
        ans += fruit[i];
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1736
import math
import heapq
xs,ys,xt,yt=map(int,input().split())
N=int(input())
x=[xs]+[0 for i in range(N)]+[xt]
y=[ys]+[0 for i in range(N)]+[yt]
r=[0]+[0 for i in range(N)]+[0]
for i in range(1,N+1):
    x[i],y[i],r[i]=map(int,input().split())
dist=[10**15 for i in range(N+2)]
dist[0]=0
adjlist=[[0 for i in range(N+2)] for j in range(N+2)]
for i in range(N+2):
    for j in range(N+2):
        if i==j:
            continue
        adjlist[i][j]=max(math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)-r[i]-r[j],0)
q=[]
heapq.heappush(q,(0,0))
while(len(q)>0):
    d,p=heapq.heappop(q)
    if dist[p]<d:
        continue
    for j in range(N+2):
        if p==j:
            continue
        cost=adjlist[p][j]
        if dist[j]>dist[p]+cost:
            dist[j]=dist[p]+cost
            heapq.heappush(q,(dist[j],j))
print(dist[N+1])

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

#define MAX_N 100000
#define MAX_PRIME 1299709

bool cache[MAX_PRIME+1];

void make_cache() {
    memset(cache, 1, sizeof(cache));
    cache[0] = cache[1] = false;
    for (int i = 2; i <= MAX_PRIME; i++) {
        if (cache[i]) {
            for (int j = i + i; j <= MAX_PRIME; j+=i) {
                cache[j] = false;
            }
        }
    }
}

int main() {
    make_cache();
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int gap;
        if (cache[n]) {
            gap = 0;
        } else {
            int l, r;
            int i;
            for (i = 0; !cache[n-i]; i++);
            l = n-i;
            for (i = 0; !cache[n+i]; i++);
            r = n+i;
            gap = r - l;
        }
        cout << gap << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	int N, k, p;
	int i, j;
	bool flag = 0;
	cin >> N;
	for(i = 0; i < N; ++i){
		cin >> k >> p;
		flag = 0;
		while(1){
			for(j = 1; j <= p; ++j){
				--k;
				if(k == 0){
					cout << j << endl;
					flag = 1;
					break;
				}
			}
			if(flag == 1) break;
		}	
	}
	return 0;
}

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

using namespace std;

int arr[200001];
int idx[200001];
set <int,greater<int>> s;
int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,t;
	vector <int> v;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	int num = 0;
	int Max = 0;
	for(int i=0;i<n;i++)
	{
		auto it = s.upper_bound(v[i]);
		if(it==s.end() || *it!=v[i]-1)
		{
			idx[v[i]] = num;
			arr[num++]+=1;
			s.insert(v[i]);
		}
		else
		{
			//cout << *it << ' ' << v[i] << '\n';
			int idx2 = idx[*it];
			arr[idx2]+=1;
			idx[v[i]] = idx2;
			s.erase(*it);
			s.insert(v[i]);
		}
	}

	for(int i=0;i<num;i++)
	{
		Max = max(Max,arr[i]);
	}

	cout << n - Max << '\n';

	return 0;
}

Measured memory_bytes: 12020