akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    string s;
    cin>>n>>s;
    if(n<3){
        cout<<0<<endl;
        return 0;
    }
    deque<pair<char,int>> p;
    int r=0, g=0, b=0;
    for(int i=n-1; i>=0; --i){
        char c=s[i];
        if(c=='R'){
            r++;
            p.push_front({c,r});
        }
        if(c=='G'){
            g++;
            p.push_front({c,g});
        }
        if(c=='B'){
            b++;
            p.push_front({c,b});
        }
    }
    ll a;
    ll ans=0;
    rep(i,n-2){
        for(int j=i+1; j<n-1; ++j){
            if(s[i]=='R' && s[j]=='G'){
                for(int k=j+1; k<n; ++k){
                    if(s[k]=='B'){
                        a=p[k].second;
                        if(s[j*2-i]=='B' && j*2-i<n) a--; //範囲外参照大丈夫か？
                        ans+=a;
                        break;
                    }
                }
            }
            if(s[i]=='G' && s[j]=='R'){
                for(int k=j+1; k<n; ++k){
                    if(s[k]=='B'){
                        a=p[k].second;
                        if(s[j*2-i]=='B' && j*2-i<n) a--; //範囲外参照大丈夫か？
                        ans+=a;
                        break;
                    }
                }
            }
            if(s[i]=='R' && s[j]=='B'){
                for(int k=j+1; k<n; ++k){
                    if(s[k]=='G'){
                        a=p[k].second;
                        if(s[j*2-i]=='G'  && j*2-i<n) a--; //範囲外参照大丈夫か？
                        ans+=a;
                        break;
                    }
                }
            }
            if(s[i]=='B' && s[j]=='R'){
                for(int k=j+1; k<n; ++k){
                    if(s[k]=='G'){
                        a=p[k].second;
                        if(s[j*2-i]=='G'  && j*2-i<n) a--; //範囲外参照大丈夫か？
                        ans+=a;
                        break;
                    }
                }
            }
            if(s[i]=='B' && s[j]=='G'){
                for(int k=j+1; k<n; ++k){
                    if(s[k]=='R'){
                        a=p[k].second;
                        if(s[j*2-i]=='R'  && j*2-i<n) a--; //範囲外参照大丈夫か？
                        ans+=a;
                        break;
                    }
                }
            }
            if(s[i]=='G' && s[j]=='B'){
                for(int k=j+1; k<n; ++k){
                    if(s[k]=='R'){
                        a=p[k].second;
                        if(s[j*2-i]=='R' && j*2-i<n) a--; //範囲外参照大丈夫か？
                        ans+=a;
                        break;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
int n;
/**/
int main()
{
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    read(n);
    for(int i=1;i<=9;i++)
    {
        if(n%i==0)
        {
            int x=n/i;
            if(x>=1&&x<=9)
            {
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}

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

namespace TemplateAlgorithm
{
    class Program
    {
        public const long Inf = (long)1e18;
        public const double eps = 1e-6;
        public const string alfa = "abcdefghijklmnopqrstuvwxyz";
        public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const int MOD = 1000000007;


        static void Main(string[] args)
        {
            int n = IO.ReadInt();
            var a  = IO.ReadIntArr();
            
            var d = a.Where((pi, i) => pi != i + 1).Count();
            Console.WriteLine(d == 0 || d == 2 ? "YES" : "NO");
        }

        static int ToInt(char c) => c - '0';

        #region MIN,MAX

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

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

    #region IO

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

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

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

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

        public static void Cout<T>(T value) => WriteLine(value);
        public static void CoutJoin<T>(T[] values, string separator = " ") => Cout(string.Join(separator, values));
    }

    #endregion    
}


Measured memory_bytes: 13268
def main():
    n, k = map(int, input().split())
    r = [0 for _ in range(k)]
    for i in range(1, n + 1):
        r[i % k] += 1
    answer = 0
    for i in range(k):
        if 2 * (k - i) % k == 0:
            answer += r[i] * (r[k - i if i > 0 else 0] ** 2)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 4632
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;
const int INF = 100000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    for(double a1, a2, b1, b2, c1, c2;cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;){
        double x, y;
        bool swp = false;
        b2 -= b1 * (a2 / a1);
        c2 -= c1 * (a2 / a1);
        y = c2 / b2;
        x = (c1 - y * b1) / a1;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;   
}

Measured memory_bytes: 1236
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int n;
int a[N], b[N];
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i ++){
		scanf("%d", &a[i]);
		b[i] = a[i];
	}	
	sort(b, b+n);
	int ans = 0;
	for(int i = 0; i < n; i ++){
		ans += ((lower_bound(b, b+n, a[i]) - b) ^ i) & 1;
	}
	printf("%d\n", ans >> 1);
} 

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int inf=2e9;
const int maxn=2e5+5;

int n;
int a[maxn],b[maxn];

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    b[n-1]=a[n-1];
    for(int i=n-2;i>=0;--i) b[i]=max(b[i+1],a[i]);
    int ans=-inf;
    for(int i=0;i+1<n;++i){
        ans=max(ans,b[i+1]-a[i]);
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
 
  cin >> a;
  cin >> b;
 
  	if (a > b) {
      cout << a + (a-1) << endl;
    }
	if (a == b) {
      cout << a + b << endl;
    }
  	if (a < b) {
      cout << b + (b-1) << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long int L[100];
int main() {
  int N;
  cin >> N;
  L[0] = 2;
  L[1] = 1;
  for (int i=2; i<=N; i++) {
    L[i] = L[i-1] + L[i-2];
  }
  cout << L[N] << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
	int a, b, c;
	std::cin >> a >> b >> c;
	
	if ( a < b && b < c ){
		std::cout  << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, p[2][10], v[10], pc[2], c;
string s;
int main(){
	scanf("%d", &n);
	rep(i,2) rep(j,n) scanf("%d", p[i]+j);
	rep(i,n) v[i] = i+1;
	do{
		rep(i,2){
			bool ok = true;
			rep(j,n) if(v[j] != p[i][j]) ok = false;
			if(ok) pc[i] = c;
		}
		c++;
	}while(next_permutation(v,v+n));
	printf("%d\n", abs(pc[0]-pc[1]));
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp39
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] high = Console.ReadLine().Split(' ');
            int a =int.Parse(high[0]);
            int b = int.Parse(high[1]);
            int c = int.Parse(high[2]);

            if (b - a == c - b)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

template <typename T>
T mod_expt(T a, std::int64_t n, T mod){
    T power {1};
    while(n > 0){
        if(n & 1){power = power * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return power;
}

constexpr ll MOD = 1'000'000'007;
constexpr ll HALF = 500'000'004;
int N;
std::vector<int> G[200100];
int size[200100];
std::vector<int> vec[200100];

void dfs(int v, int p){
    size[v] = 1;

    for(int w : G[v]){
        if(w == p){continue;}

        dfs(w, v);

        vec[v].emplace_back(size[w]);
        size[v] += size[w];
    }

    vec[v].emplace_back(N - size[v]);
}

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::cin >> N;

  for(int i=0;i<N-1;++i){
      int a, b;
      std::cin >> a >> b;

      G[a].emplace_back(b);
      G[b].emplace_back(a);
  }

  dfs(1, -1);

  ll E = 0;

  for(int i=1;i<=N;++i){
      ll p = 0;
      p += mod_expt<ll>(2, N - 1, MOD);
      p += 1;
      for(int s : vec[i]){
          p += mod_expt<ll>(2, s, MOD) - 1;
      }
      p = (mod_expt<ll>(2, N, MOD) - p) % MOD;
      if(p < 0){p += MOD;}
      p = p * mod_expt<ll>(HALF, N, MOD) % MOD;
      E += p;
  }

  E %= MOD;

  std::cout << E << std::endl;
}


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

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)
#define int long long

const int N = 2e5 + 2, inf = 1e18;

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);

    for (int& x : a) {
        cin >> x;
    }    
    for (int& x : b) {
        cin >> x;
    }
    reverse(b.begin(), b.end());
    int c = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            c = a[i];
            break;
        }
    }
    int l = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == c && b[i] == c) {
            l = i;
            break;
        }
    }
    int r = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == c && b[i] == c) {
            r = i;
            break;
        }
    }
 
    for (int i = 0; i < n; ++i) {
        if (a[i] != c && b[i] != c && l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }
 
    if (l <= r) {
        cout << "No\n";
        return 0;
    }
 
    cout << "Yes\n";
 
    for (int i = 0; i < n; ++i) {
        cout << b[i] << ' ';
        assert(b[i] != a[i]);
    }
    cout << "\n";


}


Measured memory_bytes: 6348
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int sum = 0;
        if (c * 2 >= a + b) {
            sum += a * x + b * y;
        } else {
            if (x > y) {
                sum += 2 * c * y;
                x -= y;
                sum += Math.min(a * x, 2 * c * x);
            } else if (x < y) {
                sum += 2 * c * x;
                y -= x;
                sum += Math.min(b * y, 2 * c * y);
            } else {
                sum += 2 * c * x;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 22996
// Daniel Grzegorzewski15
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int k;

int main() {
  init_ios();
  cin >> k;
  if (__gcd(k, 10) != 1) {
    cout<<"-1\n";
    return 0;
  }
  int id = 1, val = 7%k;
  while (val) {
    val = (10*val+7)%k;
    ++id;
  }
  cout<<id<<"\n";
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
   
public class Main {
    HashSet<String> hs = new HashSet<>();
    public static void main(String[] args) throws IOException {
//    	long l = System.currentTimeMillis();
        new Main().exec();
//    	long l2 = System.currentTimeMillis();
//    	System.out.println(l2 - l);
    }
      
    public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        for(int i=0; i<n; i++) {
        	String cmd = in.br.readLine();
        	if(cmd.charAt(0)=='i'){
        		hs.add(cmd.substring(7));
        	}else{
        		out.println(hs.contains(cmd.substring(5))?"yes":"no");
        	}
        }
        out.flush();
    }
}

class InputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int nextInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }

}

Measured memory_bytes: 126284
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <algorithm>
using namespace std;

int main() {
  long long H, W, M;
  cin >> H >> W >> M;
  long long h[M], w[M];
  for (int i = 0; i < M; i++) cin >> h[i] >> w[i];
  
  int sumH[H], sumW[W];
  map<int, int> Map[H];
  for (int i = 0; i < H; i++) sumH[i] = 0;
  for (int i = 0; i < W; i++) sumW[i] = 0;
  for (int i = 0; i < M; i++) {
    sumH[h[i] - 1]++;
    sumW[w[i] - 1]++;
    Map[h[i] - 1][w[i] - 1] = 1;
  }
  pair<int, int> SetH[H], SetW[W];
  for (int i = 0; i < H; i++){
    pair<int, int> a;
    a.first = sumH[i];
    a.second = i;
    SetH[i] = a;
  }
  for (int i = 0; i < W; i++){
    pair<int, int> a;
    a.first = sumW[i];
    a.second = i;
    SetW[i] = a;
  }
  sort(SetH, SetH + H);
  sort(SetW, SetW + W);
  
  int max_ = SetH[H - 1].first + SetW[W - 1].first - 1;
  int sum__H = 0, sum__W = 0;
  for (int i = 0; i < H; i++) if (SetH[i].first == SetH[H - 1].first) sum__H++;
  for (int i = 0; i < W; i++) if (SetW[i].first == SetW[W - 1].first) sum__W++;
  bool flag = false;
  for (int i = H - 1; i >= H - sum__H; i--){
    for (int j = W - 1; j >= W - sum__W; j--){
      if (Map[SetH[i].second][SetW[j].second] == 0){
        max_++;
        flag = true;
        break;
      }
    }
    if (flag == true) break; 
  }
  cout << max_ << endl;
}

Measured memory_bytes: 43444
import collections

def factor(m):
    num=m
    s=[]
    i=2
    while i*i<=m:
        if num%i:
            i+=1
        else:
            s.append(i)
            num//=i
    if num!=1:
        s.append(num)
    return s

def conb(n,r):
    r=min(r,n-r)
    N,R=n,r
    if r==1:
        return n
    elif r==0:
        return 1
    else:
        for i in range(1,r):
            N*=n-i
            R*=r-i
        return N//R
	
n,m=map(int,input().split())
a=factor(m)
b=collections.Counter(a)
mod=10**9+7
ans=1
for i in b.values():
    ans=(ans*conb(n+i-1,n-1))%mod
print(ans)

Measured memory_bytes: 3316
fun main(arr:Array<String>) {
    val dishes = (1..5).map { readLine()!!.toInt() }.sortedByDescending { if(it%10==0) 10 else it%10 }
    var current = 0
    for(i in dishes) {
        if(current % 10 != 0) {
            current += (10 - current%10)
        }
        current += i
    }
    println(current)
}


Measured memory_bytes: 35984
N, D = [int(x) for x in input().split()]
X, Y = zip(*[[int(x) for x in input().split()] for _ in range(N)])

cnt = 0
for i in range(N):
    if X[i] * X[i] + Y[i] * Y[i] <= D * D:
        cnt += 1

print(cnt)

Measured memory_bytes: 56464
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define ll long long

using namespace std;
map<ll,ll>dp;
const ll mod=1e9+7;
ll solve(ll n)
{
  if(dp[n])
    return dp[n];
  else
    return dp[n]=(solve(n/2)%mod+solve((n-1)/2)%mod+solve((n-2)/2)%mod)%mod;
}
int main()
{
   ll n;
   while(~scanf("%lld",&n))
         {
            dp[0]=1;
            dp[1]=2;
             printf("%lld\n",solve(n));
         }
         return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cctype>
#include<cstring>
#include<list>
#include<map>
#include<sstream>
#include<set>
#include<string>
#include<vector>
typedef long long ll;
using namespace std;
#define MN 300005
#define MM 600005
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define RF(i,a,b) for(int i=a;i>=(b);--i)
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define int long long
int a[100001];
signed main()
{
   double pi=acos(-1);
   double n;
   cin>>n;
   printf("%.20lf\n",2*pi*n);
   return 0;
}


Measured memory_bytes: 3784
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		System.out.println((x-a)%b);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, 0, n){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    sort(s.begin(), s.end());
    ll ans = 0;
    ll cnt = 1;
    string target;
//    bool flag = false;
    target = s[0];
    REP(i, 1, n){
        if(target == s[i]){
            cnt++;
        } else {
            ans += (cnt*(cnt-1))/2;
            cnt = 1;
            target = s[i];
        }

    }

    ans += (cnt*(cnt-1))/2;

    p(ans);


    return 0;
}


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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int t[20][20];
int memo[1<<16];
int n;

int solve(int bit){
	if(memo[bit]>0)return memo[bit];
	if(bit+1==1<<n)return 0;
	int i,res=100100100,mn;
	for(i=0;i<n;i++){
		if(bit&1<<i)continue;
		int j;
		mn=t[i][0];
		for(j=0;j<n;j++){
			if(bit&1<<j){
				chmin(mn,t[i][j+1]);
			}
		}
		chmin(res,solve(bit|1<<i)+mn);
	}
	memo[bit]=res;
	return res;
}

int main() {
	while(n=in()){
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				cin>>t[i][j];
			}
		}
		memset(memo,0,sizeof(memo));
		cout<<solve(0)<<endl;
//for(i=0;i<1<<n;i++){
//cout<<i<<":"<<memo[i]<<endl;
//}
	}
	return 0;
}

Measured memory_bytes: 1160
#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

int N;
vector<string> ans;
void dfs(int bit, string s, char ch){

  //pr(bit, s, ch);
  if(bit == (1<<N) - 1){ ans.push_back(s); return;}

  int mbit = 0;
  while((bit>>mbit&1) != 0) mbit++;

  for(int i=1;i<(1<<N);i++){
    if((bit & i) != 0) continue;
    if((i >> mbit & 1) == 0) continue;
    int nbit = bit | i;
    string ns = s;
    for(int j=0;j<N;j++) if(i>>j&1) ns[j] = ch;
    int nch = ch + 1;
    dfs(nbit, ns, nch);
  }
}

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

  cin>>N;

  dfs(0, string(N, '!'), 'a');
  sort(ans.begin(), ans.end());
  for(string a:ans) cout<<a<<endl;

  return 0;
}


