akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k, c = map(int, input().split())
s = list(input().rstrip())

to_work_f = set() 
to_work_b = set() 

rest = 0
for i, ch in enumerate(s):
    if rest == 0 and ch == "o":
        to_work_f.add(i)
        rest = c
    elif rest != 0:
        rest -= 1
rest = 0
for i, ch in enumerate(s[::-1]):
    if rest == 0 and ch == "o":
        to_work_b.add(n - i - 1)
        rest = c
    elif rest != 0:
        rest -= 1

if len(to_work_f) > k or len(to_work_b) > k:
    exit()
ans = []
for item in to_work_f:
    if item in to_work_b:
        ans.append(item + 1)
ans.sort()
for item in ans:
    print(item)

Measured memory_bytes: 43188
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*/
/**status : */
/**url: */
/* Generate with Contest-Helper **/
/* https://github.com/goldenbijoy/Contest_Helper */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define INF 1e18
#define __FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr2V(x,sz) for(int iii=0;i<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define Pause system("pause");
#define MAX 100050/** can increase another 0 */

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s;

    cin>>n;

    if(n%2==1 || n<9) cout<<0<<NL;
    else{
        ll prev = 1;
        x = 5;
        ans = 0;
        ll z;
        while(n/x>=1){
            ans+=((n/x)/2);

            x*=5;
        }
        cout<<ans<<NL;
    }


    /// Don't forget to initialize array....
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int x1, x2, x3, x4, x5, ans=0;
    
    scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
    if(x1==0){
      ans=1;
    }else if(x2==0){
      ans=2;
    }else if(x3==0){
      ans=3;
    }else if(x4==0){
      ans=4;
    }else{
      ans=5;
    }
    printf("%d",ans);
