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

public class Main {

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

        final int n = sc.nextInt();
        final char[] cs = sc.next().toCharArray();

        long r = 0;
        long g = 0;
        long b = 0;
        for (char c : cs) {
            if (c == 'R') r++;
            if (c == 'G') g++;
            if (c == 'B') b++;
        }

        long all = r * g * b;

        long sub = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (cs[i] == cs[j]) continue;
                int k = j*2 - i;
                if (k >= n || cs[k] == cs[i] || cs[k] == cs[j]) continue;
                sub++;
            }
        }

        System.out.println(all-sub);
    }
}


Measured memory_bytes: 35988
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    Int A, B, N;
    cin>>A>>B>>N;

    //A = random()%100 + 1;
    //B = random()%100 + 1;
    //N = random()%100 + 1;

    auto calc=[&](Int x){return (A * x / B) - (A * (x/B));};

    Int ans = calc(N);
    if(B <= N) Max(ans, calc(B));
    if(B-1 <= N) Max(ans, calc(B-1));
    cout<<ans<<endl;

    return 0;
    /*
    Int mx = -INF;
    for(Int i=0;i<=N;i++){
      Int a = A * i / B;
      Int b = A * (i / B);
      pr(a, b, a - b, i, A * i, i/B);
      Max(mx, a - b);
    }
    pr(A, B, N, ans, mx);
    assert(mx == ans);
    */
  }

  return 0;
}


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

signed main(){
  string S;
  cin>>S;
  int N=S.size();
  rep(i,N){
    S.at(i)='x';
  }
  cout<<S<<endl;
}

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

int main(void){
   
   int N,K,sum=0;
   cin >> N >> K;
   int data[N];
   
   for(int i=0;i<N;i++) cin >> data[i];
   
   sort(data,data+N,greater<int>());
   
   for(int i=0;i<K;i++) sum += data[i];
   cout << sum << endl;
}

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

int main(){
	#ifdef LOCAL_DEFINE
		freopen("../a.in","r",stdin);
		freopen("../a.out", "w",stdout);
	#endif

	int N,M,C;
	cin >> N >> M >> C;
	int arrB[M];
	for(int i=0;i<M;i++){
		cin >> arrB[i];
	}
	int arr[N][M];
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			cin >> arr[i][j];
		}
	}
	int ans = 0;
	for(int i=0;i<N;i++){
		int temp = 0;
		for(int j=0;j<M;j++){
			temp += (arr[i][j]*arrB[j]);
		}
		temp += C;
		if(temp>0){
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <vector>

int main() {
  int V, E;
  scanf("%d%d", &V, &E);
  std::vector<std::vector<int>> edges(V, std::vector<int>());
  std::vector<int> cs(V, 0);
  for (int i = 0; i < E; i++) {
    int s, t;
    scanf("%d%d", &s, &t);
    edges[s].push_back(t);
    cs[t]++;
  }
  std::vector<int> todo;
  for (int v = 0; v < V; v++)
    if (cs[v] == 0)
      todo.push_back(v);
  while (todo.size()) {
    auto s = todo.back();
    todo.pop_back();
    for (auto&& t : edges[s])
      if (--cs[t] == 0)
        todo.push_back(t);
  }
  printf("%d\n", std::accumulate(cs.begin(), cs.end(), 0) > 0);
  return 0;
}

Measured memory_bytes: 2816
#include <iostream>
using namespace std;
int main(void){
    long long int n,a[110000],ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==1)ans++;
    }
    if(ans%2==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }
};

//--global--//



//----------//

ll calc(int n, int a, int b, int c, int *l, string out){
    if(out.find('0') != string::npos && out.find('1') != string::npos && out.find('2') != string::npos){
        ll res = 0;
        ll a2 = 0;
        ll b2 = 0;
        ll c2 = 0;
        rep(i, out.size()){
            if(out[i] == '0'){
                if(a2) res += 10;
                a2 += l[i];
            }
            else if(out[i] == '1'){
                if(b2) res += 10;
                b2 += l[i];
            }else if(out[i] == '2'){
                if(c2) res += 10;
                c2 += l[i];
            }
        }
        res += abs(a - a2) + abs(b - b2) + abs(c - c2);
        //cout << out << " -> " << res << endl;
        return res;
    }
    return LLINF;
}

