akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

int main() {
    long a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
   
typedef struct node{
    int p;
    int left;
    int right;
} Node;

Node *node;

int searchHight(int index){
    int hleft = 0;
    int hright = 0;
   
    if (node[index].left != -1){
        hleft = searchHight(node[index].left) +1;
    }
    if (node[index].right != -1){
        hright = searchHight(node[index].right) +1;
    }
    if (hleft < hright) return hright;
    else return hleft;
}
   
int main(){
       
    int n,i,id,depth,tmp,deg,nownode,sibling;
   
    scanf("%d",&n);
   
    node = malloc(sizeof(Node)*n);
   
    for (i = 0; i < n; i++){
        node[i].p = -1;
    }
   
    for (i = 0; i < n; i++){
        scanf("%d",&id);
        scanf("%d%d",&node[id].left,&node[id].right);
        node[node[id].left].p = id;
        node[node[id].right].p = id;
    }
   
    nownode = 0;
    while(1){
        if(node[nownode].left != -1 && node[nownode].right != -1) break;
         else if(node[nownode].left == -1) nownode = node[nownode].right;
         else nownode = node[nownode].left;       
    }
   
    for (i = 0; i < n; i++){           
        tmp = node[i].p;
        if(tmp == -1) sibling = -1;
        else if(node[tmp].left == i) sibling = node[tmp].right;
        else sibling = node[tmp].left; 
        depth = 0;
        while(tmp != -1){
            tmp = node[tmp].p;
            depth++;
        }    
        deg = 0;
        if (node[i].left != -1) deg++;
        if (node[i].right != -1) deg++;   
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,node[i].p,sibling,deg,depth,searchHight(i));   
        if(node[i].p == -1) printf("root\n");
        else if(node[i].left == -1 && node[i].right == -1) printf("leaf\n");
        else printf("internal node\n");
    }
    return 0;
}

