akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d) yes;
    else if (abs(a - b) <= d && abs(b - c) <= d) yes;
    else no;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type Shop struct {
	a, b int
}

type Shops []Shop

func (s Shops) Len() int {
	return len(s)
}
func (s Shops) Less(i, j int) bool {
	return s[i].a < s[j].a
}
func (s Shops) Swap(i, j int) {
	t := s[i]
	s[i] = s[j]
	s[j] = t
}

func main() {
	var N, M int
	fmt.Scanln(&N, &M)

	shops := make(Shops, N)
	for i := 0; i < N; i++ {
		fmt.Scanln(&shops[i].a, &shops[i].b)
	}
	sort.Sort(shops)

	result := 0
	m := 0

	for _, sh := range shops {
		buy := sh.b
		if m+buy > M {
			buy = M - m
		}
		result += sh.a * buy
		m += buy
	}

	fmt.Println(result)
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
 
using namespace std;
 
int main()
{
    int N, A;
    cin>>N>>A;
 
    vector<vector<long long>> T(N+1, vector<long long>(50*N+1));
    T[0][0] = 1LL;
 
    for (int i=0; i<N; i++)
    {
        int x;
        cin>>x;
 
        vector<vector<long long>> P = T;
 
        for (int j=0; j<=i; j++)
        for (int k=0; k<=50*i; k++)
            T[j+1][k+x] += P[j][k];
    }
    long long ans = 0;
    for (int i=1; i<=N; i++)
        ans += T[i][i*A];
    cout<<ans<<endl;
}


Measured memory_bytes: 2312
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

//inline int read(){int t = 0;int neg=1;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1;continue;}t=t*10+c-48;}return neg*t;}
//inline int readl(){long long t = 0;long long neg=1ll;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1ll;continue;}t=t*10+c-48;}return neg*t;}

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<pi> vpi;
typedef vector<plli> vplli;
const lli M=1000000007ll;

int main(){
	fast_io
	int s,w; cin>>s>>w;
	if(w>=s) cout<<"unsafe";
	else cout<<"safe"; 
	
	return 0;
}

Measured memory_bytes: 3628
/* ***************************************
Author        :Scau.ion
Created Time  :2016/10/01 21:04:10 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

int main()
{
	int n;
    int a[200];
    scanf("%d",&n);
    int sum[200];
    memset(sum,0,sizeof sum);
    int mi=200,ma=0;
    for (int j=1;j<=n;++j)
    {
        scanf("%d",&a[j]);
        ++sum[a[j]];
        mi=min(mi,a[j]);
        ma=max(ma,a[j]);
    }
    bool flag=1;
    for (int j=mi+1;j<=ma;++j)
        if (sum[j]<2) flag=0;
    if (mi*2<ma) flag=0;
    if (sum[mi]>2) flag=0;
    if (mi==1)
    {
        if (ma==1)
        {
            if (sum[1]!=2) flag=0;
        }
        else
        {
            if (sum[1]>1) flag=0;
        }
    }
    if (ma%2==0&&sum[mi]==2) flag=0;
    if (ma%2==1&&sum[mi]==1) flag=0;
    if (flag) printf("Possible\n");
    else printf("Impossible\n");
	return 0;
}


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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 100000;

vector<pii> gp[MAX_N+1];
int N;
int K;

int chk[MAX_N+1];
int c[MAX_N+1];
bool vst[MAX_N+1];

void dfs(int x){
	vst[x] = true;
	int idx = 1;
	bool b = true;
	for(pii i : gp[x]){
		if(vst[i.first])	continue;
		if(chk[idx] && b){
			chk[idx] = false;
			b = false;
			idx++;
		}
		c[i.second] = idx++;
	}
	for(pii i : gp[x]){
		if(vst[i.first])	continue;
		chk[c[i.second]] = true;
		dfs(i.first);
		chk[c[i.second]] = false;
	}
}

int main(){
	scanf("%d", &N);
	for(int i=1; i<N; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		gp[a].pb({b, i});
		gp[b].pb({a, i});
	}
	for(int i=1; i<=N; i++){
		K = max(K, (int)gp[i].size());
	}
	dfs(1);
	printf("%d\n", K);
	for(int i=1; i<N; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}


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

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

  sort(a, a + 12);
  bool f = (a[0] == a[3]) && (a[4] == a[7]) && (a[8] == a[11]);

  cout << (f ? "yes" : "no") << endl;
}

Measured memory_bytes: 3144
$n=<>;
chomp($n);
%list;
for (my$i=2;$i<=$n;$i++){
    my$p=$i;
    for(my$d=2;$d<=$p;$d++){
        while($p%$d==0){
            $list{$d}++;
            $p/=$d;
        }
    }
}
@larger = sort {$list{$b}<=>$list{$a}} keys %list;
$nn=$#larger;
foreach my$i (@larger){
    $ans++ if ($list{$i}>=74); #x^74(x=2 if N<=100)
    $n24++ if ($list{$i}>=24); #
    $n14++ if ($list{$i}>=14); #
    $n4++ if ($list{$i}>= 4);  #
    $n2++ if ($list{$i}>= 2);  #
}
# print ("74:$ans, 24:$n24, 14:$n14, 4:$n4, 2:$n2\n");

$ans+=$n24*($n2-1);
$ans+=$n14*($n4-1);
$ans+=$n4*($n4-1)*($n2-2)/2;
$ans//=0;
print ("$ans");


# 32400=2^4*3^4*5^2
# 75=25*3=5*5*3*15*5
# pt1. a**74
# pt2. a**24 * b**2
# pt3. a**14 * b**4
# pt4. a** 4 * b**4 * c**2 (a!=b) = (n4)C2 * n2-2


Measured memory_bytes: 512
// 16D8104007J Kanehiro Maho 兼弘真帆 2018年4月23日

#include<stdio.h>
int main(void){
  int n,i,j,max,min,ans;
  scanf("%d",&n);
  int r[n];
  for(i=0;i<n;i++){
    scanf("%d",&r[i]);
  }
  max=r[1]-r[0];
  min=r[0];
  for(i=1;i<n;i++){
    ans=r[i]-min;
    if(max<ans){
      max=ans;
    }
    if(r[i]<min){
      min=r[i];
    }
  }

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



Measured memory_bytes: 2532
import java.util.Scanner;

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

		int n = sc.nextInt();
		String s = sc.next();
		System.out.println( solve(n, s) );
	}

    private static int solve(int N, String S) {
        int max = 0;

        for (int i = 1; i < N; i++) {
            String head = S.substring(0, i);
            String tail = S.substring(i);

            int cnt = 0;
            for (int c = 'a'; c <= 'z' ; c++) {
                if( head.indexOf(c) != -1 && tail.indexOf(c) != -1 ) {
                    cnt++;
                }
            }
            if (max < cnt) max = cnt;
        }
        return max;
    }
}


Measured memory_bytes: 23380
#include <stdio.h>

int main(void) {
	char s;
	int i, flag[3] = {0};
	
	for (i = 0; i < 3; i++) {
		scanf(" %c", &s);
		flag[s == 'a' ? 0 : s == 'b' ? 1 : 2] = 1;
	}
	
	if (flag[0] && flag[1] && flag[2])
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int k;
    k=0;
    int a[20];
    for(int i=0;i<20;i++){
        a[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int b[50];
    for(int i=0;i<50;i++){
        b[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    int c[20];
    for(int i=0;i<20;i++){
        c[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    for(int i=0;i<n;i++){
        k+=b[i];
        if(a[i]==a[i+1]-1){
           k+=c[a[i]-1];
        }
    }

    cout<<k;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD 1000000007
void bulk(){}template<class H,class...T>void bulk(H&h,T&...t){cin>>h;bulk(t...);}
#define get(...) int __VA_ARGS__; bulk(__VA_ARGS__);
int main(){
	get(n);
	int m=0;
	rep(i,n){
	    get(p);
	    m|=p;
	}
    cout<<__builtin_ctz(m)<<endl;
	return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
CTs = [list(map(int, input().split())) for _ in range(N)]

ans = float('inf')
flg = False
for c, t in CTs:
    if t <= T:
        flg = True
        ans = min(ans, c)

if flg:
    print(ans)
else:
    print('TLE')


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	ll first,second,third;
	Data()=default;
	Data(ll f,ll s,ll t):first(f),second(s),third(t){}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),K=in();
	out(N-K+1);
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<algorithm>
#include<cstdio>
#define INF 1000005
using namespace std;
char cmd[20];

int main()
{
    int T;
    cin >> T;
    list <int> v;
    while(T--)
    {
        int a;
        cin >> cmd ;
        if(cmd[0]=='i')
        {
            cin >> a;
            v.push_front(a);
        }
        else
        {
            if(cmd[6]=='F')
                v.pop_front();
            else if(cmd[6]=='L')
                v.pop_back();
            else
            {
                cin >> a;
                for(list<int>::iterator it=v.begin();it!=v.end();it++)
                    if(*it==a)
                    {
                        v.erase(it);
                        break;
                    }

            }
        }
        }
        int i=0;
        for(list<int>::iterator it=v.begin();it!=v.end();it++)
        {
            if(i++) printf(" ");
            printf("%d",*it);
        }
        printf("\n");

    return 0;
}

Measured memory_bytes: 34480
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	for(char s[5];scanf("%s",s),strcmp(s,"0000")!=0;){
		if(count(s,s+4,s[0])==4){
			puts("NA");
			continue;
		}

		int ans=0;
		while(strcmp(s,"6174")!=0){
			char s1[5]; strcpy(s1,s); sort(s1,s1+4);
			char s2[5]; strcpy(s2,s); sort(s2,s2+4,greater<char>());
			int a1=atoi(s1);
			int a2=atoi(s2);
			sprintf(s,"%04d",a2-a1);
			ans++;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1024
import collections

N=int(input())
V=[int(i) for i in input().split()]

oddSeq,evenSeq=[],[]
for i in range(N//2):
    oddSeq.append(V[i*2])
    evenSeq.append(V[i*2+1])

oddCounter = collections.Counter(oddSeq)
evenCounter = collections.Counter(evenSeq)

oddMostCommonNumber = oddCounter.most_common()[0][0]
evenMostCommonNumber = evenCounter.most_common()[0][0]

oddMostCommonTimes = oddCounter.most_common()[0][1]
evenMostCommonTimes = evenCounter.most_common()[0][1]

odd2ndCommonNumber = 0
even2ndCommonNumber = 0

odd2ndCommonTimes = 0
even2ndCommonTimes = 0

if len(oddCounter.most_common())!=1:
    odd2ndCommonNumber = oddCounter.most_common()[1][0]
    odd2ndCommonTimes = oddCounter.most_common()[1][1]
if len(evenCounter.most_common())!=1:
    even2ndCommonNumber = evenCounter.most_common()[1][0]
    even2ndCommonTimes = evenCounter.most_common()[1][1]

ans=-1
if evenMostCommonNumber!=oddMostCommonNumber:
    ans = N-oddMostCommonTimes-evenMostCommonTimes
else:
    ans1 = N-oddMostCommonTimes-even2ndCommonTimes
    ans2 = N-odd2ndCommonTimes-evenMostCommonTimes
    ans = min(ans1,ans2)
print(ans)

Measured memory_bytes: 20576
#include<stdio.h>
#include<stdbool.h>
#include<math.h>
#define ll long long

bool sosuu(ll n){
  for(int i=3;i<sqrt(n);i+=2){
    if(n%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  ll x,i;
  scanf("%lld",&x);
  if(x==2){
    printf("2");
    return 0;
  }
  if(x%2==0)x+=1;
  while(1){
    if(sosuu(x)) break;
    x+=2;
  }
  printf("%lld",x);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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 tmp = 0;
        if (a > b){
            tmp = a;
            a = b;
            b = tmp;
        }
        if (b > c){
            tmp = b;
            b = c;
            c = tmp;
        }
        if (a > b){
            tmp = a;
            a = b;
            b = tmp;
        }
        System.out.println(a +" "+ b +" "+ c);
    }
}


Measured memory_bytes: 26224
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

ll N, W, V;
ll w[110], v[110];
const ll INF = 1e9;
ll VAL = 1e5+1;
ll dp[110][100010];

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

  cin >> N >> W;
  REP(i, N) {
    cin >> w[i] >> v[i];
    V += v[i];
  }
  VAL = V+1;
  //漸化式ver.
  // dp[i][j] := i番目までの価値jとなる最小重さ
  REP(j, VAL) dp[0][j] = INF;
  dp[0][0] = 0;
  
  REP(i, N+1){
    REP(j, VAL){
      dp[i+1][j] = dp[i][j];
      if(j >= v[i]){
	dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i]);
      }
    }
  }

  ll ans = 0LL;
  /*
  REP(i, VAL){
    //if(dp[N][i] <= W) ans = max(ans, (ll)i);
  }
  */
  ROF(i, V, 0){
    if(dp[N][i] <= W){
      cout << i << endl;
      return 0;
    }
  }
  
  
  return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var A = input[0];
            var B = input[1];
            var K = input[2];
            for (int i = 0; i < K; i++)
            {
                if (i % 2 == 0)
                {
                    if (A % 2 == 1)
                    {
                        A--;                        
                    }
                    B += A / 2;
                    A /= 2;
                }
                else
                {
                    if (B % 2 == 1)
                    {
                        B--;
                    }
                    A += B / 2;
                    B /= 2;
                }
            }

            Console.WriteLine(A + " " + B);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
typedef long long int ll;
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
const double pi = 3.14159265358979323846;


void solve()
{
	ll i=0,j=0,m=0;
	ll n,cnt=0;
	vi tab;
	cin>>n;
    while(n%2==0)
    {
        cnt++;
        n/=2;
    }
    if(cnt!=0)
    tab.pb(cnt);
    cnt=0;
    for(i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
            cnt=0;
            while(n%i==0)
            {
                n/=i;
                cnt++;
            }
            tab.pb(cnt);
        }
    }
    if(n>2)
    tab.pb(1);
    ll reg=0;
    for(i=0;i<tab.size();i++)
    {
        int lol=1;
        while(tab[i]-lol>=0)
        {
            tab[i]-=lol;
            lol++;
            reg++;
        }
    }
    cout<<reg;
    
}

