akhauriyash/Code-Regression huggingface dataset:
MOD = 998244353

n = int(input())
distances = list(map(lambda x: int(x), input().split()))

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in dist_list.keys():
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    pre_v = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            pre_v = v
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        if v==0 and smaller > 1:
            ans = 0

        if v == pre_v - 1:
            ans *= (smaller**bigger)
            ans = ans % MOD
            pre_v = v
        else:
            ans = 0
        
print(ans)

Measured memory_bytes: 19552
N=int(input())
S=input()
L=[[0 for j in range(10)]for i in range(N+1)]
R=[[0 for j in range(10)]for i in range(N+1)]
for i in range(N):
    for j in range(10):
        L[i+1][j]=L[i][j]
    L[i+1][int(S[i])]=1
for i in range(N-1,-1,-1):
    for j in range(10):
        R[i][j]=R[i+1][j]
    R[i][int(S[i])]=1
ans=[[[0 for k in range(10)]for j in range(10)] for i in range(10)]
num=[0 for k in range(10)]
for t in range(N):
    X=[]
    Y=[]
    k=int(S[t])
    if num[k]==100:
        continue
    for x in range(10):
        if L[t][x]==1:
            X.append(x)
    for y in range(10):
        if R[t+1][y]==1:
            Y.append(y)
    for i in X:
        for j in Y:
            if ans[i][j][k]==0:
                ans[i][j][k]=1
                num[k]+=1
print(sum(num))

Measured memory_bytes: 60636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    REP(i,10) REP(j,10) REP(k,10){
        int cnt = 0;
        int cur = 0;
        REP(l,N) if(S[l] - '0' == i){
            cnt++;
            cur = l+1;
            break;
        }
        for(int l=cur;l<N;l++) if(S[l] - '0' == j){
            cnt++;
            cur = l+1;
            break;
        }
        for(int l=cur;l<N;l++) if(S[l] - '0' == k){
            cnt++;
            break;
        }
        
        if(cnt == 3) ans++;
    }
    cout << ans << endl;
}

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

long long gcd(long long x, long long y)
{
    long long a = std::max(x, y);
    long long b = std::min(x, y);

    if (b == 0) return a;
    return gcd(b, a % b);
}