Measured memory_bytes: 612
/*
    A - Circle
    https://atcoder.jp/contests/abc145/tasks/abc145_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    int r;
    cin >> r;

    cout << (r * r) << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

		int N = sc.nextInt();
		int sum = 0;
		int [] array = new int [N];
		for (int i=0;i<N;i++){
			array[i]=sc.nextInt();
			sum+=array[i];
		}
		int M = sc.nextInt();
		for(int i=0;i<M;i++){
			int p = sc.nextInt();
			int x = sc.nextInt();
			System.out.println(sum-array[p-1]+x);
		}
		
		// 文字列の入力
		
	}
	
}

Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    ll N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll cnt = 0;
    for(int i = 0;i < N;i++) {
        cnt += vec.at(i);
    }
    ll cnt2 = (1 + N) * N / 2;
    if(cnt % cnt2 != 0) {
        cout << "NO" << endl;
    }
    else {
        vec.push_back(vec.at(0));
        cnt /= cnt2;
        ll cnt3 = 0;
        bool ret = true;
        for(int i = 0;i < N;i++) {
            if(((vec.at(i + 1) - vec.at(i)) - cnt) % N != 0 || vec.at(i + 1) - vec.at(i) - cnt > 0) {
                ret = false;
            }
            else {
                cnt3 += ((vec.at(i + 1) - vec.at(i)) - cnt) / -N;
            }
        }
        if(ret == false) {
            cout << "NO" << endl;
        }
        else {
            if(cnt3 == cnt) {
                cout << "YES" << endl;
            }
            else {
                cout << "NO" << endl;
            }
        }
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N,M;
  cin>>N>>M;
 
  
  if(abs(N-M)!=1&&abs(N-M)!=0){
    cout<<0<<endl;
  }
  
  else if(abs(N-M)==1){
    
    ll n=1;
    ll num=N;
    while(n!=num){
    
      N=N*n%mod;
      n++;
    
    }
         ll m=1;
    num=M;
    while(m!=num){
     
      M=M*m%mod;
      m++;
      
    }
        
  cout<<M*N%mod<<endl;
   
    }
      else{
        ll num=N;
            ll n=1;
    while(n!=num){
      
      N=N*n%mod;
      n++;
    }
       
  
     cout<<2*N*N%mod<<endl;   
      }
}
        
        


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

int main(){
    int N;
    long long ans=0;
    cin>>N;
    vector<long long>A(N+1),B(N);
    for(int i=0;i<N+1;i++){
        cin>>A.at(i);
    }
    for(int i=0;i<N;i++){
        cin>>B.at(i);
    }
    
    for(int i=0;i<N;i++){
        
        if(B.at(i)<=A.at(i)){
            ans += B.at(i);
            A.at(i) -= B.at(i);
        }else if(A.at(i)<B.at(i)&&B.at(i)<A.at(i)+A.at(i+1)){
            ans += B.at(i);
            A.at(i+1) = A.at(i+1)-(B.at(i)-A.at(i));
            A.at(i) = 0;
        }else if(A.at(i)+A.at(i+1)<=B.at(i)){
            ans +=A.at(i)+A.at(i+1);
            A.at(i) = 0;
            A.at(i+1) = 0;
        }
        
    }
    
    cout<<ans<<endl;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<vector<int>> d(n,vector<int>(2));
    REP(i,n){
        cin >> d[i][0] >> d[i][1];
    }
    REP(i,n-2){
        if(d[i][0]==d[i][1]&&d[i+1][0]==d[i+1][1]&&d[i+2][0]==d[i+2][1]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3660
import numpy as np

A, B, H, M = map(int, input().split())


angle_h = 1./ 12.*(H + M/60.) * 2*np.pi

angle_m = M/60. * 2 * np.pi

hour = (A*np.sin(angle_h), A*np.cos(angle_h))
minute = (B*np.sin(angle_m), B*np.cos(angle_m))

dist = np.sqrt((hour[0] - minute[0])**2 + (hour[1] - minute[1])**2)

print(dist)


Measured memory_bytes: 27284
using System;
class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine(); //標準入力
        

        int N = int.Parse(a);
        
        if(N == 1)
        {
            Console.WriteLine("{0}", 0);
            return;
        }
        
        decimal an = 0;
        decimal bn = 8;
        decimal cn = 1;
        decimal dn = 1;
        
        for (int i = 1;i< N; i++)
        {
            decimal an1 = an * 10 + cn + dn;
            decimal bn1 = bn * 8;
           decimal  cn1 = cn * 9 + bn;
            decimal dn1 = dn * 9 + bn;

            an = an1;
            bn = bn1;
            cn = cn1;
            dn = dn1;

            an = an % (decimal)(Math.Pow(10, 9) + 7);
           bn = bn % (decimal)(Math.Pow(10, 9) + 7);
           cn = cn % (decimal)(Math.Pow(10, 9) + 7);
           dn = dn % (decimal)(Math.Pow(10, 9) + 7);

        }
        Console.WriteLine("{0}", an);
    }

}
//2,2
//1,0
//869121,2511445

Measured memory_bytes: 27884
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sum(b)

for i in range(len(a)-2,-1,-1):
    b[i] = max(b[i]-a[i+1],0)
    if b[i] < a[i]:
        a[i] = a[i]-b[i]
        b[i] = 0
    else:
        b[i] = b[i]-a[i]
        a[i] = 0
    
print(c-sum(b))

Measured memory_bytes: 18624
N=int(input())
A=list(map(int,input().split()))
flag=1
for i in range(N):
    if A[i]%2==0:
        if not((A[i]%3==0)or(A[i]%5==0)):
            flag=0

if flag==1:
    print("APPROVED")
else:
    print("DENIED")

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

int main() {
  int n, m, c;

  int b[20];
  int a[20][20];

  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &c);

  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }

  int p;
  int tmp_a;
  int ans = 0;

  for (int i = 0; i < n; i++) {
    p = c;
    for (int j = 0; j < m; j++) {
      scanf("%d", &tmp_a);
      p += tmp_a * b[j];
    }
    if (p > 0) {
      ans++;
    }
  }

  printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 10000000000000;

int main() {
  char s[4];
  rep(i,0,4){
    cin>>s[i];
  }
  sort(s,s+4);
  if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#2522
l = []
word = input()
for i in word:
    l.append(i)

a = 0
b = 0
c = 0
d = 0

if len(l) >= 6:
    a += 1
for i in l:
    if 48 <= ord(i) <= 57:
        b += 1
    elif 97 <= ord(i) <= 122:
        c += 1
    elif 65 <= ord(i) <= 90:
        d += 1
    else:
        c += 0
        
if a >= 1 and b >= 1 and c >= 1 and d >= 1:
    print('VALID')
else:
    print('INVALID')


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
int mod_pow(int x,int n,int mod){
    int res=1;
    while(n>0){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
signed main(void){
    int n;cin>>n;
    vector<vector<int>>V(10,vector<int>(10,0));
    for(int i=1;i<=n;i++){
        int m=i;
        int last=m%10;
        while(m>=10)m/=10;
        int first=m;
        V[first][last]++;
    }
    int ans=0;
    rep(i,10)rep(j,10){
        int count0=V[i][j];
        int count1=V[j][i];
        ans+=count0*count1;
    }
    cout<<ans<<endl;
}
        


Measured memory_bytes: 256
import sys
# input処理を高速化する
input = sys.stdin.readline
# 入力
N, W = map(int, input().split())
array = [list(map(int, input().split())) for _ in range(N)]  # [重さ、価値]
# sum_vの取りうる上限値
# MAX_V = (10**3 + 1) * N
MAX_V = 0
for line in array:
    MAX_V += line[1]
MAX_V += 1
# 最小値を求めるので無限大の値
f_inf = float('inf')


def chmin(a, b):
    if a <= b:
        return a
    else:
        return b


def knapsack(n, w):
    # dpの初期化　dp[i][sum_v]は重さの総和の最小値
    dp = [[f_inf] * MAX_V for j in range(N + 1)]
    # 初期条件
    dp[0][0] = 0
    # forは全て関数の中で回す。
    # 入力
    for i in range(N):
        # w, v = map(int, input().split())
        for sum_v in range(MAX_V):
            # i番目の品物を選ぶ場合
            if sum_v - array[i][1] >= 0:
                dp[i + 1][sum_v] = chmin(dp[i + 1][sum_v],
                                         dp[i][sum_v - array[i][1]] + array[i][0])
            # i番目の品物を選ばない場合
            dp[i + 1][sum_v] = chmin(dp[i + 1][sum_v], dp[i][sum_v])
    # dp[N][sum_v]の値が、W以下であるsum_vの値の最大値
    ans = 0
    for sum_v in range(MAX_V):
        if dp[N][sum_v] <= W:
            ans = sum_v
    print(ans)


knapsack(N, W)


Measured memory_bytes: 326784
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
    int n;
    cin >> n;
    map<ll, ll, greater<ll>> cnt;
    vector<ll> arr(n);
    for(ll &x : arr)
        cin >> x, cnt[x]++;
    sort(allr(arr));

    ll sum = 0;
    queue<pi> q;
    q.push({arr[0], arr[0]});

    for(int i = 1; i < n; i++)
    {
        pi u = q.front();
        q.pop();
        sum += min(u.ff, u.ss);
        q.push({u.ff, arr[i]});
        q.push({arr[i], u.ss});
    }
    cout << sum;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 19032
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	int b=0;
	int tmp=a;
	while(tmp){
		b+=tmp%10;
		tmp/=10;
	}
	if(a%b==0){
		printf("Yes\n");
	}else printf("No\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N;
  cin >> N;
  vector<int> v(N + 1);
  rep(i, 1, N + 1) { cin >> v[i]; }
  rep(i, 1, N + 1) v[i] += v[i - 1];

  auto valid = [&](int s, int m, int t) { return abs(v[m] * 2 - v[s] - v[t]); };
  int ans = INF;

  dump(v);

  rep(i, 2, N - 1) {
    // (0,i),(i,N+1)
    int l = 1, r = i;
    while (r - l > 1) {
      int m = (l + r) / 2;
      int x = valid(0, m, i);
      int y = valid(0, m - 1, i);
      int z = valid(0, m + 1, i);

      if (y <= x) {
        r = m;
      } else {
        l = m;
      }
    }

    vector<int> a;
    a.push_back(v[l]);
    a.push_back(v[i] - v[l]);

    l = i + 1, r = N;
    while (r - l > 1) {
      int m = (l + r) / 2;
      int x = valid(i, m, N);
      int y = valid(i, m - 1, N);

      if (y <= x) {
        r = m;
      } else {
        l = m;
      }
    }
    a.push_back(v[l] - v[i]);
    a.push_back(v[N] - v[l]);
    sort(all(a));
    chmin(ans, a[3] - a[0]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

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

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

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int X, A; cin >> X >> A;
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;
}   


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
template <typename T, const T TINF>
struct WarshallFloyd {
  vector<vector<T> > dist;

  WarshallFloyd(int sz_) : sz(sz_) {}

  void build(const vector<vector<T> > &graph) {
    dist = graph;
    internal.assign(sz, vector<int>(sz, -1));
    REP(k, sz) REP(i, sz) REP(j, sz) {
      if (dist[i][k] != TINF && dist[k][j] != TINF && dist[i][j] > dist[i][k] + dist[k][j]) {
        dist[i][j] = dist[i][k] + dist[k][j];
        internal[i][j] = k;
      }
    }
  }

  void add(vector<tuple<int, int, T> > edges) {
    set<int> ver;
    for (tuple<int, int, T> e : edges) {
      int s = get<0>(e), t = get<1>(e);
      T cost = get<2>(e);
      if (dist[s][t] >= cost) {
        dist[s][t] = cost;
        internal[s][t] = -1;
      }
      ver.insert(s);
      ver.insert(t);
    }
    for (int v : ver) {
      REP(i, sz) REP(j, sz) {
        if (dist[i][v] != TINF && dist[v][j] != TINF && dist[i][j] > dist[i][v] + dist[v][j]) {
          dist[i][j] = dist[i][v] + dist[v][j];
          internal[i][j] = v;
        }
      }
    }
  }

  bool has_negative_cycle() {
    REP(i, sz) if (dist[i][i] < 0) return true;
    return false;
  }

  vector<int> build_path(int s, int t) {
    vector<int> res;
    if (dist[s][t] != TINF) {
      build_path(s, t, res);
      res.emplace_back(t);
    }
    return res;
  }

private:
  int sz;
  vector<vector<int> > internal;

  void build_path(int s, int t, vector<int> &path) {
    int k = internal[s][t];
    if (k == -1) path.emplace_back(s);
    else {
      build_path(s, k, path);
      build_path(k, t, path);
    }
  }
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m, r; cin >> n >> m >> r;
  WarshallFloyd<long long, LINF> wf(n);
  vector<int> town(r);
  REP(i, r) {
    cin >> town[i];
    --town[i];
  }
  vector<vector<long long> > graph(n, vector<long long>(n, LINF));
  REP(i, n) graph[i][i] = 0;
  REP(i, m) {
    int a, b, c; cin >> a >> b >> c; --a; --b;
    graph[a][b] = c;
    graph[b][a] = c;
  }
  wf.build(graph);
  // REP(i, n) {
  //   REP(j, n) cout << wf.dist[i][j] << ' ';
  //   cout << '\n';
  // }
  vector<int> per(r); REP(i, r) per[i] = i;
  long long ans = LINF;
  do {
    long long tmp = 0;
    REP(i, r - 1) tmp += wf.dist[town[per[i]]][town[per[i + 1]]];
    ans = min(ans, tmp);
  } while (next_permutation(ALL(per)));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>

// Aliases
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
using ull = unsigned long long;

using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::string;
using std::vector;
using std::array;
template <class T>
using matrix = vector<vector<T>>;
template <class T>
constexpr T inf = std::numeric_limits<T>::max();
template <class T>
constexpr T neg_inf = -std::numeric_limits<T>::max();
template <class T>
constexpr T pi = static_cast<T>(3.141592653589793);

template <class T = i64>
vector<T> read_vector(const u64 n)
{
    vector<T> vec;
    vec.reserve(n);
    for (u64 i = 0; i < n; i++)
    {
        T v;
        cin >> v;
        vec.emplace_back(v);
    }

    return vec;
}

template <class T>
void print(const vector<T>& vec, const bool new_line = false)
{
    const u64 n = vec.size(); 
    if (new_line)
    {
        for (u64 i = 0; i < n; i++)
        {
            cout << vec[i];
            if (i != n - 1) { cout << '\n'; }
        }
    }
    else
    {
        for (u64 i = 0; i < n; i++)
        {
            cout << vec[i];
            if (i != n - 1) { cout << ' '; }
        }
    }

    cout << endl;
}

int main()
{
    u32 n;
    cin >> n;
    auto vec = read_vector<u32>(n);
    u32 sum = 0;
    for (u32 i = 0; i < n; i++)
    {
        for (u32 j = i + 1; j < n; j++)
        {
            sum += vec[i] * vec[j];
        }
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
  string s;

  cin >> s;

  for (int i = 0;i < s.size();i++) {
    if (s[i] == s[i+1]) {
      cout << "Bad";
      return 0;
    } 
    else {
      continue;
    }
  }
  cout << "Good";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
ll MOD=1e9+7;
int n;
ll dp[1000005][2][2];

int main(void){
	cin>>n;
	if(n==1){
		cout<<0;
		return 0;
	}
	dp[0][0][0]=8ll;
	dp[0][1][0]=1ll;
	dp[0][0][1]=1ll;
	dp[0][1][1]=0ll;
	FORN(i,1,n){
		dp[i][0][0]=(dp[i-1][0][0]*8ll)%MOD;
		dp[i][1][0]=(dp[i-1][0][0]+(dp[i-1][1][0]*9ll)%MOD)%MOD;
		dp[i][0][1]=(dp[i-1][0][0]+(dp[i-1][0][1]*9ll)%MOD)%MOD;
		dp[i][1][1]=((dp[i-1][0][1]+dp[i-1][1][0])%MOD+(dp[i-1][1][1]*10ll)%MOD)%MOD;
	}
	cout<<dp[n-1][1][1]%MOD;
	return 0;
}

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

int main(){
    int n, i, j, ans=1;
  char s[100010];
    cin >> n;
    cin >> s;
    //同色は最初の奴を0に変換
    for (i=1; i < n; i++) {
        if (s[i]==s[i-1]) {
            /*DO_NOTHING*/
        } else {
            ans++;
        }
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >> n >> m;
  int ans = 0;
  if(n == 1){
    cout << m << endl;
    return 0;
  }
  for(int k=1;k<=m/n;k++){
    if(m%k) continue;
    if(m/k >= n) ans = max(k,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
int a[50], b[50], c[50], d[50], n, m, q, z[10], ans = 0;
void mutu(int fn, int fm) {
	if (fn == 0) {
		int sum = 0;
		f(i, q) {
			if (z[b[i] - 1] - z[a[i] - 1] == c[i])sum += d[i];
		}
		ans = max(sum, ans);
		return;
	}
	for (int i = fm; i <= m; i++) {
		z[n - fn] = i;
		mutu(fn - 1, i);
	}
	return;
}
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	c = min(b - 1, c);
	cout << a * c / b - a * (c / b) << endl;
}


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

int n, a[401];
long long b[401], dp[401][401], mod = 1e9+7;

long long func(int l, int r){
	if(l == r) return dp[l][r] = 0;
	if(l+1 == r) return dp[l][r] = a[l];
	if(dp[l][r] != 0) return dp[l][r];
	long long res = 1e18;
	for(int i=l+1; i<r; ++i) res = min(res, func(l, i) + func(i, r) - b[l-1] + b[r-1]);
	return dp[l][r] = res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		cin >> a[i+1];
		b[i+1] = a[i+1];
		b[i+1] += b[i];
	}
	cout << func(1, n+1) - b[n] << "\n";
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e18+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 210000
#define offset 200
#define ptr nodo*


using namespace std;
const int mod=1e6+3;
string txt;
int v[tam],dp[tam];
int f(int num)
{
	if (num==0)
		return 0;
	if (dp[num]!=-1)
		return dp[num];
	return dp[num]=f(num%(__builtin_popcount(num)))+1;

}
int main()
{
	memset(dp,-1,sizeof dp);
	int n;
	cin>>n;
	cin>>txt;
	ll actnum=0;
	int bits=0;
	forr(i,0,n)
	{
		if (txt[i]=='1')
			bits++;
	}
	int b1,b2;
	b1=bits-1,b2=bits+1;
	int actnum1,actnum2;
	actnum1=actnum2=0;
	forr(i,0,n)
	{
		if (b1!=0)
		{
			actnum1*=2;
			actnum1+=(txt[i]=='1');
			actnum1%=b1;
		}
		
		actnum2*=2;
		actnum2+=(txt[i]=='1');
		actnum2%=b2;
	}
	reverse(all(txt));
	ll pot1=1,pot2=1;
	//cout<<txt<<endl;
	//cout<<actnum1<<" "<<actnum2<<endl;
	forr(i,0,n)
	{
		ll auxanswer;
		if (txt[i]=='1')
		{
			if (b1==0)
			{
				v[n-1-i]=0;
				continue;
			}
			auxanswer=actnum1-pot1+b1;
			auxanswer%=b1;
			v[n-1-i]=f(auxanswer)+1;
		}
		else
		{
			auxanswer=actnum2+pot2;
			auxanswer%=b2;
			//cout<<auxanswer<<" "<<i<<endl;
			v[n-1-i]=f(auxanswer)+1;
		}
		if (b1!=0)
			pot1*=2,pot1%=b1;
		
		pot2*=2;pot2%=b2;
	}
	forr(i,0,n)
	{
		cout<<v[i]<<endl;
	}

}

Measured memory_bytes: 5320
#include <bits/stdc++.h>  // ver2.2.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,k;
  cin >> n >> k;
  Vi w(n),v(n);
  
  rep(i,0,n) cin >> w[i] >> v[i];
  
  VVi dp(n+5,Vi(k+5));
  
  rep(i,0,n){
    repeq(j,0,k){
      
      if(j-w[i] >= 0){
        dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i]);
      }
      
      else dp[i+1][j] = dp[i][j];  //  超えるときそのまま
    }
  }
  //VVerr(dp);
  cout << dp[n][k] << endl;
  return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};

