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

class combination
{
public:

	//N????????§?????????????????°??£??\??????
	combination( long long int combinationThreshold = 1e7 ) {
		(*this).combinationThreshold = combinationThreshold;
	}

	//a^p % mod
	long long int powmod( long long int A, long long int P, long long int M = LLONG_MAX ) {
		long long int ans = 1;
		long long int mul = A;
		for( ; P > 0; P >>= 1, mul = (mul*mul) % M ) {
			if( (P & 1) == 1 ) ans = (ans*mul) % M;
		}
		return ans;
	}

	//nCk mod m
	long long int cb( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( N < combinationThreshold ) {// ???????¨????O(N)??????????????????O(1)
			if( inv.size() == 0 ) {
				inv = vector<long long int>( combinationThreshold );
				inv[1] = 1;
				for( long long int i = 2; i < combinationThreshold; i++ ) {
					inv[i] = M - (M / i)*inv[M%i] % M;
				}
				fact = vector<long long int>( combinationThreshold );
				fact[0] = 1;
				revFact = vector<long long int>
					( combinationThreshold );
				revFact[0] = 1;
				for( long long int i = 1; i < combinationThreshold; i++ ) {
					fact[i] = (fact[i - 1] * i) % M;
					revFact[i] = (revFact[i - 1] * inv[i]) % M;
				}
			}
			return (((fact[N] * revFact[K]) % M)*revFact[N - K]) % M;
		} else {
			return cbOnce( N, K, M );
		}
	}

	//???????????????????????? O(K + log(M))
	long long int cbOnce( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( K > N / 2 ) return cb( N, N - K, M );
		long long int ans = 1;
		long long int div = 1;
		for( long long int i = 0; i < K; i++ ) {
			ans *= N - i;
			ans %= M;
			div *= i + 1;
			div %= M;
		}
		ans *= powmod( div, M - 2, M );
		return ans%M;
	}

private:
	vector<vector<long long int>>C;//3000??\????????????
	vector<long long int>fact;//??????
	vector<long long int>revFact;//???????????????
	vector<long long int>inv;//mod p??§?????????

	long long int combinationThreshold;//N????????§?????????????????°??\?????????
};