return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100005];
int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
	}
	LL ans = 1e18;
	for(int i=1;i<=n;i++){
		int l = i;
		int r = i+k-1;
		if(r > n) break;
		LL res = 0;
		if(a[l] <= 0 && 0 <= a[r]){
			res = min(abs(a[r]) + abs(a[r]-a[l]), abs(a[l]) + abs(a[r]-a[l]));
		}
		else if(a[l] <= 0 && a[r] <= 0){
			res = abs(a[l]);
		}
		else if(0 <= a[l] && 0 <= a[r]){
			res = abs(a[r]);
		}
		ans = min(ans, res);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(void){
    int a;
    cin>>a;
    if(a%10==9||a/10==9){
        cout<<"Yes"<<endl;
    }else cout <<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll k;
  cin >> k;
  ll sev = 7;
  ll ans = -1;
  rep(i, k) {
    sev = sev % k;
    if (sev == 0) {
      ans = i + 1;
      break;
    } else {
      sev = sev * 10 + 7;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
n = int(input())
a = list(map(int, input().split()))
cnt = 0
tmp = 1000000005
for i in range(n):
  if a[i] < 0:
    a[i] = -a[i]
    cnt += 1
  tmp = min(tmp, a[i])
if cnt % 2 == 0:
  print(sum(a))
else:
  print(sum(a) - 2 * tmp)

Measured memory_bytes: 14284
package main

import "fmt"

var A, B, C, D int

func main() {
	fmt.Scan(&A, &B, &C, &D)
	if A+B > C+D {
		fmt.Println("Left")
	} else if A+B < C+D {
		fmt.Println("Right")
	} else {
		fmt.Println("Balanced")
	}
}


Measured memory_bytes: 512
d = list(map(int,input().split()))
e = list(map(int,input().split()))
f = list(map(int,input().split()))


k =0
for i in range(0,2):
        if d[i+1]-d[i]==e[i+1]-e[i]==f[i+1]-f[i]:
            k = k + 1
            #print(k)
if d[0]-e[0]==d[1]-e[1]==d[2]-e[2] and d[0]-f[0] == d[1]-f[1] == d[2]-f[2]:
    k = k+1
    #print(k)
if d[0] + f[2] == d[2] + f[0]:
    k = k +1
    #print(k)

if k == 4:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MAX 101
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int n,m;
vector<int> e[MAX];
bool a[MAX],b[MAX];

int rec(int u){
  if(a[u])return 1;
  a[u]=true;
  FOR(i,0,e[u].size()){
    if(b[e[u][i]])continue;
    if(rec(e[u][i]))return 1;
  }
  b[u]=true;
  a[u]=false;
  return 0;
}

int solve(){
  fill(b,b+MAX,false);
  FOR(i,0,n){
    fill(a,a+MAX,false);
    if(b[i])continue;
    if(rec(i))return 1;
  }
  return 0;
}

int main(){
  cin>>n>>m;
  FOR(i,0,m){
    int s,t;
    cin>>s>>t;
    e[s].pb(t);
  }
  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main()
{
    string s;
    cin >> s;
    sort(all(s));
    bool diff = 1;
    for (int i = 1; i < sz(s); i++)
    {
        if (s[i] == s[i - 1])
        {
            diff = 0;
            break;
        }
    }
    if (diff)
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}


Measured memory_bytes: 3608
n = int(input())
s = input()

output = 0
for idx1 in range(10):
    digit1 = s.find(str(idx1))
    if digit1 == -1:
        continue

    for idx2 in range(10):
        digit2 = s.find(str(idx2), digit1 + 1)
        if digit2 == -1:
            continue

        for idx3 in range(10):
            digit3 = s.find(str(idx3), digit2 + 1)
            if digit3 == -1:
                continue
            output += 1
print(output)

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

#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int lli;
typedef pair<int, int> P;

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

    int ans = 0;

    for (int i = 0; i < n; i++) {
        bool is_ok = true;
        for (int j = 0; j < n; j++) {
            // i 個目より左にあるやつが全部 i 個目以下かどうかをチェック
            if (j >= i)
                break;
            if (h[i] < h[j])
                is_ok = false;
        }
        if (is_ok)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int recur(ll pos,ll n,ll a[],ll dp[])
{
if(pos+1>=n||pos+2>=n)
  return abs(a[pos]-a[n-1]);
  if(dp[pos]!=-1)
    return dp[pos];
  return dp[pos]=min((abs(a[pos]-a[pos+1])+recur(pos+1,n,a,dp)),(abs(a[pos]-a[pos+2])+recur(pos+2,n,a,dp)));}
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  ll dp[n];
  for(int i=0;i<n;i++)
    dp[i]=-1;
  cout<<recur(0,n,a,dp);
}

Measured memory_bytes: 6528
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class agc026_c {
private:
    long long brute(const string &S, int a, int num, int N, vector<int> &vis, vector<int> &cnt) {
        if (num == N) {
            for (int i = 0, j = 2 * N - 1; i < 2 * N; ++i, --j) {
                while (i < 2 * N && !vis[i]) ++i;
                while (j >= 0 && vis[j]) --j;
                if (i < 2 * N && S[i] != S[j]) {
                    return 0;
                }
            }
            return 1;
        }
        long long res = 0;
        for (int i = a; i < 2 * N; ++i) {
            if (cnt[S[i]] % 2 == 0) {
                vis[i] = 1;
                cnt[S[i]] -= 2;
                res += brute(S, i + 1, num + 1, N, vis, cnt);
                vis[i] = 0;
                cnt[S[i]] += 2;
            }
            
        }
        return res;
    }
    int num_ways(string S, string A, string B) {
        int N = S.size();
        int n1 = A.size(), n2 = B.size();
        vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
        dp[0][0] = 1;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < n1 && j <= i; ++j) {
                if (S[i] == A[j]) {
                    int k = i - j;
                    dp[j + 1][k] += dp[j][k];
                }
            }
            for (int k = 0; k < n2 && k <= i; ++k) {
                if (S[i] == B[k]) {
                    int j = i - k;
                    dp[j][k + 1] += dp[j][k];
                }
            }
        }
        return dp[n1][n2];
    }
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        string S;
        in >> S;
        /*vector<int> vis(2 * N, 0), cnt(1000, 0);
        for (char c : S) {
            ++cnt[c];
        }
        out << brute(S, 0, 0, N, vis, cnt) << "\n";*/
        long long res = 0;
        string last = S.substr(N);
        reverse(begin(last), end(last));
        for (int i = 0; i < (1 << N); ++i) {
            string a, b;
            for (int j = 0; j < N; ++j) {
                if (i & (1 << j)) {
                    a += S[j];
                } else {
                    b += S[j];
                }
            }
            res += num_ways(last, a, b);
        }
        out << res << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	agc026_c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
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()))
p.sort()
q.sort()
nums=p[-X:]+q[-Y:]+r
nums.sort()
print(sum(nums[-(X+Y):]))

Measured memory_bytes: 23328
#include <stdio.h>
#define S 1000000

int search(int A[S],int n, int key){
  int i;
  A[n]=key;
  for(i=0 ; A[i]!=key ; i++){}
  return i != n;
}

int main(){
  int i=0,n,A[S],q,key,sum=0;
  scanf("%d" ,&n);
  while(i<n){
    scanf("%d",&A[i]);
    i++;
  }
  scanf("%d",&q);
  i=0;
  while(q!=i){
    
    scanf("%d",&key);
    if(search(A,n,key)){
      sum++;
    }
    i++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    set<string> st;
    REP(i,N) {
        string s; cin >> s;
        st.insert(s);
    }

    OUT(st.size())

    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M ;
  
  vector <int> A (M);
  for ( int i=0 ; i<M ; i++ ) {
    cin >> A.at (i) ;
    }
  int X=0;
    for ( int i=0 ; i<M ; i++ ) {
      X=X+ A.at(i) ;
    }  
  N= N- X ;
  
  
  if(N<0) {
    
    cout << "-1" << endl;
  }
  
  else {
    
    
    cout << N << endl;
  }
  
  
  
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main()
{
	int n, d, x;
	cin >> n >> d >> x;
	vi a(n);
	int cnt = 0;
	int temp;

	rep(i,n) {
		temp = d;
		cin >> a[i];
		while(temp > 0){
			temp -= a[i];
			cnt++;
		}
	}
	cout << cnt + x << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;



int n,k;
const int MOD = 1000000007;
const int nax = 1000005;
ll int f[nax] , iv[nax];

ll int powermod(ll int base, ll int exp, ll int mod) {
    ll result = 1;
    while (exp != 0) {
        if ((exp % 2) == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}
ll C(ll n,ll r){
	if(n<r)return 0;
	ll ans=(f[n]*iv[r])%MOD;
	ans=(ans*iv[n-r])%MOD;
	return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    f[0] = 1;
    iv[0] = 1;
    for (size_t i = 1; i < nax; i++) {
        f[i] = (i*f[i-1]) % MOD;
        //iv[i] = powermod(f[i] , MOD-2 , MOD) % MOD;
    }
    iv[nax-1] = powermod(f[nax-1],MOD-2  , MOD);
	for(ll int i=nax-2;i>=0;--i)iv[i]=(iv[i+1]*(i+1))%MOD;

    cin>>n>>k;

    vector<int> v(n);

    REP(i,n){cin>>v[i];}

    sort(ALL(v));

    ll int ans = 0, mx  = 0 , mn = 0;
    for (size_t i = 0 ; i < n ; i++) {
        ll int left  = i , right = n - 1 - i;
        mx = (mx + v[i] * C(left , k-1 )) % MOD;
        mn = (mn + v[i] * C(right , k-1 )) % MOD;

    }
    ans = (mx - mn + MOD) % MOD;
    while(ans < 0){
        ans  = (ans + MOD) % MOD;
    }
    cout<<ans<<"\n";
    return 0;

}


Measured memory_bytes: 16256
N=int(input())

def divide(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
  
divide=divide(N)

L=len(divide)

if L%2==0:
  print(divide[L//2-1]+divide[L//2]-2)
else:
  print(divide[(L+1)//2-1]*2-2)

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

int main()
{
	char a[1001];
	while(scanf("%s",a)!=EOF){
		int i,j,max,n;
		n=strlen(a);
		for(i=0;i<n-1;i++){
			if(a[i]=='C')
			break;
		}
		for(j=0;j<=n-1;j++){
			if(a[j]=='F')
			max=j;
		}
		if(i<max)
		printf("Yes\n");
		else
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n ; i++) {
            p[i] = sc.nextInt();
        }
        int c = 0;
        for (int i = 0 ; i < n ; i++) {
            if (p[i] != i + 1) c++;
        }

        if (c > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }

    }

}


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

int main(){
  int n, k, q;
  cin >> n >> k >> q;

  vector<int> p(n, k-q);
  rep(i, q){
    int a;
    cin >> a;
    a--;
    p[a]++;
  }

  rep(i, n) cout << (p[i] > 0 ? "Yes" : "No") << endl;

  return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.rbegin(), a.rend());
  
  priority_queue<pair<ll, ll>> pq;
  pq.push(make_pair(a.front(), a.front()));
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    auto [x, y] = pq.top();
    pq.pop();
    ans += min(x, y);
    pair<ll, ll> p1 = make_pair(a.at(i), y), p2 = make_pair(a.at(i), y);
    if (p1.first > p1.second) swap(p1.first, p1.second);
    if (p2.first > p2.second) swap(p2.first, p2.second);
    pq.push(p1);
    pq.push(p2);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 8984
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(void){
  int n;
  cin>>n;

  vector<int> a(n),b(n),c(n);
  r(i,n)cin>>a.at(i);
  r(i,n)cin>>b.at(i);
  r(i,n-1)cin>>c.at(i);

  int sum=0;
  r(i,n){
    sum+=b.at(a.at(i)-1);
    
    if(i!=0){
      if(a.at(i)-a.at(i-1)==1)sum+=c.at(a.at(i-1)-1);
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>

const double PI=3.14159265358979323846;

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

int main() {
  double r;
  cin >> r;
  printf("%5.10f %5.10f", PI*r*r, 2.0*PI*r);
}



Measured memory_bytes: 3280
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll sum = 0;
    ll d[N];
    rep(i, N){
        cin >> d[i];
        sum += d[i];
    }

    ll ans = 0;
    rep(i, N - 1){
        sum -= d[i];
        ans += d[i] * sum;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

string s;
ll memo[110][4][2];

ll f(int index, int k, bool any)
{
  if (memo[index][k][any] != -LINF)
  {
    return memo[index][k][any];
  }

  if (index == s.length())
  {
    memo[index][k][any] = (k == 0 ? 1 : 0);
    return memo[index][k][any];
  }

  if (any)
  {
    if (k == 0)
    {
      memo[index][k][any] = f(index + 1, 0, true);
      return memo[index][k][any];
    }
    else
    {
      memo[index][k][any] = 9 * f(index + 1, k - 1, true) + f(index + 1, k, true);
      return memo[index][k][any];
    }
  }
  else
  {
    ll top = s[index] - '0';
    if (k == 0)
    {
      memo[index][k][any] = 1;
      return memo[index][k][any];
    }
    else
    {
      if (top == 0)
      {
        memo[index][k][any] = f(index + 1, k, false);
        return memo[index][k][any];
      }
      else
      {
        memo[index][k][any] = f(index + 1, k, true) + max((top - 1), 0LL) * f(index + 1, k - 1, true) + f(index + 1, k - 1, false);
        return memo[index][k][any];
      }
    }
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  cin >> s;
  int k;
  cin >> k;
  rep(i, 110) rep(j, 4) memo[i][j][0] = memo[i][j][1] = -LINF;
  cout << f(0, k, false) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 500000
#define INF 1000000000

int L[N], R[N];
long long count = 0;

void merge(int A[], int left, int mid, int right)
{
  int n1, n2, i, j, k;

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];

  L[n1] = INF;
  R[n2] = INF;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
      count += n1 - i;
    }
  }
}

void mergeSort(int A[], int left, int right)
{
  int mid;

  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void)
{
  int i, n, A[N];

  scanf("%d", &n);

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

  mergeSort(A, 0, n);

  printf("%lld\n", count);            //%lldとすることでlong long int型の数値をprint文で表示

  return 0;
}



Measured memory_bytes: 3288
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    cnt=0
    for i in range(n):
        if A[A[i]-1]==i+1:
            cnt+=1
    print(cnt//2)    
resolve()

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

using namespace std;

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

vector<char> s;

string s1="";
string s2="";
string tot="";

const int MAX_N=19;
long long dp[MAX_N][MAX_N];

int n;

long long calc(int chars_in_s_left, int to_use_for_s1)
{
    if(dp[chars_in_s_left][to_use_for_s1] != -1) return dp[chars_in_s_left][to_use_for_s1];
    int to_use_for_s2=chars_in_s_left-to_use_for_s1;
    if(chars_in_s_left<to_use_for_s1 || chars_in_s_left<to_use_for_s2) return dp[chars_in_s_left][to_use_for_s1]=0;
    if(chars_in_s_left==0) return dp[chars_in_s_left][to_use_for_s1]=1;
    long long ret_and_save=0;
    if(to_use_for_s1>0 && s[2*n-chars_in_s_left]==tot[tot.size()-to_use_for_s1])
    {
        ret_and_save+=calc(chars_in_s_left-1, to_use_for_s1-1);
    }
    if(to_use_for_s2>0 && s[2*n-chars_in_s_left]==tot[to_use_for_s2-1])
    {
        ret_and_save+=calc(chars_in_s_left-1, to_use_for_s1);
    }
    return dp[chars_in_s_left][to_use_for_s1]=ret_and_save;
}

int main()
{
    //freopen("inp.in", "r", stdin);
    //freopen("outp.out", "w", stdout);
    //ios::sync_with_stdio(false);
    scanf("%d", &n);
    s.assign(2*n, '#');
    for(int i=0; i<2*n; i++) scanf(" %c", &s[i]);
    long long ans=0;
    for(long long mask=0; mask<(1LL<<n); mask++)
    {
        s1="";
        s2="";
        tot="";
        for(int i=0; i<n; i++)
        {
            if((1LL<<i)&mask)
            {
                s2+=s[i];
            }
            else
            {
                s1+=s[i];
            }
        }
        for(int i=0; i<s1.size(); i++) tot+=s1[i];
        for(int i=((int)s2.size())-1; i>=0; i--) tot+=s2[i];
        for(int i=0; i<MAX_N; i++)
        {
            for(int j=0; j<MAX_N; j++)
            {
                dp[i][j]=-1;
            }
        }
        ans += calc(n,n-s1.size());
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
class CountUp:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

S = input()
T = input()
N = len(S)
Sdic = defaultdict(CountUp())
Tdic = defaultdict(CountUp())
for i in range(N):
    s = Sdic[S[i]]
    t = Tdic[T[i]]
    if s != t:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 41840
#include<stdio.h>
#include<math.h>

int main(){
	
	double x,h,s ;
	
	while(1){
		scanf("%lf %lf" ,&x ,&h ) ;
		if( x==0 && h==0 ) break;
		
		s = x * x + 2 * ( x * sqrt( pow(x/2,2) + pow(h,2) ) ) ;
		printf("%lf\n" ,s ) ;
	}
return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

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

struct Edge{
	int s,d,w,c;
	Edge(int s,int d,int w,int c):s(s),d(d),w(w),c(c){}
	bool operator<(const Edge& e)const{return w<e.w;}
	bool operator>(const Edge& e)const{return w>e.w;}
};
typedef vector<vector<Edge>> Graph;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		Graph g(n);
		rep(i,m){
			int u,v,d,c; cin>>u>>v>>d>>c; u--,v--;
			g[u].emplace_back(u,v,d,c);
			g[v].emplace_back(v,u,d,c);
		}
		
		vector<int> d(n,1<<29);
		vector<vector<int>> p(n);
		priority_queue<Edge,vector<Edge>,greater<Edge>> pq;
		pq.emplace(-1,0,0,0);
		while(!pq.empty()){
			Edge c=pq.top(); pq.pop();
			if(d[c.d]>=c.w) p[c.d].push_back(c.c);
			if(d[c.d]<=c.w) continue;
			d[c.d]=c.w;
			for(Edge e:g[c.d])
				pq.emplace(e.s,e.d,c.w+e.w,e.c);
		}
		
		int res=0;
		rep(i,n) res+=*min_element(begin(p[i]),end(p[i]));
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3424
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i,sum=0;
    for(i=0;i<s.size();i++)
    {
        sum+=s[i]-'0';
    }
    if(sum==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        if(sum%9==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    }


Measured memory_bytes: 3704
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
N,K = parseMap(split(readline()))
if abs(N - K) > N
    println(N)
else
    if N > K
        h = N ÷ K
        N -= K * h
        ans = min(abs(N-K),N)
        println(ans)
    else
        h = K ÷ N
        K -= N * h
        ans = min(abs(N-K),K)
        println(ans)
    end
end
end

main()

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

int main () {
  string S;
  cin >> S;
  int x = S.size();
  int count = 0;
  for (int i = 0; i < x-1; i++) {
    if (S.at(i) != S.at(i+1)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int num[100005];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>num[i];
	for(int i=2;i<=n;i++){
		if(num[i]<num[i-1])
			num[i]+=1;
	}
	for(int i=1;i<=n;i++){
		if(num[i]<num[i-1]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <deque>
#include <numeric>
#include <set>
using namespace std;

typedef long long ll;

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toid(int i, int j){
    if(i > j)   swap(i, j);
    return id[i][j];
}

bool visited[MAXV];     // 訪問済みフラグ
bool calculated[MAXV];  // 計算済みフラグ
int dp[MAXV];           // 距離
int dfs(int v){
    if(visited[v]){
        // 計算済みでない場合に、訪問済みの頂点に訪れた場合、閉路を検出した。
        if(!calculated[v])   return -1;

        return dp[v];
    }

    visited[v] = true;
    dp[v] = 1;
    for(auto u : to[v]){
        int res = dfs(u);
        // 閉路を検出すれば、-1を返す。
        if(res == -1)   return -1;
        dp[v] = max(dp[v], res + 1);
    }
    
    calculated[v] = true;
    return dp[v];
}

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

    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n-1; ++j){
            cin >> a[i][j];
            --a[i][j];
        }
    }

    int V = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i < j)   id[i][j] = V++;
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n - 1; ++j){
            a[i][j] = toid(i, a[i][j]);
        }
        for(int j = 0; j < n - 2; ++j){
            to[a[i][j + 1]].push_back(a[i][j]);
        }
    }

    int ans = 0;
    for(int i = 0; i < V; ++i){
        int res = dfs(i);
        if(res == -1){
            puts("-1");
            return 0;
        }
        ans = max(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 38528
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int a, b;
    cin >> a >> b;
    cout << a * b - (b + a - 1) << endl;
}


Measured memory_bytes: 256
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function Main(_: NormalInput) {
  const S=_.str();
  const [a,b]=[S.substring(0,2), S.substring(2,4)];
  const [am, bm]=[a,b].map(item=>parseInt(item, 10)).map(num=>num>0&&num<=12);
  if(am){
    if(bm){
      console.log('AMBIGUOUS');
    }else{
      console.log('MMYY');
    }
  }else{
    if(bm){
      console.log('YYMM');
    }else{
      console.log('NA');
    }
  }
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
ll A[N], B[N], C[N];
int main() {
	int x, y, a, b, c;
	scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);
	for (int i = 1; i <= a; i++)
		scanf("%lld", &A[i]);
	for (int i = 1; i <= b; i++)
		scanf("%lld", &B[i]);
	for (int i = 1; i <= c; i++)
		scanf("%lld", &C[i]);
	sort(A + 1, A + a + 1);
	sort(B + 1, B + b + 1);
	sort(C + 1, C + c + 1);
	A[a + 1] = 2e9, B[b + 1] = 2e9;
	int la = a - x + 1, lb = b - y + 1;
	ll ans = 0;
	for (int i = a - x + 1; i <= a; i++)
		ans += A[i];
	for (int i = b - y + 1; i <= b; i++)
		ans += B[i];
	while (la <= a || lb <= b) {
		ll t = min(A[la], B[lb]);
		if (c != 0 && C[c] > t)
			ans += (C[c] - t), c--;
		else
			break;
		if (t == A[la])
			la++;
		else
			lb++;
	}
	printf("%lld", ans);	
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll n, ans = 0;
    string s, t;

    cin >> s >> t;



    cout << t << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> pl3;

const ll max_n = 52;
const ll max_s = 2500;
vector<ll> c, d;
vector<pl3> g[max_n];

ll n, m;
ll s;

const ll INF = 1e15;
ll dp[max_n+1][max_s + 1];

void dijkstra(){
	s = min(s, max_s);
	rep(i, n) rep(j, max_s + 1) dp[i][j] = INF;
	dp[0][s] = 0;

	priority_queue<pl3,vector<pl3>,greater<pl3> > que;
	que.push({0, {0, s}});

	while(!que.empty()){
		pl3 p = que.top();
		que.pop();

		ll time = p.first;
		ll v = p.second.first;
		ll ns = p.second.second;

		if(dp[v][ns] < time) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる

		if(ns + c[v] <= max_s && dp[v][ns + c[v]] > time + d[v]){
			dp[v][ns + c[v]] = time + d[v];
			que.push({time + d[v], {v, ns + c[v]}});
		}

		for(pl3 x : g[v]){
			ll w = x.first;
			ll a = x.second.first;
			ll b = x.second.second;

			if(ns < a || dp[w][ns - a] <= time + b) continue;
			dp[w][ns - a] = time + b;
			que.push({time + b, {w, ns - a}});
		}
	}
}

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

	cin >> n >> m >> s;
	rep(i, m){
		ll u, v, a, b;
		cin >> u >> v >> a >> b;
		u--;
		v--;
		g[u].push_back({v, {a, b}});
		g[v].push_back({u, {a, b}});
	}

	c.resize(n);
	d.resize(n);
	rep(i, n) cin >> c[i] >> d[i];

	dijkstra();

	rep(i, n-1){
		ll ans = INF;
		rep(j, max_s + 1) ans = min(ans, dp[i+1][j]);
		cout << ans << "\n";
	}
}


Measured memory_bytes: 7256
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n;
     cin>>n;
  
      int arr[n];
      for(int i=0;i<n;i++)
          cin>>arr[i];
  
        sort(arr,arr+n);
       
       double sum=0;
      for(int i=0;i<n;i++)
      {
          if(i==0)
            sum=arr[i];
        
           else
             sum=(sum+arr[i])/2.0;
      }
      cout<<sum;
}

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

int main () {
  // 期待値が最大となる連続するK個の整数の組を特定
  int N,K,max_count = 0;
  cin >> N >> K;
  vector<int>num(N);
  vector<int>sum(N+1); sum.at(0) = 0.0;
  
  for (int i = 0; i < N; i++) {
    cin >> num.at(i);
  }
  for (int i = 0; i < N; i++) {
    sum.at(i+1) = sum.at(i) + num.at(i);
  }
  
  for (int i = K; i < N+1; i++) {
    max_count = max(max_count,sum.at(i)-sum.at(i-K));
  }  
  
  // 期待値の計算式
  cout << fixed << setprecision(10);
  cout << (double) max_count / (double)2 + 0.5 * K << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 P = 1000000000 + 7;
i64 deg(i64 x, i64 d) {
    d %= P - 1;
    if (d < 0) d += P - 1;
    i64 y = 1;
    while (d) {
        if (d & 1) y *= x, y %= P;
        x *= x, x %= P;
        d /= 2;
    }
    return y;
}

const int MAXN = 300000;
i64 fact[MAXN], tcaf[MAXN];

i64 CNK(int a, int b) {
    return fact[a] * tcaf[b] % P * tcaf[a - b] % P;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    fact[0] = tcaf[0] = 1;
    for1(i, MAXN - 1) fact[i] = i * fact[i - 1] % P, tcaf[i] = deg(fact[i], -1);
    int H, W, N;
    cin >> H >> W >> N;
    vector<pii> a(N);
    forn(i, N) cin >> a[i].fi >> a[i].se;
    a.pb(mp(H, W));
    sort(all(a));
    vi64 dp(N + 1);
    forn(i, N + 1) {
        dp[i] = CNK(a[i].fi + a[i].se - 2, a[i].fi - 1);
        forn(j, i) {
            if (a[j].fi <= a[i].fi && a[j].se <= a[i].se) {
                dp[i] -= dp[j] * CNK(a[i].fi - a[j].fi + a[i].se - a[j].se, a[i].fi - a[j].fi);
                dp[i] %= P;
            }
        }
    }
    i64 res = dp[N];
    if (res < 0) res += P;
    cout << res << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 5120
<?php

fscanf(STDIN,"%d %d %d",$a,$b,$c);
$array = range($a,$b);
$ans = 0;
for($i=0; $i<count($array); $i++){
    if($c % $array[$i] == 0){
        $ans++;
    }
}
echo $ans,PHP_EOL;


Measured memory_bytes: 10688
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	string X;
	
	cin >> X;
	int S=0;
	int cnt=0;
	for(int i=0;i<X.size();i++)
	{
		if(X[i]=='S')S++;
		else if(S>0)
		{
			S--;
			cnt++;
		}
	}

	cout << X.size()-2*cnt << endl;
	return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
cities = {}
for m in range(M):
    p, y = map(int, input().split())
    if p not in cities:
        cities[p] = []
    cities[p].append([y, m])

ids = [None for _ in range(M)]
for city in sorted(cities.keys()):
    for idx, value in enumerate(sorted(cities[city])):
        year, m = value
        ids[m] = str(city).zfill(6) + str(idx + 1).zfill(6)

[print(id) for id in ids]

Measured memory_bytes: 95412
import java.util.*;

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

    String s = sc.next();
    char[] c = s.toCharArray();
    int l = c.length;
    long sum = 0;

    for(int i=0; i<(1<<(l-1));i++){//演算子に対しての全bit探索
      int[] kigou = new int[l-1];//初期化
      //System.out.println("*");
      for(int j=0; j<l-1;j++){//演算bitチェック
        if((i>>j&1)==1){//jビット目が1かどうか
          kigou[j] = 1;//bit配列への代入
        }
      }
      //System.out.println("***"+Integer.toBinaryString(i));

      //計算開始

      int pp = 0;//乗数
      for(int j=l-1; j>-1;j--){
        sum += (c[j]-48)*Math.pow(10,pp);
        //System.out.println(sum);
        if(j>0&&(kigou[j-1]==1)){
          pp = 0;
        }else{
          pp +=1;
        }
      }

    }

    System.out.println(sum);

  }
}

Measured memory_bytes: 21716
#include<stdio.h>
int main()
{
	int N,A,B;
	int m=1,t;
	scanf("%d%d%d",&N,&A,&B);
	if(N>=1&&N<=20&&A>=1&&A<=100&&B>=1&&B<=2000)
	{
		m=N*A;
		if(m>B)
		{
			t=B;
			B=m;
			m=t;
		}
	}
	 printf("%d",m);
	return 0;
 } 

Measured memory_bytes: 128
import sys
from collections import deque
import time
import bisect
def input():
    return sys.stdin.readline()[:-1]
s=input()
# if len(s)==1:
#     print('-1 -1')
#     exit()
n=len(s)
for i in range(1,n):
    if s[i-1]==s[i]:
        print(str(i)+" "+str(i+1))
        exit()

for i in range(2,n):
    if s[i-2]==s[i]:
        print(str(i-1)+" "+str(i+1))
        exit()

print('-1 -1')

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

int main() {
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a);
    for(int i=0;i<a;i++) cin >> p[i];
    vector<int> q(b);
    for(int i=0;i<b;i++) cin >> q[i];
    vector<int> r(c);
    for(int i=0;i<c;i++) cin >> r[i];
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    sort(r.begin(),r.end());
    reverse(r.begin(),r.end());
    
    ll sum=0;
    vector<int> s;
    for(int i = a-x; i < a; i++) {
        sum += p[i];
        s.push_back(p[i]);
    }
    for(int i = b-y; i < b; i++) {
        sum += q[i];
        s.push_back(q[i]);
    }
    sort(s.begin(),s.end());
    
    int i=0;

    while(i<c && i<x+y){
        sum += max(s[i],r[i])-s[i];
        i++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5420
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<ll> V;

int main()
{
    ios;
    ll n,m,s[20005],c[2002];
    cin>>n>>m;
    rep(i,0,m-1)cin>>s[i]>>c[i];
    ll chck=0;
    ll digi[n+2];
    rep(i,0,n)digi[i]=-1;
    rep(i,0,m-1)
    {
        if(digi[s[i]]!=c[i] && digi[s[i]]!=-1)
            chck++;
        else
            digi[s[i]]=c[i];
    }
    if(n==1 && m==0){cout<<0;return 0;}
    if(digi[1]==0 && n!=1)chck++;
    if(chck)cout<<-1;
    else
    {
        if(digi[1]==-1)digi[1]=1;
        rep(i,2,n)if(digi[i]==-1)digi[i]=0;
        rep(i,1,n)cout<<digi[i];
    }
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
 
def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
 
a, b = map(int, input().split())
print(len(set(pf(gcd(a, b)))) + 1)

Measured memory_bytes: 5048
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


int main()
{
    while (true)
    {
        int n, x; cin >> n >> x;
        if (n == 0 and x == 0) { break; }

        map<vector<int>, int> mp;
        reps (i, n) reps (k, n) reps (m, n)
        {
            if (!(i != k and k != m and m != i)) { continue; }

            if (i + k + m == x)
            {
                vector<int> tmp = { i, k, m };
                sort(ALL(tmp));
                mp[tmp] = 1;
            }
        }

        cout << mp.size() << "\n";
    }

    return 0;
}



Measured memory_bytes: 3276
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    if ( s.length() < 4 ) {
        cout << "No" << endl;
        return 0;
    }
    string s_req = "YAKI";
    rep(i, 4) {
        if ( s[i] == s_req[i] ) continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

vector<long long> fact(200001,1);
void factorial(int N){
    for(int i=1; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
}

map<long long, long long> inv_fact;
long long inv_factorial(long long x){
    if (inv_fact.count(x)){
        return inv_fact[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv_fact[x]=ret;
    return ret;
}

long long comb(ll a, ll b){
    ll ret=1;
    for(ll i=0; i<b; i++){
        ret*=(a-i);
        ret%=MOD;
        ret*=inv_factorial(b-i);
        ret%=MOD;
    }
    return ret;
}

ll pow2(ll N){
    ll ret=1;
    ll base=2;
    while(N>0){
        if(N&1){
            ret*=base;
            ret%=MOD;
        }
        base*=base;
        base%=MOD;
        N/=2;
    }
    return ret;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    factorial(200000);

    cout << ((pow2(n)-1-comb(n,a)-comb(n,b))%MOD+MOD)%MOD << endl;
    
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 10000007
typedef long long ll;

int main(void)
{
	int N;
	cin >> N;
	vector<ll> v(N);
	rep(i, N) cin >> v.at(i);
	ll ans=INF, sum1=0, diff;
	ll sum2 = accumulate(v.begin(), v.end(), 0LL);
	rep(i, N-1)
	{
		sum1 += v.at(i);
		sum2 -= v.at(i);
		diff = abs(sum1 - sum2);
		if(diff<ans) ans = diff; 
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfInt()
    println(if (a <= b) a else a - 1)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 36196
# -*- coding: utf-8 -*-
 
A = int(input())
B = int(input())
C = int(input())
X = int(input())
 
count = 0
 
for i in range(A + 1):
  for j in range(B + 1):
    for k in range(C + 1):
      if 500 * i + 100 * j + 50 * k == X:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long


using namespace std;


int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int a, b, c;
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    if(a == b)
        cout << c;
    if(a == c)
        cout << b;
    if(b == c)
        cout << a;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256