int main()
{
    long long N, X;
    std::cin >> N >> X;

    std::vector<long long> x(N);
    for (long long i = 0; i < N; i++) {
        std::cin >> x[i];
    }
    if (std::find(std::begin(x), std::end(x), X) == std::end(x)) {
        x.push_back(X);
    }

    std::sort(std::begin(x), std::end(x));

    long long ans = 0;
    for (long long i = 0; i < x.size()-1; i++) {
        ans = gcd(x[i+1] - x[i], ans);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define N 100000

int S[N];
int binarySearch(int key, int n)
{
  int left=0,right=n,mid;
    while(left<right){
      mid = (left+right)/2;
      if(S[mid] == key) return 1;
      if(key < S[mid]) right = mid;
      else left = mid+1;
    }
    return 0;
}
int main()
{
  int i,n,m,key,count=0;

  scanf("%d",&n);

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

  scanf("%d",&m);
  for(i=0; i<m; i++){
    scanf("%d",&key);
    if(binarySearch(key,n))count++;
  }
  printf("%d\n",count);
  return 0;
}
    
  



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

#define int long long 

signed main(){
	int a;
	cin>>a;
	for(int g=0; g<3; g++){
	if(a%10==7){
	cout<<"Yes";
	return 0;
	}
	else{
	a=a/10;
	}
	
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3612
(defn input []
  (-> (read-line)
    Integer/parseInt))

(defn CakesAndDonuts [N]
  (if-let [ans (first (for [cake (range 0 (inc N) 4)
                            dounut (range 0 (inc N) 7)
                            :let [n (+ cake dounut)]
                            :when (= N n)] "Yes"))]
    ans
    "No"))

(-> (input)
  CakesAndDonuts
  println)

Measured memory_bytes: 69172
import sys
from collections import Counter
input = sys.stdin.readline

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

ans = []

ans.extend(sorted(p, reverse=True)[:X])
ans.extend(sorted(q, reverse=True)[:Y])
ans.extend(r)
ans.sort(reverse=True)

print(sum(ans[:X+Y]))

Measured memory_bytes: 22968
#include <iostream>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;
void init();
#ifdef DEBUG_BUILD
#define DBG(expr) cout << #expr << " = " << expr << endl;
#endif
#define ECHO(expr) cout << expr << endl;
#define REP(var, num) for(ll var = 0; var < num; var++)
#define REP_FROM(var, from, num) for(ll var = from; var < num; var++)
#define MAX_OF(type) numeric_limits<type>::max()
#define MIN_OF(type) numeric_limits<type>::min()
#define SORT(vec) sort(vec.begin(), vec.end())
#define REVERSE(vec) reverse(vec.begin(), vec.end())
#define ALL(vec) vec.begin(), vec.end()
typedef signed long long ll;
typedef unsigned long long ull;

void solve() {
    ll n;
    vector<string> said;
    cin >> n;
    REP(i, n) {
        string s;
        cin >> s;
        if (find(said.begin(), said.end(), s) != said.end()) {
            ECHO("No")
            return;
        }

        if (i > 0 && said[i - 1][said[i - 1].length() - 1] != s[0]) {
            ECHO("No")
            return;
        }

        said.push_back(s);
    }

    ECHO("Yes")
}

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

#ifdef INPUT_FILE
    if (!freopen(INPUT_FILE, "r", stdin)) {
        perror("freopen");
        exit(1);
    }
#endif

    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,k;
int main(void){
	cin>>a>>b>>k;
	if(k*2>=b-a+1)for(;a<=b;a++)cout<<a<<endl;
	else{
		for(int i=0;i<k;i++)cout<<a+i<<endl;
		for(int i=k-1;i>=0;i--)cout<<b-i<<endl;
	} 
	return 0;
}

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

int main(){
  long long a,b,c;
  cin>>a >>b >>c;
  if(a%2==0||b%2==0||c%2==0){
    cout<<0<<endl;
    return 0;
  }
  cout<<min({a*b,b*c,c*a})<<endl;
  return 0;
}

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

using namespace std;

int N, X;
int A[2000];
int B[2000];

int main()
{
    scanf("%d%d", &N, &X);
    for(int i=0; i<N; i++)
        scanf("%d", A+i), B[i]=A[i];
    long long ans=0x3f3f3f3f3f3f3f3fLL;
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<N; j++)
            B[j]=min(B[j], A[(i+j)%N]);
        ans=min(ans, 1LL*i*X+accumulate(B, B+N, 0LL));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

map<string,int> freq;

int main()
{
	int n;
	while(~scanf("%d",&n)){
		int s;
		scanf("%d",&s);
		
		int* bits = new int[10]();

		for(int i=0;i<n;i++) bits[i] = 1;
		reverse(bits,bits+10);

		if(n==0 && s==0) break;

		int res = 0;
		do{
			int sum = 0;
			for(int i=0;i<10;i++){
				sum += bits[i] ? i : 0;
			}
			//cout << "sum " << sum << endl;
			if(sum == s) res++;
		}while(next_permutation(bits,bits+10));

		cout << res << endl;
	}
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){if(a > b) a = b;}



int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	int n=sz(s);
	cout << string(n, 'x') <<"\n";
	return 0;
}


Measured memory_bytes: 256
local msq = math.sqrt
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local n = io.read("*n")
-- n = k^a(1-kb)
local ret = 0
local lim = mmi(n - 1, mce(msq(n)))
-- a = 0
for i = 1, lim do
  if n - 1 < i * i then break
  elseif n - 1 == i * i then
    ret = ret + 1
  elseif (n - 1) % i == 0 then
    ret = ret + 2
  end
end
-- a = 1, ..., 40
for a = 1, 40 do
  for k = 2, lim do
    local kpow = 1
    for i = 1, a do
      kpow = kpow * k
    end
    if n < kpow then break end
    if n % kpow == 0 then
      local v = n // kpow
      if v % k == 1 then
        ret = ret + 1
      end
    end
  end
end
print(ret)


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
using gragh = vector<vector<int>>;



int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if (a+c+b >=22){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }




}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int n,x;
vector<int> v;
map<int,bool> mp;
int ans,d;
int main(){
  cin >> n >> x;
  v.push_back(x);
  REP(i,n){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  REP(i,v.size()-1){
    d = v[i+1] - v[i];
    mp[d] = true;
  }
  ans = d;
  for(auto x:mp){
    ans = gcd(ans, x.first);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  long long R = 0, G = 0, B = 0;
  for (char c : S){
    if (c == 'R'){
      R++;
    }
    if (c == 'G'){
      G++;
    }
    if (c == 'B'){
      B++;
    }
  }
  long long ans = R * G * B;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      if ((i + j) % 2 == 0){
        int k = (i + j) / 2;
        if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]){
          ans--;
        }
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
struct A{
    ll t,a;
}a[10000];
char c[10000];
int main(){
    /*ll n;
    sld(n)
    for(ll i = 0; i < n; i ++){
        sld(a[i].t) sld(a[i].a)
    }*/
    ss(c);

    int lenc = len(c);
    int p = 0;
    int sum = 0;
    for(int i = 0; i < lenc; i ++){
        if(c[i] == 'g'){
            if(p > 0){
                p --;
                sum ++;
            }else if(p == 0){
                p++;
            }
        }else if(c[i] == 'p'){
            if(p > 0){
                p --;
            }else if(p == 0){
                p ++;
                sum --;
            }
        }
    }
    p(sum) pn


    return 0;

}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int K,X;
  cin>>K>>X;
  FOR(i,X-K+1,X+K){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int ans = X % 1000;
		if(ans!=0) ans -= 1000;
		System.out.println(Math.abs(ans));
	}
}


Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()

void ans(vector<bool>&V) {
	for (bool i : V) {
		if (i)cout << 'S';
		else cout << 'W';
	}
	cout << endl;
}

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<bool> A(N);

	// 1が羊 Nが羊
	A[0] = 1;
	if (S[0] == 'o')A[1] = 1;
	else A[1] = 0;
	for (int i = 1;i < N - 1;i++) {
		if (S[i] == 'o') {
			if (A[i])A[i + 1] = A[i - 1];
			else A[i + 1] = !A[i - 1];
		}
		else {
			if (A[i])A[i + 1] = !A[i - 1];
			else A[i + 1] = A[i - 1];
		}
	}
	if (A[N - 1]) {
		if (S[N - 1] == 'o' && A[N - 2] == A[0]) {
			ans(A);
			return 0;
		}
		if (S[N - 1] == 'x' && A[N - 2] != A[0]) {
			ans(A);
			return 0;
		}
	}

	// 1が羊 Nが狼
	A[0] = 1;
	if (S[0] == 'o')A[1] = 0;
	else A[1] = 1;
	for (int i = 1;i < N - 1;i++) {
		if (S[i] == 'o') {
			if (A[i])A[i + 1] = A[i - 1];
			else A[i + 1] = !A[i - 1];
		}
		else {
			if (A[i])A[i + 1] = !A[i - 1];
			else A[i + 1] = A[i - 1];
		}
	}
	if (!A[N - 1]) {
		if (S[N - 1] == 'o' && A[N - 2] != A[0]) {
			ans(A);
			return 0;
		}
		if (S[N - 1] == 'x' && A[N - 2] == A[0]) {
			ans(A);
			return 0;
		}
	}

	// 1が狼 Nが羊
	A[0] = 0;
	if (S[0] == 'o')A[1] = 0;
	else A[1] = 1;
	for (int i = 1;i < N - 1;i++) {
		if (S[i] == 'o') {
			if (A[i])A[i + 1] = A[i - 1];
			else A[i + 1] = !A[i - 1];
		}
		else {
			if (A[i])A[i + 1] = !A[i - 1];
			else A[i + 1] = A[i - 1];
		}
	}
	if (A[N - 1]) {
		if (S[N - 1] == 'o' && A[N - 2] == A[0]) {
			ans(A);
			return 0;
		}
		if (S[N - 1] == 'x' && A[N - 2] != A[0]) {
			ans(A);
			return 0;
		}
	}

	// 1が狼 Nが狼
	A[0] = 0;
	if (S[0] == 'o')A[1] = 1;
	else A[1] = 0;
	for (int i = 1;i < N - 1;i++) {
		if (S[i] == 'o') {
			if (A[i])A[i + 1] = A[i - 1];
			else A[i + 1] = !A[i - 1];
		}
		else {
			if (A[i])A[i + 1] = !A[i - 1];
			else A[i + 1] = A[i - 1];
		}
	}
	if (!A[N - 1]) {
		if (S[N - 1] == 'o' && A[N - 2] != A[0]) {
			ans(A);
			return 0;
		}
		if (S[N - 1] == 'x' && A[N - 2] == A[0]) {
			ans(A);
			return 0;
		}
	}

	cout << -1 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<stdlib.h>
#include<cstring>
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    while(n)
    {
        sum+=n%10;
        n/=10;
    }
    if(sum==1)
        sum=10;
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 256
m, d  = map(int, input().split())

cnt = 0

if m <= 3 or d <= 21:
	print(0)
else:
	for i in range(22,d+1):
			d10 = int(i/10)
			d1 = int(i%10)
			# print(d1)
			# print(d10)
			if d1 >= 2 and d10 >= 2 and d1*d10  <= m:
				cnt += 1

	print(cnt)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<map>
#include<vector>
#define rep(i,a) for(int i=0;i<a;i++)
#define pb push_back
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n,m;cin>>n;
	map<string,int>tmp;
	vi ne(n);
	rep(i,n){
		string s;cin>>s>>ne[i];
		tmp[s]=i;
	}
	cin>>m;
	vi p,q;
	rep(i,m){
		string a,b;cin>>a>>b;
		p.pb(tmp[a]);q.pb(tmp[b]);
	}
	rep(i,m)rep(j,m)ne[p[j]]=ne[q[j]]=min(ne[p[j]],ne[q[j]]);
	int sum=0;
	rep(i,n)sum+=ne[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1836
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define debug printf("\n-------------\n")
using namespace std;
typedef long long ll;
const int INF1=(~0u>>2);
const ll INF2=(~0ull>>2),P1=10007,P2=998244353,P3=1000000007;
int n,p[200010],mi,sum=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	mi=n+1;
	for(int i=1;i<=n;i++)
		if(p[i]<mi)
		{
			mi=p[i];
			sum++;
		}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int n;
	char str[5];
	scanf("%d", &n);
	
	int ctr0 = 0;
	int ctr1 = 0;
	int ctr2 = 0;
	int ctr3 = 0;
	
	for(int i = 0; i<n; i++){
		scanf("%s", str);
		if(str[0] == 'A' && str[1] == 'C'){
			ctr0++;
		}
		else if(str[0] == 'W' && str[1] == 'A'){
			ctr1++;
		}
		else if(str[0] == 'T' && str[1] == 'L' && str[2] == 'E'){
			ctr2++;
		}
		else{
			ctr3++;
		}
	}
	
	printf("AC x %d\n", ctr0);
	printf("WA x %d\n", ctr1);
	printf("TLE x %d\n", ctr2);
	printf("RE x %d\n", ctr3);
	
	return 0;
}

Measured memory_bytes: 1708
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) cin >> P[i];
    vector<bool> OX(N, true);
    for(int i = 0; i < N; i++) if(P[i] == i + 1) OX[i] = false;
    int swap = 0;
    for(int i = 0; i < N - 1; i++){
        if(!OX[i] and !OX[i + 1]){
            swap++;
            OX[i] = true;
            OX[i + 1] = true;
        }
    }
    for(int i = 0; i < N; i++){
        if(!OX[i]) swap++;
    }
    cout << swap << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int a, b;
    cin >> a >> b;
    a += b;
    if (a == 3)
        cout << 3;
    else if (a == 4)
        cout << 2;
    else
        cout << 1;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#include<string.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX_LIMIT 10000000
#define haha(x) x.begin(),x.end()
#define remove_zero(str) str.erase(0, str.find_first_not_of('0'));
#define br break
#define pb emplace_back
using kk = long double;
#define endl "\n"
using namespace std;
ll findLCM(ll a, ll b)
{
    ll lar = max(a, b);
    ll small = min(a, b);
    for (ll i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}
vector<ll>v;
void subsetSums(ll arr[], ll n)
{
    // There are totoal 2^n subsets
    ll total = 1<<n;

    // Consider all numbers from 0 to 2^n - 1
    for (ll i=0; i<total; i++)
    {
        ll sum = 0;

        // Consider binary reprsentation of
        // current i to decide which elements
        // to pick.
        for (ll j=0; j<n; j++)
            if (i & (1<<j))
                sum += arr[j];

        // Print sum of picked elements.
        //cout << sum << " ";
        v.pb(sum);
    }
}
int main()
{
    fio;
    ll T=1;
    //cin>>T;
    while(T--){
       ll n;
       cin>>n;
       vector<string>v(n);
       vector<ll>vec(n);
       ll i;
       for(i=0;i<n;i++){
         cin>>v[i]>>vec[i];
       }
       string x;
       cin>>x;
       ll pos=0;
       ll sum=0;
       for(i=0;i<n;i++){
         if(v[i]==x){
           pos=i;
         }
       }
       for(i=pos+1;i<n;i++){
          sum+=vec[i];
       }
       cout<<sum<<endl;
    }
}


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

int main() {
  string n; cin >> n;
  string ans = "No";
  rep(i,3) if (n[i] == '7') ans = "Yes";
  cout << ans << endl;		
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

vector<ll> dp(2001,0);

void pre(){
    dp[3] = 1;
    for(int i=4; i<2001; i++){
        for(int j=0; j<=i-3; j++){
            dp[i] += dp[j];
        }
        dp[i]++;
        dp[i] %= MOD;
    }
}

int main(){
    pre();
    int s;  cin >> s;
    print(dp[s]);
}

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


def solve(S: str):
    if 'RRR' in S:
        return 3
    elif 'RR' in S:
        return 2
    elif 'R' in S:
        return 1
    else:
        return 0


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 9008
def resolve():
    q = int(input())
    def is_prime(n):
        if n == 1:
            return False
        for i in range(2, int(n ** 0.5) + 1):
            if n % i == 0:
                return False
        return True
    prime = []
    prime2 = []
    for i in range(1, 10**5):
        if is_prime(i):
            prime.append(i)
    primes = set(prime)
    for i in range(0, len(prime)):
        if (((prime[i])+1)//2) in primes:
            prime2.append(prime[i])
    prime2s = set(prime2)
    ans = [0]*(10**5+1)
    count = 0
    for i in range(0, 10**5+1):
        if i in prime2s:
            count += 1
        ans[i] = count
    for i in range(q):
        l, r = map(int, input().split())
        print(ans[r+1]-ans[l-1])
resolve()

Measured memory_bytes: 54364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 10;
const int mod = 1e9+7;
const int INF=0x3f3f3f3f;

ll vis[3010][3010];
ll dp[3010][3010][4];
void solve() {
    int r,c,t;
    cin>>r>>c>>t;
    for(int i=0;i<t;i++){
        int a,b,c;
        cin>>a>>b>>c;
        vis[a][b]=c;
    }
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++) {
            if (vis[i][j] != 0) {
                for (int k = 1; k < 4; k++) {
                    dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][3] + vis[i][j]);
                    dp[i][j][k] = max(dp[i][j][k], max(dp[i][j - 1][k - 1] + vis[i][j],dp[i][j - 1][k]));
                }
            }else{
                for(int k=0;k<4;k++) {
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]);
                    dp[i][j][k] = max(dp[i][j][k], dp[i-1][j][k]);
                }
            }
        }
    }
    ll res=0;
    for(int i=0;i<4;i++){
        res=max(res,dp[r][c][i]);
    }
    cout<<res;
}