int main() {
	combination cb;
	long long int m, n;
	cin >> m >> n;
	cout << cb.powmod( m, n, 1000000007LL ) << endl;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int A,B;
  int ans = 0;
  cin >> A >> B;
  int total = 1;
  while(total < B) {
    ans++;
    total = total + A - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# Python Program to find the count of 
# numbers in a range where the number 
# does not contain more than K non 
# zero digits 

# This function returns the count of 
# required numbers from 0 to num 
def countInRangeUtil(pos, cnt, tight, num): 

	# Last position 
	if pos == len(num): 

		# If count of non zero digits 
		# is less than or equal to K 
		if cnt == K: 
			return 1
		return 0

	# If this result is already computed 
	# simply return it 
	if dp[pos][cnt][tight] != -1: 
		return dp[pos][cnt][tight] 

	ans = 0

	# Maximum limit upto which we can place 
	# digit. If tight is 1, means number has 
	# already become smaller so we can place 
	# any digit, otherwise num[pos] 
	limit = 9 if tight else num[pos] 

	for dig in range(limit + 1): 
		currCnt = cnt 

		# If the current digit is nonzero 
		# increment currCnt 
		if dig != 0: 
			currCnt += 1

		currTight = tight 

		# At this position, number becomes 
		# smaller 
		if dig < num[pos]: 
			currTight = 1

		# Next recursive call 
		ans += countInRangeUtil(pos + 1, currCnt, currTight, num) 

	dp[pos][cnt][tight] = ans 
	return dp[pos][cnt][tight] 

# This function converts a number into its 
# digit vector and uses above function to compute 
# the answer 
def countInRange(x): 
	global dp, K, M 
	num = [] 
	while x: 
		num.append(x % 10) 
		x //= 10
	num.reverse() 
	dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
	return countInRangeUtil(0, 0, 0, num) 

# Driver Code 

# states - position, count, tight 
dp = [] 
M = 101

# K is the number of non zero digits 
K = 0

L = 1
R = int(input())
K = int(input())
print(countInRange(R) - countInRange(L - 1))

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int z[3]; z[0]=a; z[1]=b; z[2]=c;
    sort(z,z+3);
    if(z[0]+z[1]==z[2]) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=212345;

ll h[nmax],cnt[nmax],s[nmax];
pair<long double,ll> df[nmax];

int main()
{
    ll n,c,l,r,lmax=0,rmax=0,pos=0;
    long double df2;
    scanf("%lld %lld",&n,&c);
   for(ll i=0; i<n; ++i)
        scanf("%lld",&h[i]);
    ll i=1;
    s[0]=h[0]*h[0];
    while(i<n)
    {
        while(lmax<=rmax && df[lmax].first<=h[i])
        {
            ++lmax;
        }
        --lmax;
        pos=lmax;
        cnt[i]=cnt[df[pos].second]+(h[i]-h[df[pos].second])*(h[i]-h[df[pos].second])+c;
        s[i]=cnt[i]+h[i]*h[i];
        df2=(long double)(s[i]-s[df[rmax].second])/(h[i]-h[df[rmax].second])/2;
        if(pos==rmax || df2>df[rmax].first)
        {
            ++rmax;
            df[rmax]=make_pair(df2,i);
        }
        else
        {
            l=pos;
            r=rmax;
            while(l<=r)
            {
                pos=(l+r)/2;
                df2=(long double)(s[i]-s[df[pos].second])/(h[i]-h[df[pos].second])/2;
                if(df[pos].first<df2)
                {
                    l=pos+1;
                }
                else
                {
                    r=pos-1;
                }
            }
            df2=(long double)(s[i]-s[df[r].second])/(h[i]-h[df[r].second])/2;
            if(df2<=df[l].first)
            {
                df[l]=make_pair(df2,i);
                rmax=l;
            }
        }
        ++i;
    }
    printf("%lld\n",cnt[n-1]);
    return 0;
}


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

int n;
string s;
char used[100010];
string dfs(char first, char second) {

  for(int i=0;i<n+3;i++)
    used[i] = -1;
  used[0] = first;
  used[n-1] = second;
  char next;
  string ret = {first};
  char pre1 = first, pre2 = second;
  for(int i=0;i<n;i++) {
    if(pre1 == 'S' && pre2 == 'S') {
      if(s[i] == 'o')
        next = 'S';
      else
        next = 'W';
    } else if(pre1 == 'S' && pre2 == 'W') {
      if(s[i] == 'o')
        next = 'W';
      else
        next = 'S';
    } else if(pre1 == 'W' && pre2 == 'S') {
      if(s[i] == 'o')
        next = 'W';
      else
        next = 'S';
    } else {
      if(s[i] == 'o')
        next = 'S';
      else
        next = 'W';
    }
    if(used[i+1] == -1) {
      used[i+1] = next;
    } else {
      if(used[i+1] != next)
        return "";
    }
    pre2 = pre1;
    pre1 = next;
    if(i < n - 1)
      ret += next;
  }
  if(used[n] == used[0])
    return ret;
  else
    return "";

}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> s;

  string ans;
  vector<char> v1 = {'S', 'W'};
  for(int i=0;i<2;i++) {
    for(int j=0;j<2;j++) {
      ans = dfs(v1[i], v1[j]);
      if(ans != "") {
        cout << ans  << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;


}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int R;
    cin>>R;
    cout<<2*PI*R<<endl;

}

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

int main() {
 string x;
 cin>>x;
 
 int sum = 0;
 
 for(int64_t i = 0;i<x.size();i++) {
  sum+=(int)x.at(i)-48;
  
  }
 
 
 
 if(sum%9==0){
  cout << "Yes";
  } else {
   cout << "No";
   }
 
}

Measured memory_bytes: 3668
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,i,s,t;
deque<int> d(100);
inline void solve(){
  IN(N);
  REP(i,N)IN(d[i]);
  sort(RALL(d));
  REP(i,N){
    if(i&1)t+=d[i];
    else s+=d[i];
  }
  OUT(s-t);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

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

	int index = 0;
	vector<int> input(1);
	do{
		cin >> input[index];
		index++;
		input.push_back(0);
	} while (input[index - 1] != 0);
	for (int i = 0; i < index - 1; i++){
		cout << "Case " << i + 1 << ": " << input[i] << "\n";
	}

	return 0;
}


Measured memory_bytes: 3212
import sys
input = sys.stdin.readline

def solve():
    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def setInit(As):
        for iB, A in enumerate(As, 1):
            data[iB] = A
        for iB in range(1, numPow2):
            i = iB + (iB & -iB)
            data[i] += data[iB]
    def addValue(iA, A):
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(iA):
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans
    def getRangeSum(iFr, iTo):
        return getSum(iTo) - getSum(iFr-1)


    N, Q = map(int, input().split())
    As = list(map(int, input().split()))

    data, numPow2 = makeBIT(N)
    setInit(As)

    anss = []
    for _ in range(Q):
        t, i, j = map(int, input().split())
        if t == 0:
            addValue(i, j)
        else:
            anss.append(getRangeSum(i, j-1))

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 80992
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next()+"R";
    int n=s.length()-1;
    int[] ans=new int[n];
    int l=0;
    int c;
    while(l<n-1){
      c=s.indexOf("RL",l);
      int r=s.indexOf("LR",c);
      ans[ c ]=(c-(l-1)+1)/2+(r-c  )/2;
      ans[c+1]=(c-(l-1)  )/2+(r-c+1)/2;
      l=r+1;
    }
    for(int i=0;i<n-1;i++){
      System.out.print(ans[i]+" ");
    }
    System.out.println(ans[n-1]);
  }
}

Measured memory_bytes: 41356
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long x=0;
    for(long long i=2;i*i<=n;i++){
        if(n%i==0){
            long long N=n;
            while(N%i==0)N/=i;
            if(N%i==1)x++;
        }
    }
    n--;
    long long yakusu=1;
    for(long long i=2;i*i<=n;i++){
        int p=0;
        while(n%i==0){
            n/=i;
            p++;
        }
        yakusu*=p+1;
    }
    if(n>1)yakusu*=2;
    cout<<x+yakusu<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main() {
    int bingos[3][3] = {0};
    bool bingos_mark[3][3] = {false};
    int ninp;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            scanf("%d", &bingos[i][j]);
        }
    }
    scanf("%d", &ninp);
    for (int i = 0; i < ninp; i++) {
        int te;
        scanf("%d", &te);
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (te == bingos[i][j]) {
                    bingos_mark[i][j] = true;
                }
            }
        }
    }

    if (bingos_mark[0][0] && bingos_mark[1][1] && bingos_mark[2][2]) {
        printf("Yes");
    } else if (bingos_mark[0][2] && bingos_mark[1][1] && bingos_mark[2][0]) {
        printf("Yes");
    } else if (bingos_mark[0][0] && bingos_mark[0][1] && bingos_mark[0][2]) {
        printf("Yes");
    } else if (bingos_mark[1][0] && bingos_mark[1][1] && bingos_mark[1][2]) {
        printf("Yes");
    } else if (bingos_mark[2][0] && bingos_mark[2][1] && bingos_mark[2][2]) {
        printf("Yes");
    } else if (bingos_mark[0][0] && bingos_mark[1][0] && bingos_mark[2][0]) {
        printf("Yes");
    } else if (bingos_mark[0][1] && bingos_mark[1][1] && bingos_mark[2][1]) {
        printf("Yes");
    } else if (bingos_mark[0][2] && bingos_mark[1][2] && bingos_mark[2][2]) {
        printf("Yes");
    } else {
        printf("No");
    }
}