Measured memory_bytes: 7796
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n;
int a[MAX_N];
set<int> in[MAX_N];
map<int, set<int>, greater<int>> by_size;
vi ans;

void insert(int v) {
    by_size[in[v].size()].insert(v);
}

void erase(int v) {
    by_size[in[v].size()].erase(v);
    if (by_size[in[v].size()].empty()) {
        by_size.erase(in[v].size());
    }
}

int find_min(set<int>& s) {
    assert(!s.empty());

    vi l;
    if (by_size.begin()->fst >= s.size() - 1) {
        l.push_back(*(by_size.begin()->snd.begin()));
    } else {
        int c = 0;
        for (auto it = s.begin(); it != s.end() && c < 3; it++, c++) {
            l.push_back(*it);
        }
    }

    for (int v : l) {
        bool ok = ans.empty() || a[ans.back()] != v;

        if (s.size() == 3) {
            int x = -1, y = -1;
            for (int u : s) {
                if (u == v) continue;
                if (x >= 0)
                    y = u;
                else
                    x = u;
            }

            ok &= a[x] != y || a[y] != x;
        }

        if (ok) {
            return v;
        }
    }
    return -1;
}

bool rec(set<int>& s) {
    if (s.empty()) return true;

    int u = find_min(s);
    //cout << "u=" << u << endl;
    if (u < 0)
        return false;
    else {
        s.erase(u);
        erase(u);
        if (contains(s, a[u])) {
            erase(a[u]);
            in[a[u]].erase(u);
            insert(a[u]);
        }
        ans.push_back(u);

        return rec(s);
    }
}