int main() {
    fast
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}


Measured memory_bytes: 3640
n,m,x=list(map(int,input().split()))
a=[]
l=[]
for i in range(n):
    p=list(map(int,input().split()))
    l.append(p)
for i in range(1,2**n):
    k=0
    ar=[0]*m
    for j in range(n):
        if (i>>j)&1==1:
            
            k+=l[j][0]
            for u in range(m):
                ar[u]+=l[j][u+1]
    
    if min(ar)>=x:
        a.append(k)
if len(a)>0:
    print(min(a))
else:
    print(-1)
            
            
        
    

Measured memory_bytes: 9212
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long min=INF;
    long i;
    for(i=1; i<n; i++) {
        long j = n-i;

        long tmp0=0;
        long curr = i;
        while(curr>0) {
            tmp0 += curr % 10;
            curr = curr / 10;
        }

        long tmp1=0;
        curr = j;
        while(curr>0) {
            tmp1 += curr % 10;
            curr = curr / 10;
        }
        
        min = MIN(min, tmp0 + tmp1);
    }
    printf("%ld\n", min);

    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	char s; cin >> s;
	char ss = s + 1;
	cout << ss;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int w, a, b;
  cin >> w >> a >> b;

  if(a <= b && a + w >= b || b <= a && b + w >= a) {
    cout << 0 << endl;
  } else if(a + w < b) cout << b - (a + w) << endl;
  else cout << a - (b + w) << endl; //b + w < a

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	long long n;
	cin>>n;
	cout<<n*n<<endl;
	return 0;
}


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