int main() {
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 356332
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    a*=3;
    a=a+b;
    a/=2;
    cout << a << endl; 
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<int>;


ll dp[2][2002][2002];
ll MOD = 1000000007;


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

	vec S(N+1);
	vec T(M+1);

	for (int i = 0; i < N; ++i)
	{
		cin >> S[i];
	}
	for (int i = 0; i < M; ++i)
	{
		cin >> T[i];
	}

	dp[0][0][0] = 1;

	for (int i = 0; i < N+1; ++i)for (int j = 0; j < M+1; ++j)
	{
		dp[0][i + 1][j] = (dp[0][i][j] + dp[0][i + 1][j]) % MOD;
		dp[1][i][j] = (dp[0][i][j] + dp[1][i][j]) % MOD;
		dp[1][i][j + 1] = (dp[1][i][j] + dp[1][i][j + 1]) % MOD;
		if (S[i] == T[j])
		{
			dp[0][i+1][j+1] = (dp[0][i+1][j+1]+dp[1][i][j]) % MOD;
		}
	}

	cout << dp[1][N][M] << endl;

	return 0;
}

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

int main()
{
    int N;
    std::cin >> N;
    std::string S, T;
    std::cin >> S >> T;
    for (int i=0; i<N; ++i) {
        std::cout << S[i] << T[i];
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=a[i]*-1
import heapq
heapq.heapify(a)
for i in range(m):
  t=(heapq.heappop(a))*-1
  heapq.heappush(a,(t//2)*-1)
print(sum(a)*-1)

Measured memory_bytes: 20012
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int X[19][19];

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

	int N, D; cin >> N >> D;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) cin >> X[i][j];
	}

	int ans = 0;

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int dis2 = 0;
			for (int k = 0; k < D; k++) dis2 += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);

			for (int l = 0; l*l <= dis2; l++) {
				if (l*l == dis2) ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <numeric>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)

int main()
{
	std::multimap<int,int> cake;
	int K, T;
	std::cin >> K >> T;
	for (size_t i = 0; i < T; ++i)
	{
		int a;
		std::cin >> a;
		cake.insert({ a, i });
	}

	int last_cake = -1;
	while (1 < cake.size())
	{
		auto iter = --cake.end();
		if (iter->second == last_cake) {
			--iter;
		}
		last_cake = iter->second;
		auto new_num = iter->first - 1;
		cake.erase(iter);
		if (0 < new_num) {
			cake.insert({ new_num, last_cake });
		}
	}
	std::cout << cake.begin()->first - 1 << std::endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int n,k,c;cin>>n>>k>>c;
    string s;cin>>s;
     int a[200000]; int b[200000];
    for(int i=0,cur=0;i<n;i++){
        if(s[i]=='o'){
            a[cur++]=i;
            i+=c;
        }
    }
    for(int i=n-1,cur=k-1;i>=0;i--){
        if(s[i]=='o'){
            b[cur--]=i;
            i-=c;
        }
    }
    for(int i=0;i<k;i++){
        if(a[i]==b[i])cout<<a[i]+1<<endl;
    }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b) {
        cout << c << endl;
    }
    else if (b == c) {
        cout << a << endl;
    }
    else {
        cout << b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 2e5 + 20;
int n, h, w;
vector<long long> a[MAXN];

int root[MAXN], size[MAXN], marked[MAXN] = {};
void init() {
    for(int i = 0; i < MAXN; i++) {
        root[i] = i;
        size[i] = 1;
    }
}
int find(int i) {
    if(root[i] != i)
        return root[i] = find(root[i]);
    else
        return i;
}
int same(int i, int j) {
    return find(i) == find(j);
}
void join(int i, int j) {
    if(same(i, j))
        return;
    int ri = find(i);
    int rj = find(j);
    if(marked[ri] || marked[rj])
    	marked[ri] = marked[rj] = 1;
    if(size[ri] >= size[rj]) {
        root[rj] = ri;
        size[ri] += size[rj];
    }
    else {
        root[ri] = rj;
        size[rj] += size[ri];
    }
}

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

    cin >> n >> h >> w;
    for(int i = 0; i < n; i++) {
    	a[i].resize(3);
    	cin >> a[i][1] >> a[i][2] >> a[i][0];
    }

    sort(a, a + n, [](const vector<long long> & x, const vector<long long> & y) {
    	return x[0] > y[0];
    });

    init();

    long long res = 0;
    for(int i = 0; i < n; i++) {
    	int x = a[i][1];
    	int y = a[i][2] + max({n, h, w});
    	int w = a[i][0];
    	//cout << x << ' ' << y << ' ' << same(x, y) << endl;
    	if(!same(x, y)) {
    		if(!marked[find(x)] || !marked[find(y)]) {
	    		res += w;
	    		join(x, y);
    		}
    	}
    	else if(!marked[find(x)]) {
    		marked[find(x)] = 1;
    		res += w;
    	}
    }
    cout << res << endl;

    return 0;
}











Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.1415926535

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int pa(vector<pair<char, int>> &a, int p, int r) {
    int x = a[r].second;
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (a[j].second <= x) {
            i++;
            swap(a[j], a[i]);
        }
    }
    swap(a[i + 1], a[r]);
    return i + 1;
}