ll solve(int n, int a, int b, int c, int *l, string out){

    if(out.size() == n){
        return calc(n, a, b, c, l, out);
    }

    ll res = LLINF;
    rep(i, 4){
        res = min(res, solve(n, a, b, c, l, out + to_string(i)));
    }
    return res;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int n, a, b, c;
    cin >> n >> a >> b >> c;
    int l[10];
    rep(i, n){
        cin >> l[i];
    }

    string tmp;
    cout << solve(n, a, b, c, l, tmp) << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    int n,k;
    cin>>n>>k;
    vector <int> good(n);
    while (k--)
    {
        int d;
        cin>>d;
        while (d--)
        {
            int x;
            cin>>x;
            x--;
            good[x]=1;
        }
    }
    int cnt=0;
    for (int i=0;i<n;i++)
    {
        if (good[i]==0)
            cnt++;
    }
    cout<<cnt;




}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,i;
	cin>>n;
	vector<ll> a(n);
	for(i=0;i<n;i++) cin>>a[i];
	ll tmp,ans = 1e10;
	for(i=1;i<=100;i++)
	{
	    tmp = 0;
	    for(auto e :a)
	    {
	        tmp+=((e-i)*(e-i));
	    }
	    ans = min(ans,tmp);
	}
	cout<<ans<<"\n";
}

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

h = list(map(int, input().split()))

INF = 1e5

dp = [INF] * n 

dp[0] = 0

dp[1] = abs( h[1] - h[0] )

for i in range(2, n):
	dp[i] = min( dp[i-2] + abs( h[i] - h[i-2] ), dp[i-1] + abs( h[i] - h[i-1] ) )

print(dp[n - 1])

Measured memory_bytes: 13980
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int len = String.valueOf(n).length();
    int res = 0;
    for (int i = 1; i < len; i += 2) {
      res += 9 * (int) Math.pow(10, i - 1);
    }

    if (len % 2 == 1) {
      res += n - (int) Math.pow(10, len - 1) + 1;
    }

    System.out.println(res);
  }
}

Measured memory_bytes: 21716
n = int(input()); arr = list(map(int,input().split()))

from collections import Counter
countdic = Counter(arr)
sumdic = dict()
sum = 0

for i in countdic:
    sumdic[i] = (countdic[i]**2-countdic[i])//2
    sum += (countdic[i]**2-countdic[i])//2