int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      vector<pair<int,int> > set;
      for(int i=0;i<n;i++)
	{
	  int d,p;
	  cin>>d>>p;
	  set.push_back(pair<int,int>(p,d));	  
	}
      sort(set.begin(),set.end());
      int sum=0;
      for(int i=n-1;i>=0;i--)
	{
	  int d=set[i].second;
	  int p=set[i].first;
	  sum+=(max(0,d-max(m,0)))*p;
	  m-=d;
	}
      cout<<sum<<endl;
    }
 }

Measured memory_bytes: 1328
#https://oneminutepython.com/atcoder/abc126_e.html

class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]

    def is_root(self, x):
        return self.parent[x] < 0

N,M = map(int,input().split())
S =[[] for _ in range(M)]
uf = UnionFind(N)
for i in range(M):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    uf.unite(x,y)

print(sum(uf.is_root(i) for i in range(N))) #Trueの個数のみ反映


Measured memory_bytes: 80032
N, K = map(int, input().split())
cnts = [0] * N
for n in range(K):
    d = int(input())
    A = list(map(int, input().split()))

    for a in A:
        cnts[a-1] += 1
cnt = 0
for c in cnts:
    if c == 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 9080
n = int(input())
a = list(map(int,input().split()))
lst = [0]+[0]*(10**5 + 1)
for i in a:
  lst[i] += 1
  