int main() {
    fastio();

    cin >> n;

    if (n == 2) {
        cout << -1 << endl;
        return 0;
    }

    forn(i, n) {
        cin >> a[i];
        a[i]--;
        in[a[i]].insert(i);
    }

    set<int> s;
    forn(i, n) {
        s.insert(i);
        insert(i);
    }

    if (!rec(s)) {
        ans.clear();
        ans.push_back(-2);
    }

    for (int v : ans) {
        cout << v + 1 << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string s;
	cin >> s;
	if(s == "ABC"){
		cout << "ARC" << endl;
	}else{
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include<stdio.h>
using namespace std;

int main(){
    char buf[110],stack[110]={0},*sp,*p;
    while(fgets(buf,103, stdin),*buf!='.'){
        sp=stack+1;
        p=buf;
        for(;*p!='.';p++){
            if(*p == '(' || *p == '['){
                *sp++ = *p;
            }else if(*p == ')' || *p == ']'){
                sp--;
                if(!((*sp =='(' && *p == ')') || (*sp =='[' && *p == ']'))){
                    puts("no");
                    break;
                }
            }
        }
        if(*p=='.')puts(sp==stack+1?"yes":"no");
    }
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
struct cmp1
{
    bool operator () (int &a, int &b)
    {
        return a > b ;
    }
};
int main()
{
    char a[100005];
    scanf("%s",&a);
    int i=0,j=strlen(a)-1;
    int l=0,g=0;
    while(i<j)
    {
        if(a[i]=='x'&&a[j]=='x'){i++;j--;continue;}
        if(a[i]=='x'){i++;l++;continue;}
        if(a[j]=='x'){j--;l++;continue;}
        if(a[i]!=a[j]){g++;break;}
        i++;j--;
    }
    if(g==1)
        printf("-1\n");
    else printf("%d\n",l);
    return 0;
}

Measured memory_bytes: 384
fn main(){
    let mut line = String::new();
    let stdin = std::io::stdin();
    stdin.read_line(&mut line).expect("Could not read line");;
    let p : Vec<_> = line.trim().split(' ').collect();
    let n : i64 = p[0].parse().unwrap();
    let mut m : i64 = p[1].parse().unwrap();
    let mut ret : i64;
    if n >= m / 2 {
        ret = m / 2;
    }
    else {
        ret = n;
    }
    m -= 2 * ret;
    ret += m / 4;
    println!("{}", ret);
}


Measured memory_bytes: 4352
/// 5:22 PM 10/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

ll sol(ll i, ll n, ll m, vector<ll> &C, vector<vector<ll> > &v, vector<ll> algo, ll x) {
    if (i == n) {
        for (auto a:algo) {
            if (a < x) {
                return INF;
            }
        }
        return 0;
    }
    ll ans1 = sol(i + 1, n, m, C, v, algo, x);
    ll ans2 = 0;
    for (ll j = 0; j < m; j++) {
        algo[j] += v[i][j];
    }
    ans2 = C[i] + sol(i + 1, n, m, C, v, algo, x);
    ll ans = min(ans1, ans2);
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, m, x;
    cin >> n >> m >> x;
    vector<ll> C(n);
    vector<vector<ll> > v(n, vector<ll>(m));
    for (ll i = 0; i < n; i++) {
        cin >> C[i];
        for (ll j = 0; j < m; j++) {
            cin >> v[i][j];
        }
    }
    vector<ll> algo(m);
    ll ans = sol(0, n, m, C, v, algo, x);
    if(ans >= INF) {
        ans = -1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3664
import java.util.Scanner;
public class Main {
	static int mod=1000000007;
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void main(String[]args){
		String str=scan.next();
		switch(str.charAt(0)) {
		case 'S':System.out.println("Cloudy");break;
		case 'C':System.out.println("Rainy");break;
		case 'R':System.out.println("Sunny");break;
		}
	}
}

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

int main(){
    string S;
    cin >> S;

    vector<int> chi(S.size(), 0);
    int counter = 0;

    for(int i=0; i<(int)S.size(); i++){
        if(S[i] == 'R'){
            counter += 1;
        }
        if(S[i] == 'L' && counter > 0){
            chi[i] += counter / 2;
            chi[i-1] += (counter-1)/2 + 1;
            counter = 0;
        }
    }

    for(int i=S.size()-1; i>=0; --i){
        if(S[i] == 'L'){
            counter += 1;
        }
        if(S[i] == 'R' && counter > 0){
            chi[i] += counter / 2;
            chi[i+1] += (counter-1)/2 + 1;
            counter = 0;
        }
    }

    for(int i=0; i<chi.size(); i++){
        cout << chi[i] << ' ';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
 // int t;
 // cin>>t;
 // while(t--){
    int a;
    cin>>a;
    int x=a*a;
    int y=a*a*a;
    cout<<x+y+a;
    // }
  return 0;
}

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

int main(){
  int N;
  int sum=0;
  int H[100]={};
  cin >> N;
  int max_temp = 0;
  for(int i=0; i<N; i++){
    cin >> H[i];
      
    if(i==0) {
      max_temp = H[0];
      sum++;
    }else{
      if(max_temp <= H[i]){
	sum++;
	max_temp = H[i];
      }
    }
  }
  cout << sum <<endl;
  return 0;
}


Measured memory_bytes: 256
a=input()
n=len(a)
S=n*(n-1)//2+1

l={}
for i in range(n):
    if a[i] in l:
        l[a[i]]+=1
    else:
        l[a[i]]=1

cnt=0
for i in l:
    if l[i]>1:
        cnt+=l[i]*(l[i]-1)//2

ans=S-cnt

print(ans)

Measured memory_bytes: 3500
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100005;

int n, m;
vector<int> g[MAX_N];
int cntIn[MAX_N];
int dp[MAX_N];
queue<int> q;

void dfs(int u)
{
	for (int v : g[u])
	{
		dp[v] = max(dp[v], dp[u] + 1);
		cntIn[v]--;
		if (cntIn[v] == 0)
			q.push(v);
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		cntIn[v]++;
	}

	for (int i = 0; i < n; i++)
		if (cntIn[i] == 0)
			q.push(i);
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		dfs(u);
	}

	int result = 0;
	for (int i = 0; i < n; i++)
		result = max(result, dp[i]);
	cout << result << endl;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){
	int N;
	scanf("%d",&N);
	int S[N];
	for(int i = 0; i < N; i++)scanf("%d",&S[i]);

	int M;
	scanf("%d",&M);

	int Q[M];
	for(int i = 0; i < M; i++)scanf("%d",&Q[i]);
	sort(Q,Q+M);

	int left = 0,right,m,count = 0;

	for(int i = 0; i < M; i++){
		right = N-1;
		m = (left+right)/2;

		while(left <= right){
			if(S[m] == Q[i]){
				count++;
				left= m+1;
				break;
			}else if(S[m] > Q[i]){
				right = m-1;
			}else{ //S[m] < Q[i]
				left = m+1;
			}
			m = (left+right)/2;
		}
	}
	printf("%d\n",count);
}



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

#define MOD		1000000007
#define ll		long long int
#define pll		pair<ll, ll>
#define pb		push_back
#define endl	"\n"
#define f 		first
#define s 		second
#define fastio 	ios_base::sync_with_stdio(false);cin.tie(NULL)

ll power(ll x, ll y) { ll ans = 1; x %= MOD; while (y) {if (y & 1)ans = (x * ans) % MOD; x = (x * x) % MOD; y >>= 1;} return ans;}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)


void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	ll kad = -10000000;
	ll currSum = -10000000;
	ll totSum = 0;
	for (ll i : arr) {
		currSum = max(i, currSum + i);
		kad = max(kad, currSum);
		totSum += i;
	}

	if (k == 1) {
		cout << kad << endl;
		return;
	}

	ll maxPref = arr[0];
	ll currPref = arr[0];
	for (int i = 1; i < n; i++) {
		currPref += arr[i];
		maxPref = max(maxPref, currPref);
	}

	ll maxSuff = arr[n - 1];
	ll currSuff = arr[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		currSuff += arr[i];
		maxSuff = max(maxSuff, currSuff);
	}

	// debug(kad, maxPref, maxSuff, totSum);

	ll maxEdge = max(maxSuff, maxPref);
	maxEdge = max(maxEdge, maxSuff + maxPref);

	ll maxKad = max(k * totSum, (k - 2) * totSum + maxSuff + maxPref);
	// debug(kad, maxPref, maxSuff, totSum, maxKad);

	maxKad = max(kad, maxKad);
	maxKad = max(maxKad, (k - 1) * totSum + max(maxSuff, maxPref));

	cout << max(maxKad, maxEdge) << endl;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	fastio;
	ll n, d;
	cin >> n >> d;
	ll ans = 0;

	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		ll dist = x * x + y * y;
		// debug(x, y, dist);
		if (d * d >= dist) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3656
N, M = map(int, input().split())
L_MAX = 0
R_MIN = N
for i in range(M):
  L, R = map(int, input().split())
  if L > L_MAX:
    L_MAX = L
  if R < R_MIN:
    R_MIN = R

Ans=max(R_MIN - L_MAX + 1, 0)
print(Ans)
  

Measured memory_bytes: 3060
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
s = STR()
l = n // 2
if n % 2 == 0 and s[:l] == s[l:]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5196
import collections
z = int(input())
a = [input() for i in range(z)]
a = collections.Counter(a).most_common()
a.sort(key = lambda x:x[1],reverse = True)
c = a[0][1]
ans = []
for i in a:
  if i[1] == c:
    ans.append(i[0])
  else:
    break
ans.sort()
for i in ans:
    print(i)

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

int main(){
    string n;
    cin>>n;
    ll sum=0;
    rep(i,n.size()) sum+=n[i]-'0';
    cout<<(sum%9==0?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define iint int
#define pll std::pair<iint,iint>
#define rep(i,a,b) for(iint i=(iint)a;i<(iint)b;i++)
#define per(i,a,b) for(iint i=(iint)a;i>(iint)b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
	int r;
	std::cin >> r;
	std::cout << r*r << "\n";
}

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

	// int t;
	// std::cin >> t;
	// while(t--){
	// 	solve();
	// }

	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a<=8 && b<=8){
        cout << "Yay!" << endl;
    }
    else if(a>8 || b>8){
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, L = list(map(int, input().split()))
D = 99999999
I = 0
for i in range(1, N + 1):
    d = abs(L - 1 + i)
    if d < D:
        D = d
        I = i
print((N - 1) * L + (1 + N) * N // 2 - I - (N - 1))

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

int n, a[200000], b[200001];
int main() {
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", &a[i]);
		b[a[i]] = i;
	}
	set<int>v;
	ll sum = 0;
	for (ll i = 1; i <= n; i++) {
		auto it = v.lower_bound(b[i]);
		int l, r;
		if (it == v.end())r = n;
		else r = *it;
		if (it == v.begin())l = -1;
		else l = *--it;
		sum += i*(r - b[i])*(b[i] - l);
		v.insert(b[i]);
	}
	printf("%lld\n", sum);
}

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

int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int a = 0; a < 10; ++a) {
      for (int b = 0; b < 10; ++b) {
        for (int c = 0; c < 10; ++c) {
          for (int d = 0; d < 10; ++d) {
            if (a + b + c + d == n) ++ans;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3056
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
    vector<int> A(3);
    for (int i = 0; i < 3; i++) {
        cin >> A[i];
    }
    sort(all(A));
    if (A[0] == A[1]) {
        cout << A[2] << endl;
    } else {
        cout << A[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string n, ni;
    cin >> n;
    int ns, c;
    ns = static_cast<int>(n.size());
    c = 0;
    for(int i = 0; i < ns; i++){
        ni = n[i];
        c += stoi(ni);
    }
    if(stoi(n)%c == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll N=1e5;
ll dp[N];
ll dp1[N];
ll arr[N];
ll n,k;
ll ksm(ll a, ll b){
	ll sum =1;
	while(b){
		if(b&1)
			sum = sum * a % mod;
		a=a*a%mod;
		b>>=1;
	}
	return sum;
}


ll solve(ll a){
	ll sum=((k*k+k)/2)%mod;
	sum=(dp[a]*sum)%mod;
	ll sum1=(k*(k-1)/2)%mod;
	sum1=(dp1[a]*sum1)%mod;
	sum=(sum1+sum+mod)%mod;
	return sum;
}

int main(){
	ll ans=0;
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n;i++){
		scanf("%lld",arr+i);
	} 
	for(ll i=1;i<=n;i++){
		for(int k=1;k<=i;k++){
			if(arr[i]>arr[k])
				dp1[i]++;
		}
		for(ll j=i+1;j<=n;j++){
			if(arr[i]>arr[j])
				dp[i]++;
		}
	} 
	for(ll i=1;i<=n;i++){
		ans=(ans+solve(i)+mod)%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    string s;
    cin>>s;
    int n=s.length();
    if (n==1)
    {
        cout<<s[0];
        return 0;
    }
    int x=(n-1)*9+s[0]-'0'-1;
    int y=0;
    for (int i=0;i<n;i++)
    {
        y+=s[i]-'0';
    }
    cout<<max(x, y);

    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    l = list(S)
    odd = all([s in ['R', 'U', 'D'] for s in sorted(list(set(l[0::2])))])
    even = all([s in ['L', 'U', 'D'] for s in sorted(list(set(l[1::2])))])
    print(YES if odd and even else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064