for i in arr:
    print(sum-sumdic[i]+(countdic[i]-1)*(countdic[i]-2)//2)

Measured memory_bytes: 32928
def solve(data,p):
    L=[]
    if data[p[1]-1][p[0]-1]=="1":
        data[p[1]-1]=data[p[1]-1][:p[0]-1]+"0"+data[p[1]-1][p[0]:]
        L+=p
    else:
        return []
    bakuhu=[(p[0]-3,p[1]),(p[0]-2,p[1]),(p[0]-1,p[1]),(p[0]+1,p[1]),(p[0]+2,p[1]),(p[0]+3,p[1]),(p[0],p[1]-3),(p[0],p[1]-2),(p[0],p[1]-1),(p[0],p[1]+1),(p[0],p[1]+2),(p[0],p[1]+3)]
    for i in range(len(bakuhu)):
        if bakuhu[i][0]>0 and bakuhu[i][1] >0 and bakuhu[i][0] <9 and bakuhu[i][1] <9:
            L.extend(solve(data,bakuhu[i]))
    return L
    
while True:
    try:
        ndata=input()
        for i in range(ndata):
            raw_input()
            data=[]
            for j in range(8):
                data.append(raw_input())
            x=input()
            y=input()
            p=(x,y)
            L=solve(data,p)
            while len(L)!=0:
                x=L.pop(0)
                y=L.pop(0)
                data[y-1]=data[y-1][:x-1]+'0'+data[y-1][x:]
            print "Data "+str(i+1)+':'
            for i in range(len(data)):
                print data[i]
    except:
        break

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

int main()
{
    int n;
    cin >> n;
    int a[n], b[n];
    int s = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    s += a[0];
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        s += b[i];
    }
    int max = s;
    for (int i = 1; i < n; i++) {
        s = s + a[i] - b[i - 1];
        if (s > max) {
            max = s;
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.length();
    ll c = 0,c2 = 0;
    rep(i,n){
        if (s[i] == s[n-1]){
            s += s[i];
            c++;
        }
        else{
            break;
        }
    }
    rep(i,n){
        if (s[n-i-1] == s[n-1]) c2++;
        else break;
    }
    if (c == n){
        PRINT(k*n/2);
        return 0;
    }
    ll ans = 0,a = 1;
    rep(i,s.length()-1){
        if (s[i] == s[i+1]){
            a++;
        }
        else{
            ans += a/2;
            a = 1;
        }
    }
    ans += a/2;
    ans -= c/2;
    ans *= k;
    ans = ans-(c+c2)/2+c2/2+c/2;
    PRINT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}




 
    
void test_case() {

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

    vecl arr(k);
    rep(i,k) {
        cin>>arr[i];
    }

    sort(all(arr));

    ll ans = n;
    ll d1, d2;
    for(int i=0; i<k; i++) {
        if(i==0) {
            d1 = 0;
            d2 = arr[0] - arr[1]; 
        } else if(i==k-1) {
            d1 = arr[k-1] - arr[k-2];
            d2 = 0;
        } else {
            d1 = arr[i] - arr[i+1];
            d2 = arr[i] - arr[i-1];
        }

        ans = min(ans, n - abs(d1));
        ans = min(ans, n- abs(d2));

        // if(ans == 5) {
        //     cout<<i<<endl;
        // }
    }

     ans = min(ans, arr[k-1] - arr[0]);

    cout<<ans<<endl;


}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

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

template<typename T>
T gcd(T a, T b)
{
	return b ? gcd(b, a%b) : a;
}

template<typename T>
T lcm(T a, T b)
{
	return a / gcd(a, b) * b;
}

//(a^e)%mod
template<typename T>
T power(T a, T e, T mod)
{
	if(e == 0)
	{
		return 1;
	}
	if(e % 2 != 0)
	{
		//a^e=a^(e-1)*a
		return (power(a, e - 1, mod) * a) % mod;
	}
	T res = power(a, e / 2, mod);
	//a^e=a^(e/2)*a^(e/2)
	return (res * res) % mod;
}

template<typename T>
class Tree
{
private:
public:
	T data;
	Tree* parent = NULL;
	std::vector<Tree*> children;
	void setData(T x)
	{
		data = x;
	}
	void setParent(Tree* t)
	{
		parent = t;
	}
	void addChild(Tree* t)
	{
		children.push_back(t);
	}
	Tree* getParent()
	{
		return parent;
	}
	T getData()
	{
		return data;
	}
	Tree(){}
	~Tree(){}
	
};

int main()
{
	using namespace std;
	Tree<int> t[100001];
	int n, k, e, index;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> index >> k;
		t[index].setData(index);
		for (int j = 0; j < k; ++j)
		{
			cin >> e;
			t[e].setParent(&t[index]);
			t[index].addChild(&t[e]);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << "node " << i << ": parent = ";
		if(t[i].getParent() != NULL)
		{
			cout << (t[i].getParent())->getData();
		}
		else
		{
			cout << -1;
		}
		cout << ", depth = ";
		int count = 0;
		for (auto a = t[i].getParent(); a != NULL; a = a->getParent())
		{
			++count;
		}
		cout << count << ", ";
		if(count == 0)
		{
			cout << "root";
		}
		else if((t[i].children).size() == 0)
		{
			cout << "leaf";
		}
		else
		{
			cout << "internal node";
		}
		cout << ", [";
		for (int j = 0; j < t[i].children.size(); ++j)
		{
			cout << (t[i].children[j]->getData());
			if(j < t[i].children.size()-1)
			{
				cout << ", ";
			}
		}
		cout << "]" << endl;
	}
	return 0;
}



Measured memory_bytes: 8272
#include <stdio.h>
int main(void)
{
	int i,j,h,w;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0){
			break;
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i==0||i==h-1){
					printf("#");
				}
				else if(j==0||j==w-1){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int N, K, Q;
vector<int> A;


int main()
{
	cin >> N;
	cin >> K;
	cin >> Q;

	A = vector<int>(Q);

	vector<int> sc = vector<int>(N+1,0);


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

		cin >> A.at(i);
		sc.at(A.at(i))++;
	}


	for (int i = 1; i < N+1; i++) {

		cout << (( K - Q + sc.at(i) <= 0 ) ? "No" : "Yes") << endl;
 	}


	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxn = 2000;
int n, m, fa[maxn + 3], dep[maxn + 3], u[maxn + 3], v[maxn + 3], w[maxn + 3], ans;
int b[maxn + 3][maxn + 3], g[maxn + 3][2], tot, lft[maxn + 3], rht[maxn + 3], wei[maxn + 3];
bool vis[maxn + 3], res[maxn + 3];
vector<int> G[maxn + 3], D[maxn + 3], V[maxn + 3];
vector<pii> S[maxn + 3];

void add(int u, int v) {
	G[u].push_back(v);
}

void dfs(int u, int pa = 0) {
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == pa) continue;
		dep[v] = dep[u] + 1;
		fa[v] = u;
		dfs(v, u);
	}
}

void add_lim(int u, int v, int w) {
	lft[++tot] = u, rht[tot] = v, wei[tot] = w;
}

void solve(int u, int pa = 0) {
	g[u][0] = g[u][1] = -1;
	for (int i = 1; i <= m; i++) {
		b[u][i] = -1;
	}
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == pa) continue;
		solve(v, u);
		for (int j = 1; j <= m; j++) {
			if (b[u][j] == -1) {
				b[u][j] = b[v][j];
			}
		}
	}
	for (int i = 0; i < S[u].size(); i++) {
		pii x = S[u][i];
		if (x.se >= 0) {
			b[u][x.fi] = x.se;
		} else {
			b[u][x.fi] = -1;
		}
	}
	/*
	puts("-----");
	printf("%d\n", u);
	for (int i = 1; i <= m; i++) {
		printf("%d %d\n", i, b[u][i]);
	}
	*/
	int cnt = 0;
	for (int i = 1; i <= m; i++) {
		cnt += b[u][i] != -1;
	}
	if (cnt < 2) {
		ans += cnt;
	} else {
		ans += 2;
		int p = 0;
		for (int i = 0, v; i < G[u].size(); i++) {
			v = G[u][i];
			if (v == pa) continue;
			if (g[v][0] == -1) continue;
			if (~b[u][g[v][0]] && ~b[u][g[v][1]]) {
				p = v;
				break;
			}
		}
		if (p) {
			g[u][0] = g[p][0];
			g[u][1] = g[p][1];
		} else {
			int x = 0, y = 0;
			for (int i = 1; i <= m; i++) {
				if (b[u][i] == -1) continue;
				if (!x) {
					x = i;
				} else if (x && !y) {
					y = i;
				}
			}
			g[u][0] = x, g[u][1] = y;
			// printf("! %d %d %d\n", u, x, y);
			add_lim(x, y, b[u][x] ^ b[u][y] ^ 1);
		}
	}
}