int main( void ){
	initialize();
	vector <vector <P <int, bool> > > vec( 3, vector <P <int, bool> >( 3, P <int, bool>{0, false} ));
	rep( i, 0, 3 ){
		rep( j, 0, 3 ){
			cin >> vec[ i ][ j ].a;
		}
	}
	int N; cin >> N;
	rep( i, 0, N ){
		int input; cin >> input;
		rep( j, 0, 3 ){
			rep( k, 0, 3 ){
				if (vec[ j ][ k ].a == input){
					vec[ j ][ k ].b = true;
				}
			}
		}
	}
	bool is_ok = true;
	rep( i, 0, 3 ){
		is_ok = true;
		rep( j, 0, 3 ){	// horizontal
			if (!vec[ i ][ j ].b)
				is_ok = false;
		}
		if (is_ok){
			cout << "Yes\n";
			return 0;
		}
		is_ok = true;
		rep( j, 0, 3 ){	//virtical
			if (!vec[ j ][ i ].b)
				is_ok = false;
		}
		if (is_ok){
			cout << "Yes\n";
			return 0;
		}
	}
	is_ok = true;
	rep( i, 0, 3 ){
		if (!vec[ i ][ i ].b)
			is_ok = false;
	}
	if (is_ok){
		cout << "Yes\n";
		return 0;
	}
	is_ok = true;
	rep( i, 0, 3 ){
		if (!vec[ i ][ 2 - i ].b)
			is_ok = false;
	}
	if (is_ok){
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";

}

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;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
	cin.tie( 0 );
	ios::sync_with_stdio( false );
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())