Measured memory_bytes: 1696
import math
def comb(n, r):
  if n - r >= 0:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    return 0
N = int(input())
string = {}
res = 0
for i in range(N):
  s = str(sorted(input()))
  if s in string:
    string[s] += 1
  else:
    string[s] = 0
for key in string:
  res += comb(string[key] + 1, 2)
print(res)

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

using namespace std;
 
int main() {

	int n;
	cin>>n;

	if(n==1) {

		cout<<0<<endl;
		return 0;
	}

	long long int mod = 1e9+7;

	long long int a = 1, b = 1, c = 1;

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

		a = (a * 10) % mod;
	}

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

		b = (b * 9) % mod;
	}
	b = (b*2) % mod;

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

		c = (c * 8) % mod;
	}

	long long int ans;
	ans = (a-b+mod) % mod;
	ans = (ans+c+mod) % mod;
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1LL << 30;

// dp[i] := i+1番目の増加部分列の最終要素(最大化)
int dp[101010];
    
int main() {
    int n, mx;
    cin >> n;
    vector< int > a(n);
    for (int i=0; i<n; ++i) {
        cin >> a[i];
        mx = max(a[i], mx);
    }
    fill_n(dp, n, INF);
    
    for (int i=0; i<n; ++i) {
        *lower_bound(dp, dp+n, a[i]) = a[i];
    }
    
    int ans = (lower_bound(dp, dp+n, INF) - dp);
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;
const int INF = 1 << 12;

typedef pair<int, int> P;
int H, W;
string S[30];

int bfs(int y, int x) {
    queue<P> q;
    q.push(P(y, x));
    int d[30][30];

    rep(i, H) {
        rep(j, W) {
            d[i][j] = INF;
        }
    }

    d[y][x] = 0;

    while(q.size()) {
        P p = q.front(); q.pop();
        int i = p.first;
        int j = p.second;
        if (i > 0 && S[i-1][j] == '.') {
            if (d[i-1][j] == INF) {
                q.push(P(i-1, j));
                d[i-1][j] = d[i][j] + 1;
            }
        }
        if (i < H-1 && S[i+1][j] == '.' && (d[i+1][j] == INF)) {
            q.push(P(i+1, j));
            d[i+1][j] = d[i][j] + 1;
        }
        if (j > 0 && S[i][j-1] == '.' && (d[i][j-1] == INF)) {
            q.push(P(i, j-1));
            d[i][j-1] = d[i][j] + 1;
        }
        if (j < W-1 && S[i][j+1] == '.' && (d[i][j+1] == INF)) {
            q.push(P(i, j+1));
            d[i][j+1] = d[i][j] + 1;
        }
    }

    int m = 0;
    rep(i, H) {
        rep(j, W) {
            if (d[i][j] != INF) m = max(m, d[i][j]);
        }
    }
    return m;
}

int main() {
    cin >> H >> W;
    rep (i, H) cin >> S[i];

    int res = 0;

    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '.') {
                res = max(res, bfs(i, j));
            }
        }
    }

    cout << res << endl;
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  if((N-1)%(K-1)==0){
    cout << (N-1)/(K-1) << endl;
  }else{
    cout << ((N-1)/(K-1)) + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5+10;
const int mod = 1000000007;
using namespace std;

int N;
ll f[maxn][2];
int h[maxn],e[maxn*2],ne[maxn*2],idx;
void add(int a,int b){
    e[++idx] = b,ne[idx] = h[a],h[a] = idx;
}

void dfs(int u,int fa = -1){
    bool isyz = true;
    for(int i = h[u]; i ;i = ne[i]){
        int v = e[i];
        if(v == fa) continue;
        isyz = false;
        dfs(v,u);
    }
    if(isyz) f[u][1] = 1,f[u][0] = 1;
    else{
        ll black =  1,white = 1;
        for(int i = h[u]; i; i = ne[i]){
            int v = e[i];
            if(v == fa) continue;
            black *= f[v][1]; black %= mod;
            white *= (f[v][1] + f[v][0])%mod; white %= mod;
        }
        f[u][0] = black,f[u][1] = white;
    }
}
int main(){
    // debug;
    ios;

    cin>>N;
    for(int i = 1;i<=N-1;i++){
        int x,y;cin>>x>>y;
        add(x,y);
        add(y,x);
    }
    dfs(1);
    cout<<(f[1][0] + f[1][1])%mod;

    
    return 0;
}


Measured memory_bytes: 7936
my $line = <STDIN>; chomp($line);
my $line1 = <STDIN>; chomp($line1);


my ($H,$W) = split /\s/, $line;
my ($h,$w) = split /\s/, $line1;

my $result = ($H * $W) - ($h * $w) - (($H - $h) * $w) - (($W - $w) * $h);

print $result."\n";

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

const int dx[3]={-1,0,1};

int w,h,ans;
queue<pair<int,int>> que;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> w >> h,w){
        vector<vector<int>> m(h,vector<int>(w));
        for (int i=0;i<h;++i)
            for (int j=0;j<w;++j)
                cin >> m[i][j];
        vector<vector<int>> visited(h,vector<int>(w,0));
        ans=0;
        for (int i=0;i<h;++i){
            for (int j=0;j<w;++j){
                if (visited[i][j]||!m[i][j]) continue;
                ++ans;
                visited[i][j]=1; que.emplace(i,j);
                while(!que.empty()){
                    pair<int,int> p=que.front(); que.pop();
                    for (int k=0;k<3;++k){
                        for (int l=0;l<3;++l){
                            int nh=p.first+dx[k],nw=p.second+dx[l];
                            if (nh<0||h<=nh||nw<0||w<=nw) continue;
                            if (visited[nh][nw]||!m[nh][nw]) continue;
                            visited[nh][nw]=1; que.emplace(nh,nw);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3196
#include <stdio.h>
int main(void){
	int a[100]={0},n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>=0;i--){
		printf("%d",a[i]);
		if(!(i==0)){
			printf(" ");
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 612
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

a,b,k = na()

c =min(a,b)
d = 0
while(1):
  if a%c == 0 and b%c == 0:
    d += 1
  if d == k:
    break
  c -= 1
  
print(c)

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

def comb(n, r):
    result = 1
    for i in range(r):
        result = int(result * (n - i) / (i + 1))

    return result

# Nを取得
n = int(input())

# Aiを取得
a_list = list(map(int, input().split()))

# 昇順にソートしたAiを取得
a_sorted = sorted(a_list)

# 最大値およびその1/2の値を取得
a_max = max(a_sorted)

# comb(n,r)が最大になるrを取得
r = 0
d_min = a_max + 1
for a in a_sorted:
    d = abs(a_max - (2 * a))
    if d < d_min:
        d_min = d
        r = a
    else:
        break

# c = comb(a_max, r)

# 結果を出力
print("{} {}".format(a_max, r))


Measured memory_bytes: 14428
dp = Array.new(10){ Array.new(1001){0} }
dp[0][0] = 1

0.upto(100) do |i|
  1000.downto(0) do |j|
    9.downto(1) do |k|
      dp[k][j] += dp[k-1][j-i] if (j-i) >= 0
    end
  end
end

while gets do
  n, s = $_.split(' ').map(&:to_i)
  break if n == 0 and s == 0
  puts dp[n][s]
end

Measured memory_bytes: 6184
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,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)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
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);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


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

  int n;
  cin>>n;
  vector<int> A(n); iota(A.begin(), A.end(), 1);
  do{
    cout<<A<<endl;
  }while(next_permutation(A.begin(), A.end()));

  
  
  return 0;
}



Measured memory_bytes: 3148
require 'pp'
n = gets.to_i # 箱番号ラスト
a = gets.split.map(&:to_i)
b = Array.new(n)
b_count = 0
n.downto(1) do |i| # 箱番号
  sum = 0
  ii = i# iiは、増えていく用の箱番号
  ii += i
  while ii <= n
    # p [sum,i,ii,n,b]
    sum += b[ii-1]
    ii += i
  end
  if sum % 2 == a[i-1]
    b[i-1] = 0
  else
    b_count += b[i-1] = 1
  end
end
p b_count
puts b.map.with_index(1){|bb,i|bb == 1 ? "#{i} " : ''}.join.chop


Measured memory_bytes: 30204
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    L = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    print(10 * L[0] + L[1] + L[2])

Measured memory_bytes: 5072
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    string s;
    int q;cin>>s>>q;
    int cnt = 0;
    int d = 0;
    rep(i,q){
        int a;cin>>a;
        if(a == 1)cnt++;
        if(a == 2){
            int b;
            char c;cin>>b>>c;
            if(cnt%2==1){
                d++;
                if(b == 1)b = 2;
                else if(b == 2)b = 1;
            }
            if(b == 1)s.insert(s.begin(),c);
            if(b == 2)s.push_back(c);
        }
    }
    if(cnt%2==1)reverse(ALL(s));
    cout<<s<<endl;
}



Measured memory_bytes: 900
N=int(input())
s=[]
for i in range(N):
    s.append(input())
M=int(input())
t=[]
for i in range(M):
    t.append(input())
res=0
for i in range(N):
    res=max(res, s.count(s[i])-t.count(s[i]))
print(res)

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

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

    int cnt = 0;
    int cnt_even = 0;
    int cnt_odd = 0;
    int ind = 0;
    bool flag_l_even = false;
    std::vector<int> ans(S.size(), 0);

    S.push_back('E');
    for (int i = 0; i < S.size() - 1; i++)
    {
        // カウントアップ
        if (cnt % 2 == 0) cnt_even++;
        else cnt_odd++;
        cnt++;

        // (R, L) の境目にきたらインデックスを保持
        if (S[i] == 'R' && S[i+1] == 'L')
        {
            // インデックス保持
            ind = i;

            // L が偶数だったら L(i+1) に cnt_even を設定する
            if (cnt % 2 == 0) flag_l_even = true;
        }

        // (L, R) の境目にきた or 最後まできたら子供の人数を格納
        if ( (S[i] == 'L' && S[i+1] == 'R') | (S[i] == 'L' && S[i+1] == 'E') )
        {
            if (flag_l_even == false)
            {
                ans[ind] = cnt_even;
                ans[ind+1] = cnt_odd;
            }
            else if (flag_l_even == true)
            {
                ans[ind] = cnt_odd;
                ans[ind+1] = cnt_even;
            }
            cnt_even = 0;
            cnt_odd = 0;
            cnt = 0;
            flag_l_even = false;
        }
    }

    // 結果表示
    for (int i = 0; i < ans.size(); i++) std::cout << ans[i] << " ";
    std::cout << std::endl;


    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

typedef struct { int h, w, **c; } square_t;

static int largest_square(square_t s) {
  int i, j, max;

  for (i = max = 0; i < s.h; ++i) {
    for (j = 0; j < s.w; ++j) {
      if (s.c[i][j] > 0) {
        s.c[i][j] = 0;
      } else if (i == 0 || j == 0) {
        s.c[i][j] = !s.c[i][j];
      } else if (s.c[i-1][j-1] <= s.c[i-1][j] && s.c[i-1][j-1] <= s.c[i][j-1]) {
        s.c[i][j] = s.c[i-1][j-1] + 1;
      } else if (s.c[i-1][j] <= s.c[i-1][j-1] && s.c[i-1][j] <= s.c[i][j-1]) {
        s.c[i][j] = s.c[i-1][j] + 1;
      } else {
        s.c[i][j] = s.c[i][j-1] + 1;
      }
      if (max < s.c[i][j]) max = s.c[i][j];
    }
  }
  return max * max;
}

int main(int argc, char **argv) {
  square_t s;
  int i, j;

  scanf("%d %d", &s.h, &s.w);
  s.c = (int **) malloc(sizeof(int *) * s.h);
  for (i = 0; i < s.h; ++i) {
    s.c[i] = (int *) malloc(sizeof(int) * s.w);
    for (j = 0; j < s.w; ++j) scanf("%d", &s.c[i][j]);
  }
  printf("%d\n", largest_square(s));
  for (i = 0; i < s.h; ++i) free(s.c[i]);
  free(s.c);
}


Measured memory_bytes: 9136
import math
N,D=map(int,input().split())
X = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N-1):
    for k in range(j+1,N):
        L = 0
        for l in range(D):
            L += (X[j][l]-X[k][l])**2
        if math.sqrt(L).is_integer() == True:
            count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll h[100001],n,a,b;
bool test(ll m){
    ll res=0;
    rep(i,n){
        if(h[i]-b*m<=0) continue;
        int u=0;
        if((h[i]-b*m)%(a-b)!=0) u=1;
        res+=(h[i]-b*m)/(a-b)+u;
    }
    if(res>m) return true;
    else return false;
}
int main(){
    int hi;
    cin>>n>>a>>b;
    rep(i,n){
        cin>>h[i];
    }
    ll lb=0,ub=1000100010;
    while(ub-lb>1){
        ll mid=(ub+lb)/2;
        if(test(mid)) lb=mid;
        else ub=mid;
    }
    cout<<ub<<endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;

ll k;
ll a[maxN];
int n;

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

	cin >> n >> k;

	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[i] += a[i - 1];
	}
	
	map<ll, ll> cnt;
	cnt[(a[0] - 0) % k]++;
	ll fRes = 0;
	for(int i = 1; i <= n; i++){
		if(i >= k){
			cnt[(a[i - k] - (i - k)) % k]--;
		}
		ll rem = (a[i] - i) % k;
		fRes += cnt[rem];
		cnt[rem]++;
	}

	cout << fRes << '\n';

	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
int H, W, x, y;
void solve()
{
    double ans;
    ans = (H * W) / 2.0;
    cout << ans << " ";
    if (x * 2 == W && y * 2 == H) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> W >> H >> x >> y;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct{
  char name[100];
  int t;
}P;

void initialize();
char isEmpty();
char isFull();
void enqueue(P);
P dequeue();

P Q[LEN+1];
int head,tail,n,MAX;

int main(){
  int elaps=0,c;
  int i,q;
  P u;

  scanf("%d%d",&n,&q);
  initialize();
  MAX = n+1;
  for(i = 0; i < n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
    tail++;
  }
  
  while(head != tail){
    u = dequeue();
    if(u.t > q){
      u.t -= q;
      elaps += q;
      enqueue(u);
    }
    else{
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}


void initialize(){
  head = tail = 0;
}

char isEmpty(){
  return head == tail;
}

char isFull(){
  return head == (tail + 1) % MAX;
}

void enqueue(P x){
  if(isFull()){
    printf("エラー（オーバーフロー）\n");
    exit(1);
  }
  Q[tail] = x;
  if(tail + 1 == MAX)
    tail = 0;
  else
    tail++;

}

P dequeue(){
  P x;
  if(isEmpty()){
    printf("エラー（アンダーフロー）\n");
    exit(1);
  }
  x = Q[head];
  if(head + 1 == MAX)
    head = 0;
  else
    head++;
  return x;
}




Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

ll k,n,a[200010],ans=0;

int main(void){
	cin>>k>>n;
	rep(i,n)cin>>a[i];
	a[n]=a[0]+k;
	rep(i,n)ans=max(ans,a[i+1]-a[i]);
	cout<<k-ans<<endl;
	return 0;
}

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

using namespace std;

int MOD = 1000000007;
int A=0;
int C=1;
int G=2;
int T=3;

class Vertex{
public:
    int a, b, c;
    int count;
    Vertex(int aa, int bb, int cc, int cnt){
        a=aa;
        b=bb;
        c=cc;
        count=cnt;
    }

    bool operator==(const Vertex &v) const{
        if(a == v.a && b == v.b && c == v.c){
            return true;
        }
        return false;
    }

    inline bool operator!=(const Vertex& v) const{
        return !(*this == v);
    }
};


vector<Vertex> next_vertex(Vertex v){
    vector<Vertex> vv;
    if(v.a==A && v.b==C && v.c==G){
        return vv;
    }
    if(v.a==A && v.c==C){
        vv.push_back(Vertex(v.b, v.c, A, v.count));
        vv.push_back(Vertex(v.b, v.c, C, v.count));
        vv.push_back(Vertex(v.b, v.c, T, v.count));
        return vv;
    }
    if(v.a==A && v.b==C){
        vv.push_back(Vertex(v.b, v.c, A, v.count));
        vv.push_back(Vertex(v.b, v.c, C, v.count));
        vv.push_back(Vertex(v.b, v.c, T, v.count));
        return vv;
    }
    if(v.b==A && v.c==C){
        vv.push_back(Vertex(v.b, v.c, A, v.count));
        vv.push_back(Vertex(v.b, v.c, C, v.count));
        vv.push_back(Vertex(v.b, v.c, T, v.count));
        return vv;
    }
    vv.push_back(Vertex(v.b, v.c, A, v.count));
    vv.push_back(Vertex(v.b, v.c, C, v.count));
    vv.push_back(Vertex(v.b, v.c, G, v.count));
    vv.push_back(Vertex(v.b, v.c, T, v.count));
    return vv;
}

int main(){
    long N;
    cin>>N;

    vector<int> a;
    for(int i=0; i<4; ++i){
        a.push_back(i);
    }
    vector<Vertex> now, next;
    for(int i=0; i<4; ++i){
        for(int j=0; j<4; ++j){
            for(int k=0; k<4; ++k){
                if(i==0 && j==1 && k==2){
                }else if(i==0 && j==2 && k==1){
                }else if(i==1 && j==0 && k==2){
                }else{
                    now.push_back(Vertex(a[i], a[j], a[k], 1));
                    next.push_back(Vertex(a[i], a[j], a[k], 0));
                }
            }
        }
    }


    for(int i=3; i<N; ++i){
        for(int j=0; j<now.size(); ++j){
            vector<Vertex> nn = next_vertex(now[j]);
        for(int l=0; l<nn.size(); ++l){
            for(int k=0; k<next.size(); ++k){
                if(nn[l] == next[k]){
                    next[k].count += nn[l].count;
                    next[k].count %= MOD;
                }
            }
        }
        }

        now = next;
        for(int j=0; j<next.size(); ++j){
            next[j].count = 0;
        }
    }

    long ans=0;
    for(int i=0; i<now.size(); ++i){
        ans+=now[i].count;
        ans%=MOD;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
fun hey(N: Int, points: Array<Pair<Long, Long>>) {
    if (N == 1) {
        println(1)
        return
    }

    val possiblePairs = mutableListOf<Pair<Long, Long>>()
    (0..(N - 1)).forEach { a ->
        (0..(N - 1)).forEach { b ->
            if (a != b) {
                val p = points[b]!!.first - points[a]!!.first
                val q = points[b]!!.second - points[a]!!.second
                possiblePairs.add(Pair(p, q))
            }
        }
    }

    var cost = Int.MAX_VALUE
    var fake = Int.MAX_VALUE
    possiblePairs.forEach {
        val p = it.first
        val q = it.second

        var sub = 0
        (0..(N-1)).forEach { i ->
            (0..(N-1)).forEach { j ->
                if (i != j) {
                    if ((points[i].first - points[j].first) == p && (points[i].second - points[j].second) == q) {
                        sub++
                    }
                }
            }
        }
cost = Math.min(cost, N - sub)
    }
    println(cost)
}

fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val points: Array<Pair<Long, Long>> = Array(N, { Pair(0L, 0L) })
    (1..N).forEach {
        val (x, y) = readLine()!!.split(" ").map { it.toLong() }
        val pair = Pair(x, y)
        points[it - 1] = pair
    }
    hey(N, points)
}

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

#define FIND(c, e) ((c).find(e) != (c).end())
#define NFIND(c, e) ((c).find(e) == (c).end())
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int( 2e5 ) + 10;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
template<class T> T gcd(T a,T b){while(b){T r=a%b;a=b;b=r;}return a;}
template<class T> T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T> T max(T a,T b,T c){return max(max(a,b),c);}
template<class T> T min(T a,T b,T c){return min(min(a,b),c);}

void __answer()
{
    int n, a;
    cin >> n;
    set<int> s;
    while(n--) {
        cin >> a;
        if(FIND(s, a)) {
            s.erase(a);
        } else s.insert(a);
    }
    cout << s.size() << endl;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(11) << fixed;
    #ifdef LOCAL
        freopen("TEST.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,i,k,sum=0;
  string a;
  cin >> n;
  map<string,int>mp;
  
  for(i=0;i<n;i++){
    cin >> a;
    sort(a.begin(),a.end());
    mp[a]++;
  }

  for(auto p : mp){
    k = p.second;
    sum += (long long int)k*(k-1)/2;
  }

  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	Yn(s[2]==s[3]&&s[4]==s[5]);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const N_MAX = 300;
double dp[N_MAX][N_MAX][N_MAX];
ll N;

double recursion(ll d1, ll d2, ll d3) {
  if (d1 == 0 && d2 == 0 && d3 == 0) {
    return 0;
  }
  if (dp[d1][d2][d3] > 0) {
    return dp[d1][d2][d3];
  }
  double expected = N;
  if (d1 > 0) expected += d1 * recursion(d1 - 1, d2, d3);
  if (d2 > 0) expected += d2 * recursion(d1 + 1, d2 - 1, d3);
  if (d3 > 0) expected += d3 * recursion(d1, d2 + 1, d3 - 1);
  expected /= (double)(d1 + d2 + d3);
  dp[d1][d2][d3] = expected;
  return expected;
}

int main() {
  cin >> N;
  vector<ll> a(N), d(3);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
    d[a[i]]++;
  }
  for (int i = 0; i < N_MAX; i++) {
    for (int j = 0; j < N_MAX; j++) {
      for (int k = 0; k < N_MAX; k++) {
        dp[i][j][k] = 0;
      }
    }
  }
  double ans = recursion(d[0], d[1], d[2]);
  cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 211328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,e=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    vector<int> A(5);
    //cin >> x >> y;
    //cin >> s >> t;
    REP(i, 5){
      cin >> A[i];
    }
    cin >> k;
  REP(i,5){
    REP(j,5){
      if((A[i]-A[j])>k){
          cout << ":(";
        return 0;
      }
    }
  }
    cout << "Yay!";
}

Measured memory_bytes: 3528
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define ll long long
using namespace std;
int main() {
	cin.tie(0);	ios::sync_with_stdio(false);
	ll N; cin >> N;
	map<ll, ll> m;
	vector<ll> A(N);
	for (int i = 0; i < N;i++) {
		cin >> A[i];
		m[A[i]]++;
	}
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	ll l = 0, r = 0, size = A.size();
	while (true) {
		if (l == size) break;
		if (m[A[l]] != 1) {
			if (m[A[l]] % 2 == 1) {
				m[A[l]] = 1;
			}
			else {
				m[A[l]] = 1;
				r = l + 1;
				bool f = false;
				while (true) {
					if (r == size) {
						m[A[r - 1]]--;
						f = true;
						break;
					}
					if (m[A[r]] >= 2) {
						m[A[r]]--;
						break;
					}
					r++;
				}
				if (f) break;
			}
		}
		l++;
	}
	ll ans = 0;
	for (auto it = m.begin(); it != m.end();it++) {
		if (it->second == 1) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7296
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	string s;
	cin >> s;
	int l = s.length();
	string ans = "yes";
	int cnt = 0;
		for (int i = 0; i < l;++i) {
			for (int j = i+1; j < l; ++j) {
				if (s[i] == s[j]) ans = "no";
			}
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
LL solve(){
	cin >> K;
	LL now=7;
	REP(i,K+10){
		if(now%K==0) return i+1;
		now=now*10+7;
		now%=K;
	}
	return -1;
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		DEFAULT;
	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 15368
#include <stdio.h>

int main(void) {
  int m, f, r;
  while(1) {
    scanf("%d %d %d", &m, &f, &r);
    if (m == -1 && f == -1 && r == -1) break;
    if (m == -1 || f == -1) {
      puts("F");
    } else if (m + f >= 80) {
      puts("A");
    } else if (m + f >= 65) {
      puts("B");
    } else if (m + f >= 50) {
      puts("C");
    } else if (m + f >= 30) {
      if (r >= 50) {
        puts("C");
      } else {
        puts("D");
      }
    } else {
      puts("F");
    }   
  }
}


Measured memory_bytes: 2056