void quick_sort(vector<pair<char, int>> &a, int p, int r){
    if (p < r) {
        int q = pa(a, p, r);
        quick_sort(a, p, q - 1);
        quick_sort(a, q + 1, r);
    }
}

void merge(vector<pair<char, int>> &a, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    pair<char, int> l[n1 + 1];
    pair<char, int> r[n2 + 1];
    rep(i, n1) l[i] = a[left + i];
    rep(i, n2) r[i] = a[i + mid];
    l[n1] = make_pair('s', SENTINEL);
    r[n2] = make_pair('s', SENTINEL);
    int i = 0, j = 0;
    for (int k = left; k < right; k++){
        if (l[i].second <= r[j].second){
            a[k] = l[i];
            i++;
        }
        else{
            a[k] = r[j];
            j++;
        }
    }
}

void merge_sort(vector<pair<char, int>> &a, int left, int right){
    if (left + 1 < right){
        int mid = (left + right) / 2;
        merge_sort(a, left, mid);
        merge_sort(a, mid, right);
        merge(a, left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    char c;
    int i;
    vector<pair<char, int>> v(n);
    vector<pair<char, int>> w(n);
    rep(j, n) {
        cin >> c >> i;
        v[j] = make_pair(c, i);
        w[j] = make_pair(c, i);
    }
    quick_sort(v, 0, n - 1);
    merge_sort(w, 0, n);
    if (v == w)
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
    rep(i, n) {
        cout << v[i].first << ' ' << v[i].second << endl;
    }
}


Measured memory_bytes: 5096
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w, _) = (v[0], v[1], v[2]);

    let mut poses = vec![vec![]; h];
    for i in 0..h {
        let line = read::<String>().chars().collect::<Vec<_>>();
        for j in 0..w {
            if line[j] == '#' {
                poses[i].push(j);
            }
        }
    }

    let mut grouped = vec![vec![0; w]; h];
    let mut next_group = 1;

    for i in 0..h {
        if i != 0 && poses[i].is_empty() {
            for j in 0..w {
                grouped[i][j] = grouped[i - 1][j];
            }
        } else {
            let mut pointer = 0;
            for (k, &pos) in poses[i].iter().enumerate() {
                while pointer <= pos {
                    grouped[i][pointer] = next_group;
                    pointer += 1;
                }
                if k == poses[i].len() - 1 {
                    while pointer <= w - 1 {
                        grouped[i][pointer] = next_group;
                        pointer += 1;
                    }
                }
                next_group += 1;
            }
        }
    }

    let mut first_found = std::usize::MAX;
    for i in 0..h {
        if !poses[i].is_empty() {
            first_found = i;
            break;
        }
    }
    for i in (0..first_found).rev() {
        for j in 0..w {
            grouped[i][j] = grouped[i + 1][j];
        }
    }

    for line in grouped {
        print_array(&line);
    }
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#define LEN 255

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

    std::string ans = "";
    int num;
    for (int i = 0; i < S.size(); i++)
    {
        num = (S[i] - 'A' + N) % 26;
        ans += ('A' + num);
    }
    std::cout << ans << std::endl;

    // char string[LEN];
    // char angou[LEN];
    // int key, number, i;

    // scanf("%d", &key);
    // scanf("%s", string);

    // i = 0;
    // while (string[i] != '\0')
    // {
    //     number = (string[i] - 'A' + key) % 26;
    //     angou[i] = 'A' + number;
    //     ++i;
    // }
    // angou[i] = '\0';

    // printf("%s\n", angou);

    return 0;
}

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