ans = 0
for i in range(1,10**5):
  ans = max(ans,lst[i-1]+lst[i]+lst[i+1])
print(ans)

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll N; cin>>N;
  if(N%2){
    cout<<0<<endl;
    return 0;
  }
  ll k = -1;//5^kで割るのが最高
  ll n1 = N;
  while(n1 / pow(5,k) > 0){
    k++;
  }
  ll res = 0;
  N /= 2;
  // cout << k << endl;
  for(int i = k; i >= 1; i--){
    res += N/(ll)pow(5,i);
  }
  cout<<res<<endl;
}


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

int main()
{
	string s;
	cin>>s;
	int n = s.length();
	//int a = 0;
	//int min_a = 0;
	vector<int> forward((n+1),0);
	vector<int> backward((n+1),0);
	for(int i = 1 ; i <= n ; i++)
	{
		if(s[i-1] == '<')
		{
			forward[i] = (forward[i-1]+1);
		}
		else 
		{
			forward[i] = 0;
		}
	}
	for(int i = (n-1) ; i>=0 ; i--)
	{
		if(s[i] == '>')
		{
			backward[i] = (backward[i+1]+1);
		}
		else
		{
			backward[i] = 0;
		}
	}
	long long int ans =  0;
	for(int i = 0 ; i <= n ; i++)
	{
		ans += max(forward[i],backward[i]);
	}
	cout<<ans<<endl;	
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
#define nikal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    long n,m;
    cin>>n>>m;
    long long h[n+1]={0},a[n+1]={0},p,q,i;
    for(i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    for(i=0;i<m;i++)
    {
        cin>>p>>q;
        if(h[p]>h[q])
        {
            a[q]=1;
        }
        else if(h[p]<h[q])
        {
            a[p]=1;
        }
        else
        {
            a[p]=1;
            a[q]=1;
        }
    }
    p=0;
    for(i=1;i<=n;i++)
    {
        if(a[i]==0)
        {
            p++;
        }
    }
    cout<<p;
    return 0;
}


Measured memory_bytes: 5164
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int N,X;
int C;
int D[30][39];
int t[3][30];

int main() {
  scanf("%d%d", &N,&C);
  rep(i,C)rep(j,C)scanf("%d", &D[i][j]);
  rep(i,N)rep(j,N)scanf("%d", &X),t[(i+j)%3][X-1]++;
  int res=1<<30;
  rep(i,C)rep(j,C)if(i!=j)rep(k,C)if(i!=k&&j!=k) {
    int tt=0;
    rep(l,C) tt+=D[l][i]*t[0][l];
    rep(l,C) tt+=D[l][j]*t[1][l];
    rep(l,C) tt+=D[l][k]*t[2][l];
    if(tt<res) res=tt;
  }
  printf("%d\n", res);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001




int main (){
    char N; cin >> N;
    if(N=='A') N = 'T';
    else if(N=='C') N = 'G';
    else if(N=='T') N = 'A';
    else N = 'C';
    
    cout << N << endl;
    return 0;
}


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

int N,P;

int main(){
	cin>>N>>P;
	bool flg=false;
	REP(i,N){
		int a;
		cin>>a;
		if (a&1){
			flg=true;
		}
	}
	if (flg){
		cout<<(1ll<<(N-1))<<endl;
	}else{
		if (P==0){
			cout<<(1ll<<N)<<endl;
		}else{
			cout<<0<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str = sc.nextLine().split("");
		Deque<Integer> que = new ArrayDeque<>();
		Deque<List<Integer>> puddle = new ArrayDeque<>();
		for (int i = 0; i < str.length; i++) {
			if (str[i].equals("\\")) {
				que.add(i);
			} else if(str[i].equals("/")) {
				if (que.size() == 0) {
					continue;
				} else {
					int l = que.pollLast();
					int s = i - l;
					if(puddle.size() == 0) {
						puddle.addLast(new ArrayList<>());
						puddle.getLast().add(0, l);
						puddle.getLast().add(1, s);
					} else {
						if(l > puddle.getLast().get(0)) {
							puddle.addLast(new ArrayList<>());
							puddle.getLast().add(0, l);
							puddle.getLast().add(1, s);
						} else {
							List<Integer> list = puddle.pollLast();
							while (true) {
								s += list.get(1);
								if (puddle.size() == 0) {
									break;
								} else if(puddle.getLast().get(0) < l) {
									break;
								} else {
									list = puddle.pollLast();
								}
							}
							puddle.add(new ArrayList<>());
							puddle.getLast().add(0, l);
							puddle.getLast().add(1, s);
						}
					}
				}
			}
		}
		int sum = 0;
		Iterator<List<Integer>> it = puddle.iterator();
		while (it.hasNext()) {
			List<Integer> next = it.next();
			sum += next.get(1);
		}
		System.out.println(sum);
		if (puddle.size() == 0) {
			System.out.println(puddle.size());
		} else {
			System.out.print(puddle.size() + " ");
			it = puddle.iterator();
			while (it.hasNext()) {
				List<Integer> next = it.next();
				if(!it.hasNext()) {
					System.out.println(next.get(1));
				} else {
					System.out.print(next.get(1) + " ");
				}
			}
		}
	}
}


Measured memory_bytes: 32108
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int n, m ;
  cin >> n >> m ;
  
  vector<int> kk(m,0) ;
  for(int i=0;i<n;i++){
    int k ;
    cin >> k ;
    for(int j=0;j<k;j++){
      int a ;
      cin >> a ;
      a-- ;
      ++kk[a] ;
    }
  }
  
  int ans = 0 ;
  
  for (int i = 0; i < m; i++) {
    if (kk[i] == n) {
      ++ans;
    }
  }
  cout << ans << endl;
  
  
  return 0 ;
}

Measured memory_bytes: 256
import math

all_list = [int(input()) for _ in range(5)]
tmp = 0
for i in all_list:
    j = math.ceil(i/10)*10
    tmp_i = j - i
    if tmp < tmp_i:
        tmp = tmp_i
for i, num in enumerate(all_list):
    all_list[i] = math.ceil(num/10)*10
result = sum(all_list)
result -= tmp
print(result)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

const int MAX = 3e5;

vi adj[MAX];

int dp[MAX];
int ans[MAX];

bool vis[MAX];

void dfs(int cur, int prev){
	vis[cur] = true;
	ans[cur] = dp[cur] + prev;
	for(auto x : adj[cur]){
		if(vis[x])
			continue;
		dfs(x,ans[cur]);
	}
}


int32_t main(){
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < n-1; i++){
		int x, y;
		cin >> x >> y;
		adj[x].PB(y);
		adj[y].PB(x);
	}
	memset(dp,0,sizeof dp);
	memset(ans,0,sizeof ans);
	memset(vis,false, sizeof vis);
	
	while(q--){
		int node, val;
		cin >> node >> val;
		dp[node] += val;
	}
	dfs(1,0);	
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

	return 0;
}



Measured memory_bytes: 26880
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

template <class T>
class bsegment_tree {
   public:
    ll size;
    vector<T> data;
    T default_value;

    bsegment_tree(ll n, T default_value_) {
        default_value = default_value_;

        ll siz = 1;
        while (siz < n) {
            siz = siz * 2;
        }
        data.resize(siz * 2, default_value);
        size = siz;
    }

    ~bsegment_tree() {}

    T compare(T& a, T& b) {
        //  ここをカスタム ex) min
        //return min(a, b);
        //return min(a, b);
        return max(a, b);
    }

    void update(ll k, T value) {
        // 葉の節点
        k += size - 1;
        data[k] = value;

        while (k > 0) {
            // 順に親に向かっていく
            k = (k - 1) / 2;
            data[k] = compare(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    // [a, b) で compare 最強のもの
    T query_open(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l) {  // 共通要素がない
            return default_value;
        }
        if (a <= l && r <= b) {  // 完全に含んでいる
            return data[k];
        }

        // 2つの子の compare で勝つほう
        T vl = query_open(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query_open(a, b, k * 2 + 2, (l + r) / 2, r);
        return compare(vl, vr);
    }

    // [a, b] で compare 最強のもの
    T query(ll a, ll b) {
        return query_open(a, b + 1, 0, 0, size);
    }
};
using segment_tree = bsegment_tree<ll>;
using pll = pair<ll, ll>;
int main() {
    ll N, K;
    cin >> N >> K;
    vector<pll> va(N);
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        ll v;
        cin >> v;
        va[i] = {v, i};
        a[i] = v;
    }

    sort(va.begin(), va.end());

    auto st = segment_tree(N, 0);
    vector<ll> stindex(N, 0);
    for (ll i = 0; i < N; i++) {
        stindex[va[i].second] = i;
    }

    ll maxlen = 0;
    for (ll i = N - 1; i >= 0; i--) {
        ll v = a[i];
        ll left = lower_bound(va.begin(), va.end(), (pll){v - K, -1}) - va.begin();
        ll right = lower_bound(va.begin(), va.end(), (pll){v + K, 300002}) - va.begin() - 1;
        ll curlen = 1 + st.query(left, right);
        maxlen = max(curlen, maxlen);
        st.update(stindex[i], curlen);
    }
    print(maxlen);
}


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

template< class T >
int slide_smallest(const vector<T>& v, T k) {
    T x = 0;
    int l = 0, r = 0;
    int ret = (int)v.size()+1;
    for (r = 0; r < v.size(); ++r) {
        x += v[r];
        while (x >= k) {
            ret = min(ret, r - l + 1);
            x -= v[l];
            l++;
        }
    }
    if ( ret == (int)v.size()+1 ) return 0;
    return ret;
}

int main() {
    int N, S;
    cin >> N >> S;
    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    cout << slide_smallest(v, S) << endl;
}



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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

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

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 998244353;

ll pos, n;
string s;

PII formula() {
    vector<PII> ret;
    vector<char> op;
    while(pos < n && s[pos] != ')') {
        if(s[pos] == '(') {
            pos++;
            ret.push_back(formula());
            pos++;
        } else if(s[pos] == '?') {
            pos++;
            ret.push_back(PII(1,1));
        } else if(s[pos] == '&' || s[pos] == '|') {
            op.push_back(s[pos]);
            pos++;
        } 
    }
    PII ans(0, INF);
    ll con = ret[0].second, mi = ret[0].first;
    REP(i, op.size()) {
        // cout << i << " " << ans << " " << con << " " << mi << endl;
        if(op[i] == '&') {
            chmin(mi, con + ret[i+1].first);
            con += ret[i+1].second;
        } else {
            // cout << mi << endl;
            chmin(ans.second, ans.first + con);
            ans.first += mi;
            mi = ret[i+1].first;
            con = ret[i+1].second;
        }
    }
    chmin(ans.second, ans.first + con);
    ans.first += mi;
    // cout << ret << endl << op << endl << ans << endl;
    return ans;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> s;
    n = s.size();

    PII ret = formula();
    cout << ret.first << " " << ret.second << endl;

    return 0;
}



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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repi(i, x) for (auto &i : (x))

#ifndef __SOULTCH
#define endl '\n'
#define debug(...) 
#else
#define __debug_a(v) cout << " [+] " << #v << " = " << (v) << endl
#define __debug_b(v) cout << "     " << #v << " = " << (v) << endl
#define debug1(v1) __debug_a(v1);
#define debug2(v1, v2) __debug_a(v1), __debug_b(v2);
#define debug3(v1, v2, v3) __debug_a(v1), __debug_b(v2), __debug_b(v3);
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define debug(...) GET_MACRO(__VA_ARGS__, debug3, debug2, debug1)(__VA_ARGS__)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << pai.first << ' ' << pai.second;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> s) {
    for (T p : s) cout << p << ' ';
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
    for (auto p : s) cout << '(' << p << ") ";
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

template<typename T> void umax(T &a, T b) {a = max(a, b);}
template<typename T> void umin(T &a, T b) {a = min(a, b);}

int N;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    cin >> N;
    int res = 0;
    int cA = 0, cB = 0, cAB = 0;
    rep(i, N) {
        string s; cin >> s;
        if (s[sz(s)-1] == 'A' and s[0] == 'B') cAB++;
        else if (s[sz(s)-1] == 'A') cA++;
        else if (s[0] == 'B') cB++;

        rep(j, sz(s)-1) res += (s[j]=='A'&&s[j+1]=='B');
    }

    if (cA == 0 and cB == 0) res += max(0, cAB-1);
    else res += cAB+min(cA, cB);
    cout << res;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    Int(n);
    string st;
    cin >> st;
    bool state = false;
    rep(i, st.size()) {
        if (!state) {
            if (st[i] == 'x') {
                state = true;
            }
        } else {
            if (st[i] == 'x') {
                cout << i << endl;
                return 0;
            } else {
                state = false;
            }
        }
    }
    cout << st.size() << endl;


    return 0;
}



Measured memory_bytes: 3348
#include<bits/stdc++.h>
#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(){
    string s;
    cin>>s;
    long long sm=0;
    for(int i=0;i<s.size();i++){
        sm+=int(s[i]-'0');
    }
    cout<<(sm%9==0?"Yes\n":"No\n");
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;
int n;
vector<int>L;
int A,B,C;
int INF=1000000000;
int dfs(int i,int a,int b,int c) {

	if(i==n) {
		if(!a || !b || !c) return INF;
		if(a > 0 && b > 0 && c > 0) {
			return abs(a-A)+abs(b-B)+abs(c-C);
		}
	}

	int res0 = dfs(i+1,a,b,c);
	int res1 = dfs(i+1,a+L[i],b,c)+(a==0 ? 0 : 10);
	int res2 = dfs(i+1,a,b+L[i],c)+(b==0 ? 0 : 10);
	int res3 = dfs(i+1,a,b,c+L[i])+(c==0 ? 0 : 10);
	return min({res0,res1,res2,res3});
}
int main() {
	cin >> n >> A >> B >> C;
	L.resize(n);
	rep(i,n) cin >> L[i];
	cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void solveTravelingAtCoDeer() throws IOException {
		int n;
		int aMin;
		int aMax;
		int ai;
		String line;
		String[] split;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		line = br.readLine();
		n = Integer.parseInt(line);
		line = br.readLine();
		split = line.split(" ");
		aMin = Integer.MAX_VALUE;
		aMax = 0;
		for (int i = 0; i < n; i++) {
			ai = Integer.parseInt(split[i]);
			if (aMin > ai)
				aMin = ai;
			if (aMax < ai)
				aMax = ai;
		}
		br.close();
		System.out.println(aMax - aMin);
	}

	public static void main(String[] args) {
		try {
			solveTravelingAtCoDeer();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 22356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		sc.close();
		int total = 0;
		for(int a = 1; a <= K; a++) {
			for(int b = 1; b <= K; b++) {
				for(int c = 1; c <= K; c++) {
					int result = gcdThree(a , b, c);
					total += result;
				}
			}
		}
		System.out.println(total);
	}
	
	static int gcd(int a, int b) {
		int temp;
		while((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	static int gcdThree(int a , int b, int c) {
		int gcdTwo = gcd(a, b);
		int result = gcd(gcdTwo , c);
		return result;
	}

}

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

using namespace std;
#define int long long
signed  main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int sum=0;
	for(int i=1;i<s.size();i++)
		if(s[i]==s[i-1])
			sum++;
	cout<<min(sum+2*k,n-1);
	return 0;
} 

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

int main()
{
	long long int a, b, c, d;
	cin >> a >> b >> c;
	
	d = c - a - b;
	
	if (d > 0 and d * d > 4 * a * b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,k = map(int,input().split())
S = list(input())[:-1]
s = S[k-1]
if s == "A":
    S[k-1] = "a"
if s == "B":
    S[k-1] = "b"
if s == "C":
    S[k-1] = "c"
print("".join(S))

Measured memory_bytes: 13824
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int[] c;
    int a, max, i;

    c = new int[100];
    for(;sc.hasNext();){
      a = sc.nextInt();
      c[a - 1]++;
    }
    max = 0;
    for(i = 0;i < 100;i++)if(max < c[i])max = c[i];
    for(i = 0;i < 100;i++)if(max == c[i])out.println(i + 1);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 18120