n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
    x, y, z = map(int, input().split())
    uf.union(x-1, y-1)

print(uf.group_count())

Measured memory_bytes: 7856
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main(){
	char s[30];
	int a = 0;
	scanf("%s",s);

	FOR(i,0,30){
		if(s[i] == '\0') break;
		FOR(j,0,30){
			if(s[j] == '\0') break;
			if(i != j && s[i] == s[j]) a = 1;
		}
	}

	if(a == 0) printf("yes\n");
	else printf("no\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int j[100001]={0};
int i[100001]={0};
int main(void){
	int n;
	string x,xj,xi;
	int a,b;
	int cnt1,cnt2;
	LL mx1,mx2,mx3;
	cin>>n;
	cin>>x;
	
	xj=x;
	xj.push_back('J');
	for(a=0;a<xj.size();a++){
		swap(xj[a],xj[xj.size()-1]);
	}
	//cout<<xj<<endl;
	cnt1=0;
	for(a=1;a<=xj.size();a++){
		if(xj[a-1]=='J')	cnt1++;
		j[a]=cnt1;
	}
	/* for(a=0;a<=xj.size();a++){
		cout<<j[a]<<endl;
	} */
	cnt2=0;
	for(a=xj.size();a>0;a--){
		if(xj[a-1]=='I')	cnt2++;
		i[a]=cnt2;
	}
	/* for(a=0;a<=xj.size();a++){
		cout<<i[a]<<endl;
	} */
	mx1=0;
	for(a=1;a<=xj.size();a++){
		if(xj[a-1]=='O')	mx1+=(LL)j[a]*i[a];
	}
	//cout<<mx1<<endl;
	
	for(a=0;a<=xj.size();a++){
		j[a]=0;
		i[a]=0;
	}
	xi=x;
	xi.push_back('I');
	//cout<<xi<<endl;
	cnt1=0;
	for(a=1;a<=xi.size();a++){
		if(xi[a-1]=='J')	cnt1++;
		j[a]=cnt1;
	}
	cnt2=0;
	for(a=xi.size();a>0;a--){
		if(xi[a-1]=='I')	cnt2++;
		i[a]=cnt2;
	}
	mx2=0;
	for(a=1;a<=xi.size();a++){
		if(xi[a-1]=='O')	mx2+=(LL)j[a]*i[a];
	}
	//cout<<mx2<<endl;
	
	for(a=0;a<=xi.size();a++){
		j[a]=0;
		i[a]=0;
	}
	//cout<<x<<endl;
	cnt1=0;
	for(a=1;a<=x.size();a++){
		if(x[a-1]=='J')		cnt1++;
		j[a]=cnt1;
	}
	cnt2=0;
	for(a=x.size();a>0;a--){
		if(x[a-1]=='I')		cnt2++;
		i[a]=cnt2;
	}
	/* for(a=0;a<=x.size();a++){
		cout<<j[a]<<" "<<i[a]<<endl;
	} */
	int sum=0;
	for(a=1;a<=x.size();a++){
		if(x[a-1]=='O')		sum+=(LL)j[a]*i[a];
	}
	mx3=-1;
	int c,d;
	for(a=0;a<x.size()-1;a++){
		c=j[a+1];
		d=i[a+2];
		if(mx3<c*d){
			mx3=(LL)c*d;
		}
	}
	
	//cout<<mx3<<" "<<mx3+sum<<endl;
	cout<<max(mx3+sum,max(mx2,mx1))<<endl;
	return 0;
}
		
	


Measured memory_bytes: 4116
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;

int n;
int ans;
void dfs(int m){
    
    string str=to_string(m);
    string str2=to_string(n);
    
    if(str.size()>str2.size() || m>n)return ;
    if(str.size()>=3){
        int t=0,f=0,s=0;
        for(int i=0;i<str.size();i++){
            if(str[i]=='3')t=1;
            if(str[i]=='5')f=1;
            if(str[i]=='7')s=1;
            if(t && f && s){
                ans++;
                break;
            }
        }
    }
    dfs(m*10+7);
    dfs(m*10+5);
    dfs(m*10+3);
}

int main(){
    cin>>n;
    dfs(7);
    dfs(5);
    dfs(3);
    cout<<ans<<endl;
	

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scanf("%d %d", &h, &w)
	answer := countMovableCandidates(h, w)
	fmt.Println(answer)
}

func countMovableCandidates(h, w int) int {
	oddRows := h/2 + h%2
	evenRows := h / 2
	oddRowsMovableCell := w/2 + w%2
	evenRowsMovableCell := w / 2

	if h == 1 || w == 1 {
		return 1
	}

	return (oddRows * oddRowsMovableCell) + (evenRows * evenRowsMovableCell)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

int N;
int a[200010];
int p[200010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  rep(i, 0, N) {
    cin >> a[i];
    p[a[i]] = i+1;
  }
  
  set<int> st;
  st.emplace(0);
  st.emplace(N+1);
  int ans = 0;
  rep(i, 1, N+1) {
    auto it = st.lower_bound(p[i]);
    it--;
    auto it2 = st.upper_bound(p[i]);
    int tmp = 1;
    tmp *= p[i]-*it;
    tmp *= *it2-p[i];
    st.emplace(p[i]);
    ans += tmp*i;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12800
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9
#define MOD 1000000007;//1e9+7

void solve() {
    int N, K;
    cin >> N >> K;
    vector<double>sum(N + 1, 0);
    for (int i = 1; i <= N; i++){
        double p;
        cin >> p;
        sum[i] = sum[i - 1] + (p + 1) / 2;
    }
    double ans = 0;
    for (int i = 0; i <= N - K; i++)ans = max(ans, sum[i + K] - sum[i]);
    printf("%.12lf", ans);
}

int main() {
    solve();
    return 0;
}

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

int main()
{
	int N;
	double p;
	while(cin>>N)
	{
			cout<<showpoint;
        	cout<<fixed;
        	cout<<setprecision(10);
        	if(N%2==0){
        		p=(N/2)/(double)N;
        		cout<<p<<endl;
        	}
        	else{
        		p=((N+1)/2)/(double)N;
        		cout<<p<<endl;
        	}
	}
}

Measured memory_bytes: 256
// C - Snack
#include <stdio.h>
typedef long long ll;

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

int main(void){
    ll a, b;
    scanf("%lld%lld", &a, &b);
    // printf("gcd:%d\n", gcd(a, b));
    printf("%lld\n", a*b/gcd(a, b));
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

int main()
{
    char s[10],t[10];
    int i,flag=0,j;

    scanf("%s",s);
    scanf("%s",t);
    for(i=0; i<=2; i++){
        if(s[i]==t[i])
        {
           flag++;
        }
    }

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


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import logging
import time
import math


class Solver:
    def __init__(self):
        self.s = ''
        self.k = 0

    # 入力
    def input_value(self):
        # self.n = int(input())
        # self.A, self.B = map(int, input().split())
        # self.A = list(map(int, input().split()))
        # self.a, self.b, self.c = map(int, [input() for i in range(4)])
        # self.t = [None] * self.n
        self.s = input()
        self.k = int(input())

    # @staticmethod
    # def run(s, k):
    #     # count = [None] * len(s)
    #     sum = 0
    #     for i in range(len(s) + 1):
    #         # count[i] = int(s[i]) ** (5 * 10 ** 15)
    #         # sum += int(s[i]) ** (5 * 10 ** 15)
    #         sum += (5 * 10 ** 15) * math.log10(int(s[i]))
    #         if sum > math.log10(k):
    #             return s[i]
    #     return '0'

    @staticmethod
    def run(s, k):
        # count = [None] * len(s)
        i = 0
        while s[i] == '1':
            i += 1
            if i >= len(s) or i >= k:
                return '1'
        return s[i]

    @staticmethod
    def test():
        start_time = time.time()

        assert Solver.run('1214', 4) == '2', 'Error.'
        assert Solver.run('3', 157) == '3', 'Error.'
        assert Solver.run('299792458', 9460730472580800) == '2', 'Error.'
        assert Solver.run('123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789', 100000000000000000) == '2', 'Error.'
        assert Solver.run('11123', 2) == '1', 'Error.'
        assert Solver.run('11123', 3) == '1', 'Error.'
        assert Solver.run('11123', 4) == '2', 'Error.'
        assert Solver.run('11123', 5) == '2', 'Error.'

        elapsed_time = time.time() - start_time
        logging.debug('elapsed_time: {0}'.format(elapsed_time) + '[sec]')


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    solver = Solver()
    # Solver.test()

    solver.input_value()
    ans = solver.run(solver.s, solver.k)
    print(ans)


Measured memory_bytes: 4208
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
MOD = 10 ** 9 + 7
isAble = True
if N % 2 == 1:
    if cnt[0] != 1:
        isAble = False
    for i in range(2, N, 2):
        if cnt[i] != 2:
            isAble = False
            break
else:
    for i in range(1, N, 2):
        if cnt[i] != 2:
            isAble = False
            break

if isAble:
    ans = 1
    for _ in range(N // 2):
        ans *= 2
        ans %= MOD
    print(ans)
else:
    print(0)


Measured memory_bytes: 20724
import scala.math

object Main extends App {
  def Y(swich: Int): Unit ={
    println(if(swich == 1) "Yes" else "No")
  }

  val sc = new java.util.Scanner(System.in)
  var n, d = sc.nextInt()
  var x:Array[Array[Double]] = Array.fill(n,2)(sc.nextDouble())
  var ans = 0
  for (i <- 0 until n){
    if (math.pow(x(i)(0) * x(i)(0) + (x(i)(1) * x(i)(1)),0.5) <= d ) ans += 1
  }
  println(ans)
}


Measured memory_bytes: 68144
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		int wk[][] = new int[2][10];
		for(int i = 0 ; i < 2 ; i++){
			for(int j = 0 ; j < 10 ; j++){
				wk[i][j] = scan.nextInt();
			}
		}
		 int WK[][] = new int[2][3];
		 int hantei = 0;
		for(int i = 0 ; i < 2 ; i++){
			for(int j = 0 ; j < 3 ; j++){
				WK[i][j] = wk[i][0];
				hantei = 0;
				for(int k = 1 ; k < 10 ; k++){
					if(WK[i][j] < wk[i][k]){
						WK[i][j] = wk[i][k];
						hantei = k;
					}
				}
				wk[i][hantei] = -1;
			}
		}
		System.out.println((WK[0][0] + WK[0][1] + WK[0][2]) + " " + (WK[1][0] + WK[1][1] + WK[1][2]));
	}
}

Measured memory_bytes: 26156