int main() {
  int N,li,ri;
  int s,sum;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> li >> ri;
    s = (ri - li) + 1;
    sum += s;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(1000000)

n,q = map(int, input().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n-1)]
p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

v = [deque([]) for i in range(n)]
for e in a_b:
    v[e[0]-1]+=[e[1]-1]
    v[e[1]-1]+=[e[0]-1]
score = [0 for i in range(n)]
for e in p_x:
    score[e[0]-1]+=e[1]
def dfs(p, bp=-1):
    while v[p]:
        c =v[p].popleft()
        if c ==bp:
            continue
        #print(p, c, bp)
        score[c]+=score[p]
        dfs(c, bp=p)
visited = [0]                
dfs(0)
print(*score)

Measured memory_bytes: 448680
#include<stdio.h>

int main(){
    int S = 0;
    int h = 0, m = 0, s = 0;
    
    scanf("%d", &S);
    
    printf("%d:%d:%d\n", S/3600, S%3600/60, S%3600%60);
    
    return 0;
}


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

const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    if (N < M) swap(N, M);

    if (N - M >= 2) {
        cout << 0 << endl;
        return 0;
    }

    long long res = 1;
    if (N == M) {
        for (int i = 1; i <= N; i++) {
            res *= i; res %= MOD;
        }
        res *= res; res %= MOD;
        res *= 2; res %= MOD;
    } else {
        for (int i = 1; i <= M; i++) {
            res *= i; res %= MOD;
        }
        res *= res; res %= MOD;
        res *= N; res %= MOD;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstdio>
#include<math.h>

using namespace std;
int main(){
  int a,b,i,j,c=1;
  string s;
  cin>>a>>b>>s;
  for(i=0;i<a;i++){
    if(s[i]<'0'|| s[i]>'9'){
      c=0;
      break;
    }
  }
  if(s[i]!='-')c=0;
  for(j=i+1;j<a+b+1;j++){
    if(s[j]<'0'|| s[j]>'9'){
      c=0;
      break;
    }
  }
  if(c==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

  int q;
  std::cin >> q;

  std::vector<int> t(q);
  std::vector<int> f(q);
  std::vector<char> c(q);

  for (int i = 0; i < q; ++i) {
    std::cin >> t[i];
    if (t[i] == 2) {
      std::cin >> f[i] >> c[i];
    }
  }

  bool is_reversed = false;
  std::string sfront;

  for (int i = 0; i < q; ++i) {
    if (t[i] == 1) {
      is_reversed = !is_reversed;
    } else {
      if (is_reversed) {
        if (f[i] == 1) {
          s.push_back(c[i]);
        } else {
          sfront.push_back(c[i]);
        }
      } else {
        if (f[i] == 1) {
          sfront.push_back(c[i]);
        } else {
          s.push_back(c[i]);
        }
      }
    }
  }

  std::string ans;

  if (is_reversed) {
    std::reverse(s.begin(), s.end());
    ans = s + sfront;
  } else {
    std::reverse(sfront.begin(), sfront.end());
    ans = sfront + s;
  }

  std::cout << ans << std::endl;
}

Measured memory_bytes: 3040
use std::io::{BufRead, Read};

pub struct Scanner<R>
where
    R: BufRead,
{
    reader: R,
}

impl<R> Scanner<R>
where
    R: BufRead,
{
    pub fn new(reader: R) -> Self {
        Self { reader }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: ::std::str::FromStr,
        <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
    {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .unwrap()
    }
}

use std::iter::*;

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut sc = Scanner::new(stdin);

    let a: f64 = sc.next();
    let b: f64 = sc.next();
    let c: f64 = sc.next::<f64>() / 180. * std::f64::consts::PI;

    let area: f64 = c.sin() * a * b / 2.0;
    let circumference = (a.powi(2) + b.powi(2) - 2.0 *a*b * c.cos()).sqrt() + a + b;
    let h: f64 = c.sin() * b;

    println!("{}", area);
    println!("{}", circumference);
    println!("{}", h);
}



Measured memory_bytes: 5192
#include <iostream>
#include <math.h>
using namespace std;


int main() {
    int A, B;
    cin >> A >> B ;
    if((A >= 1) && (A <= 8) && (B >= 1) && (B <= 8)){
    	cout << "Yay!" << endl;
    }else{
    	cout << ":(" << endl;
    }
}



Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
prev = sum(A[0:K])
for i in range(K+1,N+1):
  curr = prev - A[i-K-1] + A[i-1]
  if prev < curr:
    print("Yes")
  else:
    print("No")
  prev = curr

Measured memory_bytes: 31608
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=b-1;i<=a;i--)
 
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
 
#define mod 1000000007
vi v(100000,-1);
int result(vi &ve,int indx,int size)
{
    if(v[indx]!=-1)
    return v[indx];
    if(indx==size-1)
    return 0;
    if(indx>size-1)
    return INT_MAX;
    return v[indx]=min(result(ve,indx+1,size)+abs(ve[indx]-ve[indx+1]),indx+2<=size?result(ve,indx+2,size)+abs(ve[indx]-ve[indx+2]):INT_MAX);
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int a;
	cin>>a;
	vi vec(a+1);
	for(int i=0;i<a;i++)
	cin>>vec[i];
	int b=vec[a-2];
	vec[a]=b;
	int res=result(vec,0,a);
	cout<<res<<"\n";
	v.clear();
	return 0;
}

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

using namespace std;

// define
#define ALL(x) x.begin(), x.end()

// functions
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b);}