void color(int u) {
	vis[u] = true;
	for (int i = 0, v; i < D[u].size(); i++) {
		v = D[u][i];
		if (vis[v]) continue;
		res[v] = res[u] ^ V[u][i];
		color(v);
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d %d", &u, &v);
		add(u, v), add(v, u);
	}
	dfs(1);
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &u[i], &v[i]);
		int x = u[i], y = v[i];
		while (x != y) {
			if (dep[x] < dep[y]) swap(x, y);
			x = fa[x];
		}
		w[i] = x;
		if (u[i] != w[i]) {
			S[u[i]].pb(mp(i, 0));
		}
		if (v[i] != w[i]) {
			S[v[i]].pb(mp(i, 1));
		}
		S[w[i]].pb(mp(i, -1));
	}
	solve(1);
	printf("%d\n", ans);
	/*
	puts("----------");
	printf("%d\n", tot);
	for (int i = 1; i <= tot; i++) {
		printf("%d %d %d\n", lft[i], rht[i], wei[i]);
	}
	*/
	for (int i = 1; i <= tot; i++) {
		D[lft[i]].pb(rht[i]), V[lft[i]].pb(wei[i]);
		D[rht[i]].pb(lft[i]), V[rht[i]].pb(wei[i]);
	}
	for (int i = 1; i <= m; i++) {
		if (!vis[i]) color(i);
	}
	for (int i = 1; i <= m; i++) {
		if (!res[i]) {
			printf("%d %d\n", u[i], v[i]);
		} else {
			printf("%d %d\n", v[i], u[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 16384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int mod = 1e9 + 7;

long long f(int N, int p) {
    int cnt = 0;
    int P = p;
    while (P <= N) {
        cnt += N / P;
        P *= p;
    }
    return cnt;
}

int main() {
    int N;
    cin >> N;
    
    vector<bool> prime(N + 1, true);
    prime[1] = false;
    for (int i = 2; i * i <= N; ++i) {
        if (!prime[i]) continue;
        for (int j = 2; i * j <= N; ++j) prime[i * j] = false;
    }
    vector<int> P;
    for (int i = 1; i <= N; ++i) {
        if (prime[i]) P.push_back(i);
    }
    
    long long ans = 1;
    rep(i, P.size()) {
        ans *= f(N, P[i]) + 1;
        ans %= mod;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring> 
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
#define N 200006
int n,tmp,ans;char s[N];
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='I')tmp++;else tmp--;
		ans=max(ans,tmp);
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int d, n; cin >> d >> n;
    vector<int> t(d);
    for(int i = 0; i < d; i++) cin >> t[i];
    vector<int> a(n);   
    vector<int> b(n);   
    vector<int> c(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    
    vector<vector<int> > dp(d + 1, vector<int> (n, -1));
    for(int j = 0; j < n; j++){
        if(a[j] <= t[0] && t[0] <= b[j]) dp[0][j] = 0;

    }

    for(int i = 0; i < d - 1; i++){
        for(int j = 0; j < n; j++){
            if(dp[i][j] == -1) continue;

            for(int k = 0; k < n; k++){
                if(a[k] <= t[i + 1] && t[i + 1] <= b[k]){
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + (int)abs(c[j] - c[k]));
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++) ans = max(ans, dp[d - 1][i]);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3204
def f():
 from heapq import heappop, heappush
 N=int(input())
 r=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  r[a-1]+=3*(c>d)+(c==d)
  r[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[r[i]]+=[i]
 pq = []
 for i, s in enumerate(r):heappush(pq,[-s,i])
 rank=1
 display_rank=1
 prev_score=float('inf')
 while pq:
  s,i=heappop(pq)
  if s!=prev_score:rank=display_rank
  r[i]=rank
  display_rank+=1
  prev_score=s
 print(*r,sep='\n')
f()


Measured memory_bytes: 5716
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

int main()
{
    string s;
    cin >> s;
    stack<char> st;
    bool ans = true;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'w' && st.size() > 1 && st.top() == 'e' && (i == s.length() - 1 || s[i + 1] != 'm')){
            st.pop();
            st.pop();
        } else {
            st.push(s[i]);
        }
        if(st.empty() && i < s.length() - 1){
            ans = false;
        }
    }
    if(!st.empty()) ans = false;
    if(ans) cout << "Cat" << endl;
    else cout << "Rabbit" << endl;
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
const long long MOD = 1e9+7;
const long long INF = 1e15;
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    ll K = 0;
    ll pos = 0;
    string tmp;
    tmp = S[0];
    K++;
    pos++;
    while(pos < N){
        if(pos == N-1 && tmp.size() == 1 && S[pos] == tmp[0]) break;
        else if(tmp.size() == 1){
            if(S[pos] != tmp[0]) K++, tmp = S[pos], pos++;
            else{
                K++; 
                string a, b;
                a = S[pos];
                b = S[pos+1];
                tmp = a+b;
                pos += 2; 
            }
        }
        else K++, tmp = S[pos], pos++;
    }
    cout << K << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        int index = 0;
        int count = 0;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while ((line = br.readLine()) != null) {
            if (index == 0) {
                index = Integer.parseInt(line);
            } else {
                int[] array = new int[index];
                java.util.StringTokenizer st = new StringTokenizer(line, " ");
                while (st.hasMoreTokens()) {
                    array[count] = Integer.parseInt(st.nextToken());
                    count++;
                }
                for (int i = (count - 1); i >= 0; i--) {
                    System.out.print(array[i]);
                    if (i != 0) {
                        System.out.print(" ");
                    }
                }

                break;

            }

        }
        System.out.println("");
    }

}



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

import sys

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

A, B = MAP()

print(max(A - B*2, 0))


Measured memory_bytes: 3064
import java.util.Scanner

fun main(args: Array<String>) {
    val (sx, sy, tx, ty) = Scanner(System.`in`).use<Scanner, List<Int>> {
        listOf(it.nextInt(), it.nextInt(), it.nextInt(), it.nextInt())
        // −1000≦sx<tx≦1000
        // −1000≦sy<ty≦1000
    }
    val x = tx - sx
    val y = ty - sy

    //上にy右にx 下にy左にx 左に1上にy+1右にx+1下に1 右に1下にy+1左にx+1上に1
    val result = CharArray(y, {'U'}) + CharArray(x, {'R'}) +
            CharArray(y, {'D'}) + CharArray(x, {'L'}) +
            'L' + CharArray(y + 1, {'U'}) + CharArray(x + 1, {'R'}) + 'D' +
            'R' + CharArray(y + 1, {'D'}) + CharArray(x + 1, {'L'}) + 'U'

    println(result)
}

Measured memory_bytes: 20420
/*
 
*/ 
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 1e3+5, INF = 1e9;
int h, w, ans = 0;
int startRow, startCols, destRow, destCols; 
char board[MAXN][MAXN];
int dp[MAXN][MAXN];
bool visited[MAXN][MAXN];
int dRow[4] = {0, 0, -1, 1};
int dCols[4] = {1, -1, 0, 0};
vector<pi> visnow, sources;

bool Valid(int row, int cols)
{
    return (row >= 0 && row < h && cols >= 0 && cols < w && !visited[row][cols] && board[row][cols] == '.');
}

void DFS_1(int row, int cols)
{
    visited[row][cols] = true;
    visnow.push_back({row, cols});
    for(int i = 0; i < 4; ++i)
    {
        int nxtRow = row + dRow[i];
        int nxtCols = cols + dCols[i];
        if(Valid(nxtRow, nxtCols))
        {
            DFS_1(nxtRow, nxtCols);
        }
    }
}

void DFS_2(int row, int cols)
{
    for(int i = -2; i <= 2; ++i)
    {
        for(int j = -2; j <= 2; ++j)
        {
            int nxtRow = row + i;
            int nxtCols = cols + j;
            if(Valid(nxtRow, nxtCols))
            {
                sources.push_back({nxtRow, nxtCols});
            }
        }
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // FOR QUERY PROBLEM DON'T FORGET TO UNCOMMENT THIS
    cin >> h >> w >> startRow >> startCols >> destRow >> destCols;
    --startRow; --startCols; --destRow; --destCols;
    for(int i = 0; i < h; ++i)
    {
        for(int j = 0; j < w; ++j)
        {
            cin >> board[i][j];
        }
    }

    sources.reserve(h*w+5); sources.push_back({startRow, startCols});
    visnow.reserve(h*w+5);
    while(true)
    {
        visnow.clear();
        for(auto& v : sources)
        {
            DFS_1(v.first, v.second);
        }

        if(visited[destRow][destCols])
        {
            cout << ans << "\n";
            return 0;
        }

        ++ans;
        sources.clear();
        for(auto& v : visnow)
        {
            //cout << "Expanding from " << v.first << " " << v.second << "\n";
            DFS_2(v.first, v.second);
        }
        if(sources.empty())
        {
            break;
        }
    }
    cout << "-1\n";
    return 0;
}
 
/*
 
*/  

Measured memory_bytes: 9804
# coding: utf-8

N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

def dfs(cur=0, a=0, b=0, c=0):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else float('inf')
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return(min(ret0, ret1, ret2, ret3))

print(dfs())

Measured memory_bytes: 3064
N, X = gets.chomp.split.map(&:to_i)

$a, $p = [1], [1]

N.times do |i|
  $a << $a[i] * 2 + 3
  $p << $p[i] * 2 + 1
end

# p $a
# p $p
# $count = 0
def f(n, x)
  # $count += 1
  if n == 0
    x <= 0 ? 0 : 1
  elsif x <= 1
    0
  elsif 1 < x && x <= 1 + $a[n - 1]
    f(n - 1, x - 1)
  elsif x == 2 + $a[n - 1]
    $p[n - 1] + 1
  elsif 2 + ($a[n - 1]) < x && x <= 2 + 2 * $a[n - 1]
    $p[n - 1] + 1 + f(n - 1, x - 2 - $a[n - 1])
  else
    2 * $p[n - 1] + 1
  end
end

puts f(N, X)

# puts "count:#{$count}"


Measured memory_bytes: 1788
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18;
const int inf = 2e9;
const int nmax = 2e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

const int N = nmax;
ll tree[4*N], lazy[4*N], ashol[4*N];
ll doshpowmod[nmax];
int n;

void init() {
    memset(tree,0,sizeof tree);
    memset(lazy,0,sizeof lazy);
}

void build (int cn,int b,int e) {
    if (b == e) {
        tree[cn] = doshpowmod[n-b];
        ashol[cn] = tree[cn];
        return;
    }
    int lc = 2*cn, rc = lc+1, mid = (b+e)/2;
    build(lc,b,mid);
    build(rc,mid+1,e);
    tree[cn] = tree[lc] + tree[rc];
    ashol[cn] = ashol[lc] + ashol[rc];
    tree[cn]%=mod, ashol[cn]%=mod;
}

void relax (int cn, int b, int e) {
    if (lazy[cn]) {
        tree[cn] = 1LL*lazy[cn]*ashol[cn] %mod;
        if (b != e) {
            lazy[2*cn] = lazy[cn] ;
            lazy[2*cn + 1] = lazy[cn] ;
        }
        lazy[cn] = 0;
    }
}

void upd (int cn, int b, int e, int i, int j, int add) {
    relax(cn,b,e);
    if (b > j or e < i) {
        return;
    }
    int lc = 2*cn , rc = lc + 1 , mid = (b+e)/2;
    if (b >= i and e <= j) {
        lazy[cn] = add;
        relax(cn,b,e);
        return;
    }
    upd(lc,b,mid,i,j,add);
    upd(rc,mid+1,e,i,j,add);
    tree[cn] = tree[lc] + tree[rc];
    tree[cn]%=mod;
}

ll query (int cn, int b, int e, int i, int j) {
    relax(cn,b,e);
    if (b > j or e < i) return 0;
    if (b >= i and e <= j) {
        return tree[cn];
    }
    int lc = 2*cn, rc = lc + 1, mid = (b+e)/2;
    return ( query(lc,b,mid,i,j) + query(rc,mid+1,e,i,j) ) % mod;
}

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

    doshpowmod[0] = 1;
    for(int i=1; i<nmax; i++)
        doshpowmod[i] = 1LL*doshpowmod[i-1]*10%mod;

    cin>>n;
    build(1,1,n);
    int q;
    cin>>q;
    while(q--){
        int L,R,d;
        cin>>L>>R>>d;
        upd(1,1,n, L, R, d);
        cout<<query(1,1,n,1,n)<<"\n";
    }
}
/*
*/


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

using namespace std;
int a[100000];
int n, b = 0, c = 0, x = 1;
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int j = 0; j < n - 1; j++){
		if(a[j] < a[j + 1]){
			if(c > 0){ 
				c = 0; 
				x++;
			}
			else{
				b++;
			}
		}
		if(a[j] > a[j + 1]){
			if (b > 0){
				b = 0; 
				x++;
			}
			else{
				c++; 
			}
		}
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 640
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
S = S.replace("BC", "X")  # BC->X
S = S.replace("B", "C")  # BCという連続になってない、[AX]の連続区間のB,Cは区切りとなる。区切り文字を"C"にまとめる

L = S.split("C")
ans = 0
# 区切り文字で分割して、それぞれを見て転倒数を数えていく
for l in L:
    X_num = l.count('X')
    for c in l:
        if c == "X":
            X_num -= 1
        else:
            ans += X_num
print(ans)


Measured memory_bytes: 5540
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int n;
    cin >> n;
    if(n >= 1 && n <= 999){
        cout << "ABC" << endl;
    }
    if(n >= 1000 && n <= 1999){
        cout << "ABD" << endl;
    }
}

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

// @author: pashka

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

    int h1, s1, h2, s2;
    cin >> h1 >> s1 >> h2 >> s2;

    while (true) {
        h2 -= s1;
        if (h2 <= 0) {
            cout << "Yes";
            return 0;
        }
        h1 -= s2;
        if (h1 <= 0) {
            cout << "No";
            return 0;
        }
    }

    return 0;
}

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

int main() {
  int N,now = 1,nowc,ans = 0;
  cin >> N;
  int a[N + 1];

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

  while(1){
    if(a[now] == 0){
      ans = -1;
      break;
    }
    nowc = now;
    now = a[nowc];
    ans++;
    if(now == 2)break;
    a[nowc] = 0;
  }
  
  cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define eb push_back
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	string A, B, C;
	cin >> A >> B >> C;

	string next;
	next.push_back( A[ 0 ] );

	int a{}, b{}, c{};
	while( true )
	{
		if( next == "a" )
		{
			if( A.empty() )
			{
				cout << "A" << endl;
				break;
			}
			next = *A.begin();
			A.erase( A.begin() );
			a++;
		}
		if( next == "b" )
		{
			if( B.empty() )
			{
				cout << "B" << endl;
				break;
			}
			next = *B.begin();
			B.erase( B.begin() );
			b++;
		}
		if( next == "c" )
		{
			if( C.empty() )
			{
				cout << "C" << endl;
				break;
			}
			next = *C.begin();
			C.erase( C.begin() );
			c++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    ll sum=0;
    for(int i=0;i<s.size();i++){
        sum += s[i]-'0';
    }

    if(sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
bool isp(string s)
{
   string t = s;
   reverse(all(t));
   return (s==t);
}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   string str;
    cin>>str; int n = str.length();
    if(n%2 == 0)
    {
         cout << "No";return 0;
    }
   string f = str.substr(0,n/2);  //cout << f <<" " ;
   string s = str.substr((n/2)+1,n/2); //cout << s ;
   if(isp(str) && isp(f) && isp(s))cout << "Yes";
   else cout << "No";


   return 0;
}     

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];

    sort(all(l));

    int cnt = 0;
    rep(i, n-2){
        for(int j = i+1; j < n-1; ++j){
            for(int k = j+1; k < n; ++k){
                if(l[i] + l[j] > l[k]){
                    ++cnt;
                }
                if(l[i] + l[j] <= l[k]){
                    break;
                }
            }
        }
    }

    cout << cnt << endl;

return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{   int a,b,c,d;
    cin>>a>>b>>c>>d;
      if(max(b,d)-max(a,c)-abs(b-d)>0)
      cout<<max(b,d)-max(a,c)-abs(b-d)<<"\n";
      else
      cout<<0<<"\n";
    return 0;
    
    
    
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  string s, t;

  cin >> s >> t;

  s = s + s;

  for(int i=0; i<s.size()/2; i++) {
    if(s.substr(i, t.size()) == t) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
	for (int i = 1; i <= 9; i++){
		for (int j = 1; j <= 9; j++){
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}

	return 0;
}

Measured memory_bytes: 1096
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
 
int main(int argc, char* argv[])
{
  int N;
  std::cin >> N;
 
  std::vector<int> A, B;
  A.resize(N);
  B.resize(N);
 
  for (auto& a : A) {
    std::cin >> a;
  }
  for (auto& b : B) {
    std::cin >> b;
  }
 
  std::vector<int> ok;
  ok.reserve(N);
  long long ng_sum = 0LL;
  int ng_count = 0;
  for (int i = 0; i < N; ++i) {
    const auto diff = A[i] - B[i];
    if (diff < 0) {
      ng_sum += -diff;
      ++ng_count;
    }
    else if (0 < diff) {
      ok.push_back(diff);
    }
  }
 
  std::sort(ok.begin(), ok.end());

  int result = ng_count;
  for (auto it =  ok.rbegin(), it_end = ok.rend(); it != it_end; ++it) {
    if (ng_sum <= 0) break;
    ng_sum -= *it;
    ++result;
  }
 
  if (ng_sum <= 0) std::cout << result;
  else std::cout << -1;
 
  return 0;
}

Measured memory_bytes: 1280
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)

vector<vector<int>> warshallFloyd(int n, vector<int>a, vector<int>b, vector<int>c) {
	// n : グラフのノードの数
	const int C_LIMIT = (int)INT_MAX/2;//100001;
	int m = c.size();
	vector<vector<int>> d = vector<vector<int>>(n, vector<int>(n, C_LIMIT));
	for (int i = 0; i < n; i++) d[i][i] = 0;
	for (int i = 0; i < m; i++) {
		d[a[i] - 1][b[i] - 1] = d[b[i] - 1][a[i] - 1] = c[i];
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	return d;

}



int main() {
	int N, M, R;
	cin >> N >> M >> R;
	vector<int>r(R, 0);
	vector<int>a(M, 0);
	vector<int>b(M, 0);
	vector<int>c(M, 0);
	rup(i, 0, R) cin >> r[i];
	rup(i, 0, M) cin >> a[i] >> b[i] >> c[i];
	vector<vector<int>> d = warshallFloyd(N, a, b, c);
	sort(r.begin(), r.end());
	long long minv = INT_MAX;

	do {
		long long sum = 0;
		for (int j = 1; j < r.size();j++){
			sum += d[r[j - 1] - 1][r[j] - 1];
		}
		minv = min(minv, sum);
	} while (next_permutation(r.begin(), r.end()));

	
	cout << minv<<endl;

	return 0;
}





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

using namespace std;

#define int long long 
#define double long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007 

int32_t main()
{
	int arr[1005],n,k;
	
	cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> arr[i];
	sort(arr+1,arr+n+1);
	int sum = 0;
	for(int i = 1; i <= k; i++)
	{
		sum+=arr[i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3592