// =============== main =============== //
int main()
{
  vector<int> v(3); cin >> v[0] >> v[1] >> v[2];
  sort(ALL(v));
  if (v[0]==5 && v[1]==5 && v[2]==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#import<cstdio>
#import<map>
#define I(M,A)for(i=0;i<M;i++)scanf("%d",&x),A[i+1]=A[i]+x;
main(){for(int n[1501],m[1501],o,a,b,i,j,x;scanf("%d%d",&a,&b),a;printf("%d\n",o)){std::map<int,int>z;*n=*m=o=0;I(a,n)I(b,m)for(i=0;i<=a;i++)for(j=0;j<=b;j++)z[n[i]+m[j]]++;for(std::map<int,int>::iterator p=z.begin();p!=z.end();p++)o+=p->second*((p->second)-1)/2;}}

Measured memory_bytes: 18000
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define read(a) scanf("%d", &a)
#define readf(a) scanf("%lf", &a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7;
const int N = 3e5 + 7;
const int M = 1e6 + 7;
int fa[N];

int get(int x) {return fa[x] = fa[x] == x ? x : get(fa[x]);}
signed main()
{
    Buff;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) fa[i] = i;
    while(m--)
    {
        int u, v;
        cin >> u >> v;
        u = get(u); v = get(v);
        fa[u] = v;
    }

    int cnt = 0;
    for(int i = 1; i <= n; i++)
        if(i == get(i)) cnt++;

    cout << cnt - 1 << "\n";
    return 0;
}
/**
**/



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
string s[10001], t;

int main() {
	cin >> n;
	inc(i, n + 1) {
		cin >> s[i];
		if(i == n) { t = s[i]; }
	}
	
	sort(s, s + n + 1);
	
	bool flag = true;
	int f, l;
	inc(i, n + 1) {
		if(s[i] == t) {
			if(flag) { f = i; flag = false; }
			l = i;
		}
		
	}
	
	int ff = f;
	inc(i, ff) {
		inc(j, s[i].size()) {
			if(s[i][j] == '?') { s[i][j] = 'z'; }
		}
		if(t <= s[i]) { f--; }
	}
	
	incII(i, f, l) {
		cout << (i == f ? "" : " ") << i + 1;
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 896
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");

		//コード
		//    	Scanner sc = new Scanner(file);
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] L = new int[N];
		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}
		int ans = 0;
		if(N<=2) {
			System.out.println(ans);
		} else {
			for (int i = 0; i < N - 2; i++) {
				for (int j = i + 1; j < N - 1; j++) {
					for (int k = j + 1; k < N; k++) {
						if(L[i]<(L[j]+L[k])&&L[j]<(L[k]+L[i])&&L[k]<(L[i]+L[j])&&(L[i]!=L[j]&&(L[j]!=L[k])&&(L[k]!=L[i]))) {
							ans++;
						}
					}
				}
			}
			System.out.println(ans);
		}

	}
}


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

ll N, K, X;
ll A[100010];
ll Anbit[70] = { 0 };
int upb;  //Kのbit数  bit上限
ll res = 0;  //計算結果

/*Kの2進数表記時のbit数*/
int upper_bit(ll K){
  if(K == 0) return 0;
  return upper_bit(K/2) + 1;
}

/*binary bit count   第iビットが立っているか*/
void bbc(ll a){
  for(int i = 1; i <= upb; i++){ if( (a >> (i-1)) & 1) Anbit[i] += 1; }
  return ;
}

/*最も値の大きくなるXを計算*/
ll calc_X(void){
  ll x[70] = {0}; ll mul = 1, xx = 0;  mul = (mul << (upb-1));

  for(int i = upb; i >= 1; i--){
    if(Anbit[i] >= (N+1)/2){ mul /= 2; continue; }
    if(mul + xx <= K) xx += mul; 
      mul /= 2;
  }
  return xx;
}


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

  upb = upper_bit(K);  //Kのbit数を計算
  for(int i = 0; i < N; i++){ cin >> A[i]; bbc(A[i]); }
  X = calc_X();

  for(int i = 0; i < N; i++) res += (X ^ A[i]);
  cout <<res << endl;
  return 0;
}

Measured memory_bytes: 1024