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

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<bool> same(n,false);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        if(i+1 == p[i]){same[i] = true;}
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(same[i]){ans++;i++;}
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int k;
	cin >> k;

	cout << (k / 2) * ((k + 1) / 2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> vec(0);
  while(N>=K) {
vec.push_back(N%K);
    N/=K;
  }
  vec.push_back(N);
 cout<<vec.size()<<endl;
}
  
  
  
  
  

  


Measured memory_bytes: 3496
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const int INF=1e6;
const ll int MOD=998244353;


//下i桁 桁和m modp で　t
main(){
    int n=in();
    ll ans=0;
    vecll a;rep(i,n*3)a.pb(in());
    sort(all(a));
    rep(i,n){
        ans+=a[n*3-2-2*i];
    }
    cout<<ans;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back



int main(){
    ll n;
    cin >> n;
    ll x=1;
    ll y=1000000000+7;
    for(int i=1;i<=n;i++){
        x=x*i%y;
    }

    
    cout << x << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 100

int main() {
	cout << fixed << setprecision(10);
	for (int D, E; cin >> D >> E&&D;) {
		double m = INF;
		for (int x = 0; x <= D; x++) {
			int y = D - x;
			m = min(abs(sqrt(x*x + y*y) - E), m);
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
import java.util.*;

public class Main{

	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int b[]=new int[n-1];
		for(int i=0;i<n-1;i++){
			b[i]=sc.nextInt();
		}
		long total=0;
		total+=b[0];

		for(int i=0;i<n-2;i++){
			total+=Math.min(b[i],b[i+1]);

		}
		total+=b[n-2];
		System.out.println(total);

	}
}


Measured memory_bytes: 21844
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	long long int ans = 1;
	for (int i = 1; i*i <= M; i++) {
		if (M%i)continue;
		if (M - (N*i) >= 0 && (M - N * i) % i == 0)ans = max((int)ans, i);
		if (M - (M / i)*N >= 0 && (M - N * (M / i)) % (M / i) == 0)ans = max(ans, M / i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int n, a = 0;
	cin >> n;
	string s = to_string(n);
	for (int i = 0; i < s.size(); i++)a += s[i] - '0';
	if (n%a)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


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

int main(){
  int n, m, i;
  vector<int> x[100005];
  cin >> n >> m;
  for(i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    --a; --b;
    x[a].push_back(b);
    x[b].push_back(a);
  }
  
  vector<int> t(n, -1);
  queue<int> q;
  vector<int> pre(n);
  pre[0] = -1;
  q.push(0);
  t[0] = 1;
  while(!q.empty()){
    int p = q.front();
    q.pop();
    for(int u : x[p]){
      if(t[u] == -1){
        q.push(u);
        pre[u] = p;
        t[u] = 1;
      }
    }
  }
  for(i = 1; i < n; i++){
    if(t[i] == -1){
      break;
    }
  }
  if(i != n){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
    for(int j = 1; j < n; j++){
      cout << pre[j]+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 10648
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static Scanner sc;

    public Main() {
    }

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

    private void solve() {
        int N = sc.nextInt();
        Arrays.fill(dp, -1);
        System.out.println(luca(N));
    }
    
    long[] dp = new long[90];
    private long luca(int n) {
        if (dp[n] != -1) {
            return dp[n];
        }
        
        if (n == 0) {
            return 2;
        }
        if (n == 1) {
            return 1;
        }
        
        return dp[n] = luca(n - 2) + luca(n - 1);
    }
}


Measured memory_bytes: 21072
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, x, y int
	fmt.Scan(&a, &b, &c, &x, &y)

	min := math.MaxInt32
	for i := 0; i <= max(x, y); i++ {
		p := a*max(0, x-i) + b*max(0, y-i) + c*2*i
		if p < min {
			min = p
		}
	}
	fmt.Println(min)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
antennas = []
for _ in range(5):
    antennas.append(int(input()))
k = int(input())
dist = 0

for a in range(5):
    for b in range(5):
        dist = max(dist, antennas[a]-antennas[b])

if dist <= k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int kohosha, wan;
		kohosha = scn.nextInt();	//候補者数
		wan = scn.nextInt();	//小石数
		while (kohosha != 0 || wan != 0) {
			int[] temoto = new int[kohosha];
			int turn = 0;
			while(true){
				if(wan == 0){
					wan = temoto[turn];
					temoto[turn] = 0;
				}else{
					temoto[turn]++;
					wan--;
				}
				if(wan == 0){
					boolean eflg = true;
					for(int i = 0; i < kohosha; i++) if(i != turn && temoto[i] != 0){eflg = false; break;}
					if(eflg) break;
				}
				turn = Math.min(turn + 1, (turn + 1) % kohosha);
			}
			System.out.println(turn);
			kohosha = scn.nextInt();
			wan = scn.nextInt();
		}
	}
}

Measured memory_bytes: 20284
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int main() {
	int A,B;
	int D[5001],E[5001];
	int R=0;
	cin>>A>>B;
	for(int i=0;i<A;i++)cin>>D[i];
	for(int i=0;i<B;i++)cin>>E[i];

	int S;
	int k;
	for(int i=0;i<B;i++){
		S=0;
		k=0;
		for(int j=0;j<A;j++){
			if(E[i+k]==D[j]){
				S+=1;
				k++;
			}
		}
		R=max(R,S);
	}

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

Measured memory_bytes: 3132
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
using namespace std;
const int mod = 1000000007;


int main() {
 
  int64_t a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a+b)>=d)cout<<min(a,d)<<endl;
  else cout<<a-(d-(a+b))<<endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_N 30000
class Dinic {
public:
  struct Edge { int to, cap, rev; };
  vector<Edge> G[MAX_N];
  int level[MAX_N], iter[MAX_N];

  void add_edge(int from, int to, int cap) {
    G[from].pb((Edge) { to, cap, (int)G[to].size() });
    G[to].pb((Edge) { from, 0, (int)G[from].size() - 1 });
  }

  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (int i=0; i<G[x].size(); i++) {
        Edge &e = G[x][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[x] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int x, int t, int f) {
    if (x == t) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      int f;
      while (true) {
        f = dfs(s, t, INF);
        if (f <= 0) break;
        flow += f;
        if (flow >= INF) return INF;
      }
    }
  }
};


int N, M;
char U[501];
int A[500];
Dinic dinic;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  cin >> U;
  rep(i, N) cin >> A[i];

  int S = N, T = N+1;
  rep(i, N) {
    if (U[i] == 'R') {
      dinic.add_edge(S, i, A[i]);
    }
    else {
      dinic.add_edge(i, T, A[i]);
    }
  }
  rep(i, M) {
    int s, t, b;
    cin >> s >> t >> b;
    s--, t--;
    if (s > t) swap(s, t);
    dinic.add_edge(s, t, b);
  }
  cout << dinic.max_flow(S, T) << "\n";
  return 0;
}



Measured memory_bytes: 4152
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();
        int sum = p+q+r;
        sum= (sum-p)<(sum-q)?(sum-p):(sum-q);
        sum= sum<(p+q)?sum:(p+q);
        System.out.println(sum);
            
        // 出力
       
    }
}


Measured memory_bytes: 21972
n = gets.to_i

w = []
while w1 = $stdin.gets do
  w << w1.chomp.split(" ")
end

sum = 0
w[0].each{|i| sum += i.to_i }

half_over = 0
index = 0
while half_over < sum/2
  half_over += w[0][index].to_i
  index += 1
end



half_less = half_over - w[0][index-1].to_i

if half_over - (sum - half_over)  > (sum - half_less) - half_less
  puts (sum - half_less) - half_less
else
  puts half_over - (sum - half_over)
end

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <set>
#include <list>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <bitset>
#include <array>
#include <stdlib.h>
#include <thread>
#include <chrono>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <fenv.h>
using namespace std;

int n;
long long a, b;
long long aa, bb;


int main()
{
    cin>>n;
    cin>>a>>b;
    for(int i=1; i<n; ++i)
    {
        cin>>aa>>bb;
        if(aa>=a && bb>=b)
        {
            a = aa;
            b = bb;
            continue;
        }
        long long ta = a%aa==0? a/aa:a/aa+1;
        long long tb = b%bb==0? b/bb:b/bb+1;
        a = aa*std::max(ta, tb);
        b = bb*std::max(ta, tb);
    }
    cout << a+b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main (void)
{
	long long n, i, ans;
	
	scanf("%lld",&n);
	ans=n-1;
	for (i=2; i*i<=n; i++) {
		if (n%i==0) {
			ans=min(ans,i+n/i-2);
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int a[1000000];
    for(int i = 0; i < 1000000; i++){
        a[i] = 0;
    }
    int a0;
    cin >> a0;
    a[a0] = 1;
    int tmp = a0;
    for(int i = 1; i < 1000000; i++){
        int next = 0;
        if(tmp%2 == 0){
            next = tmp/2;
        }else{
            next = 3*tmp + 1;
        }
        if(a[next] == 1){
            cout << i+1 << endl;
            return 0;
        }
        a[next] = 1;
        tmp = next;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
long MAX(long a,long b){
    return a>b?a:b;
}
int main(int argc, const char * argv[]) {
    char s[3001],t[3001];
    scanf("%s",s);
    scanf("%s",t);
    long ls=strlen(s),lt=strlen(t);
    long dp[ls+1][lt+1];
    for(int i=0;i<=ls;i++){
        for(int j=0;j<=lt;j++){
            dp[i][j]=0;
        }
    }
    for(long i=0;i<ls;i++){
        for(long j=0;j<lt;j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=MAX(dp[i][j]+1,dp[i+1][j+1]);
            }
            dp[i+1][j+1]=MAX(dp[i+1][j],dp[i+1][j+1]);
            dp[i+1][j+1]=MAX(dp[i][j+1],dp[i+1][j+1]);
        }
    }
    int arr[3001];
    for(int i=0;i<=3000;i++){
        arr[i]=-1;
    }
    long i=ls,j=lt,v=0;
    while (i>0&&j>0){
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }else if(dp[i][j]==dp[i][j-1]){
            j--;
        }else{
            arr[v]=s[i-1]-'a';
            i--;
            j--;
            v++;
        }
    }
    for(int i=v-1;i>=0;i--){
        printf("%c",arr[i]+'a');
    }
    return 0;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

struct Card {
    char mrk;
    int num;

    Card(char mrk,int num):mrk(mrk),num(num){}

    bool operator==(const Card &card) const {
        return mrk==card.mrk&&num==card.num;
    }
};

ostream& operator <<(ostream &os, const Card &c){
    return os<<c.mrk<<c.num;
}

vector<Card> bubbleSort(vector<Card> a,ll n){
    rep(i,n){
        rfore(j,i+1,n-1){
            if(a[j].num<a[j-1].num)swap(a[j],a[j-1]);
        }
    }
    return a;
}

vector<Card> selectionSort(vector<Card> a,ll n){
    rep(i,n){
        ll minj=i;
        fore(j,i,n-1){
            if(a[j].num<a[minj].num)minj=j;
        }
        if(minj!=i)swap(a[minj],a[i]);
    }
    return a;
}

void solve(){
    ll n;cin>>n;
    vector<Card> a;
    rep(i,n){
        string s;cin>>s;
        a.push_back(Card(s[0],s[1]-'0'));
    }
    vector<Card> b=bubbleSort(a,n);
    rep(i,n){
        if(i>0)cout<<" ";
        cout<<b[i];
    }
    cout<<endl;
    cout<<"Stable"<<endl;
    vector<Card> c=selectionSort(a,n);
    rep(i,n){
        if(i>0)cout<<" ";
        cout<<c[i];
    }
    cout<<endl;
    bool flg=1;
    rep(i,n)flg&=b[i]==c[i];
    cout<<(flg?"Stable":"Not stable")<<endl;
}

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


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

int main()
{
  int N,M;
  cin >> N >> M;
  int Freq[M+1];
  for(int i = 1; i < M+1;i++)
  {
    Freq[i] = 0;
  }
  int nomeals,crnt;
  for (int i = 0; i < N;i++)
  {
    cin >> nomeals;
    for(int j = 0; j < nomeals; j++)
    {
      cin >> crnt;
      Freq[crnt] ++;
    }
  }
  
  int count = 0;
  for(int  i = 1; i < M+1;i++)
  {
    if(Freq[i] == N)
      count ++;
  }
  
  cout << count;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace agc001_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(x);
            int a = x.Sum();
            for (int i = 1; i <= n; i++)
            {
                a -= x[i * 2 - 1];
            }
            Console.WriteLine(a);
        }
    }
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int memo[21][11][160];

int rec(int n,int k,int s){
	if(n<0||k<0||s<0)
		return 0;
	if(k==0&&s==0)
		return 1;
	int &res=memo[n][k][s];
	if(res!=-1) return res;
	res=0;
	res+=rec(n-1,k,s);
	res+=rec(n-1,k-1,s-n);
	return res;
}

int main(void){
	clr(memo,-1);
	int n,k,s;
	while(cin >> n >> k >> s){
		if(n==0)
			break;
		cout << rec(n,k,s) << endl;
	}
	return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=2010;

int n,k;
int a[N];
int f[N][2][10];
string s;

int dfs(int i,int o,int s){
    if(s>k) return 0;
    if(i>n) return s==k;
    int &ret=f[i][o][s]; if(ret>-1) return ret; ret=0;
    forinc(j,0,o?9:a[i]){
        ret+=dfs(i+1,o|(j<a[i]),s+(!!j));
    }
    return ret;
}

main(){
    #define task "TASK"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    fasty;

    reset(f,-1);
    cin>>s>>k; n=s.size();
    forinc(i,1,n) a[i]=s[i-1]-'0';

    cout<<dfs(1,0,0);
}


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

int main()
{
  string s,t,ans="";
  int n;
  cin >> n >> s>>t;
  rep(i,n){
    ans+=s[i];
    ans+=t[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3576
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int ans = a[2]*10 + a[1] + a[0];
		System.out.println(ans);
		sc.close();
	}
}


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

int main() {
	int h, w;
	cin >> h >> w;
	cout << string(w + 2, '#') << endl;
	string s;
	while (cin >> s)
		cout << '#' << s << '#' << endl;
	cout << string(w + 2, '#') << endl;
}


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

typedef long long ll;

ll f(ll b, ll n) {
	if (n < b) return n;
	return f(b, n / b) + n % b;
}

int main() {
	ios_base::sync_with_stdio(false);
	ll n, s; cin >> n >> s;
	if (n < s) return cout << -1 << '\n',0;
	if (n == s) return cout << n + 1 << '\n',0;
	ll res = n + 1; 
	for (ll i = 1; i * i <= n - s; ++i) {
		if ((n - s) % i == 0) {
			if (f(i + 1, n) == s) res = min(res, i + 1);
			if (f((n - s) / i + 1, n) == s) res = min(res, (n - s) / i + 1);
		}
	}
	if (res == n + 1) res = -1;
	cout << res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m, k, a;
    std::cin >> n >> m;
    int b = (1 << m) - 1;
    for (int i = 0; i < n; i++) {
        int t = 0;
        std::cin >> k;
        for (int j = 0; j < k; j++) {
            std::cin >> a;
            a--;
            t |= (1 << a);
        }
        b &= t;
    }
    std::cout << __builtin_popcount(b) << std::endl;

    return 0;
}


Measured memory_bytes: 256
def patty(n,x):
    if x == 0:
        return 0
    elif n == 0:
        #print(n,x,1)
        return 1
    elif x == 1 and n > 0:
        return 0
    num = 2 ** (n+2) - 3
    pre_num = 2 ** (n+1) - 3
    if x == num:
        #print(n,x,2 * patty(n-1,pre_num) + 1)
        return 2 * patty(n-1,pre_num) + 1
    elif x > pre_num + 1:
        #print(n,x,patty(n-1,pre_num) + 1 + patty(n-1,x - pre_num - 2))
        return patty(n-1,pre_num) + 1 + patty(n-1,x - pre_num - 2)
    elif x == pre_num + 1:
        #print(n,x,patty(n-1,pre_num) + 1)
        return patty(n-1,pre_num)
    else:
        #print(n,x,patty(n-1,x-1))
        return patty(n-1,x-1)

n, x = map(int,input().split())

print(patty(n,x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int h,w;
int cnt;
int main(){
	scanf("%d%d",&h,&w);
	for(int i = 1;i <= h;i++){
		getchar();
		for(int j = 1;j <= w;j++){
			char ch = getchar();
			if(ch == '#') cnt++;
		}
	}
	if(cnt == h + w - 1) printf("Possible");
	else printf("Impossible");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

vector<int> cand;

namespace isAcyclic {
    enum Status {
        New,
        Active,
        Finished
    };
    bool dfs(vector<vector<int>> &g, vector<Status> &used, int v) {
        used[v] = Active;
        cand.push_back(v);
        for (auto u: g[v]) {
            if (used[u] == Active) {
                cand.push_back(u);
                return false;
            }
            if (used[u] == New) {
                if (dfs(g, used, u) == false) return false;
            }
        }
        cand.pop_back();
        used[v] = Finished;
        return true;
    }
    bool check(vector<vector<int>> &g) {
        int n = g.size();
        vector<Status> used(n, New);
        for (int i = 0; i < n; ++i) {
            if (used[i] == New && dfs(g, used, i) == false) {
                return false;
            }
        }
        return true;
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }

    if (isAcyclic::check(g)) {
        cout << -1 << endl;
        return 0;
    }

    int s = cand.back(); cand.pop_back();
    vector<int> ci(n, -1);
    for (int i = 0; i < cand.size(); ++i) {
        ci[cand[i]] = i;
    }

    vector<int> ans;
    int cur = find(cand.begin(), cand.end(), s) - cand.begin();
    while (true) {
        ans.push_back(cur);
        int v = cand[cur];
        int dst = -1;
        int bdst = -1;
        for (auto u: g[v]) {
            if (ci[u] == -1) continue;
            if (ci[u] < cur) {
                if (binary_search(ans.begin(), ans.end(), ci[u])) {
                    bdst = max(bdst, ci[u]);
                }
            } else {
                dst = max(dst, ci[u]);
            }
        }
        if (bdst != -1) {
            auto it = lower_bound(ans.begin(), ans.end(), bdst);
            cout << ans.end() - it << endl;
            for (; it != ans.end(); ++it) {
                cout << cand[*it]+1 << endl;
            }
            return 0;
        }
        cur = dst;
    }

    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
#ABC127C
import sys

hoge = input().split()
n=int(hoge[0])
m=int(hoge[1])

l=[]
r=[]

for i in range(0,m):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	l.append(hoge[0])
	r.append(hoge[1])

maxl=l[0]
minr=r[0]
for i in range(1,m):
	maxl=max(maxl,l[i])
	minr=min(minr,r[i])

minr=min(minr,n)
if(minr<maxl):
	print(0)
else:
	print(minr-maxl+1)

Measured memory_bytes: 11048
n=int(input())
S1=input()
S2=input()
skip=False
p1,p2=False, False
dp=1
for i in range(n):
    if skip:
        skip=False
        continue
    elif S1[i]==S2[i]:
        if p1:
            dp*=2
        elif p2:
            p1=True
            p2=False
        else:
            p1=True
            dp*=3
    elif S1[i]==S1[i+1]:
        skip=True
        if p1:
            dp*=2
            p1=False
            p2=True
        elif p2:
            dp*=3
        else:
            p2=True
            dp*=6
else:
    print(dp%1000000007)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
typedef long long ll;
#define equ(a,b) ((fabs((a)-(b)))<(eps))
#define more(a,b) (((a)-(b))>(eps))
#define less(a,b) (((a)-(b))<(-eps))
#define inf 0x3f3f3f3f

int main(){
    char a;
    cin>>a;
    if(a-'a'>=0)cout<<'a';
    else cout<<'A';
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
using namespace std;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
int main() {
	int n;
	cin >> n;
	int k = n % 10;
	if (k == 3)
		cout << "bon" << endl;
	else if (k == 0 or k == 1 or k == 6 or k == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;
	return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");
		long[] A = new long[Ws.length];
		for (int i = 0; i < Ws.length; i++) {
			A[i] = Long.parseLong(Ws[i]);
		}
		int N = (int)A[0];
		int K = (int)A[1];

		W = in.readLine();
		Ws = W.split(" ");
		A = new long[Ws.length];
		double[] B = new double[(int)N];
		Arrays.fill(B,0);
		double ans = 0;
		double sum = 0;
		for (int i = 0; i < Ws.length; i++) {
			A[i] = Long.parseLong(Ws[i]);
			if(i >= K){
				sum-=A[i-K]*(A[i-K]+1)/(2.0*A[i-K]);
			}
			sum+=A[i]*(A[i]+1)/(2.0*A[i]);
			ans = Math.max(ans, sum);

		}


		System.out.printf("%.12f",ans);
	}
}


Measured memory_bytes: 49876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n; cin >> n;
	vl a(n), b(n), c(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	REP(i, n) cin >> c[i];
	sort(ALL(a));
	sort(ALL(b));
	sort(ALL(c));

	vl num(n);
	REP(i, n) {
		num[i] = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
	}
	vl num2(n);
	REP(i, n) {
		num2[i] = c.end() - upper_bound(c.begin(), c.end(), b[i]) ;
	}

	ll ans = 0;
	REP(i, n) ans += num[i] * num2[i];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    int A, B, C; cin >> A >> B >> C;
    int ans = max({A, B, C}) - min({A, B, C});

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


Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())

l = [input() for i in range(h)]
memo = [[-1]*w for i in range(h)]

black_cells = deque()
memo[0][0] = 0
black_cells.append((0, 0))
for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            memo[i][j] = -2

count = 0
while black_cells:
    nh, nw = black_cells.popleft()
    count = memo[nh][nw]
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        new_nh = nh + dy
        new_nw = nw + dx
        if new_nh < 0 or h <= new_nh or new_nw < 0 or w <= new_nw:
            continue
        if memo[new_nh][new_nw] == -1:
            memo[new_nh][new_nw] = count + 1
            black_cells.append((new_nh, new_nw))
        if new_nh == h-1 and new_nw == w-1:
            count += 1
            break
    if new_nh == h-1 and new_nw == w-1:
        break

if new_nh == h-1 and new_nw == w-1:
    sc = 0
    for i in l:
        sc += i.count("#")
    print(h*w-sc - count - 1)
else:
    print(-1)


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    cout << max(a + b, max(2 * a - 1, 2 * b - 1)) << '\n';
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;

void solve()
{	
	int n; cin >> n;
	vector<int> a(n);
	map<int,ll> m;
	rep(i, n) {cin >> a[i];m[a[i]]++;}
	ll sum = 0;
	for(auto e:m)sum += e.second*(e.second-1)/2;
	rep(i, n)
	{
		int n = m[a[i]];
		ll ans = sum -(n-1);
		cout << ans << endl;
	}
	return;
}

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


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long;
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b==c+d){
		cout<<"Balanced\n";
	}else if(a+b>c+d){
		cout<<"Left\n";
	}else{
		cout<<"Right\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define RALL(a) (a).rbegin(), (a).rend()
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int modpow(int a, int n, int mod) {
    int hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
ll n, a[200005], r, rr, ans=INF;
/*signed*/int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        r += a[i];
    }
    for (int i = 0; i < n - 1; i++){
        rr += a[i];
        if (abs(rr - (r - rr)) < ans) ans = abs(rr - (r - rr));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5172
#include <iostream>
using namespace std;
int main(){
  char c;
  cin >> c;
  if(c == 'A') cout << 'T' << endl;
  else if(c == 'T') cout << 'A' << endl;
  else if(c == 'C') cout << 'G' << endl;
  else cout << 'C' << endl;
}

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

using namespace std;

const int N = 2e5 + 5;
const int mod = 998244353;
inline int pls( int a , int b ) { a += b - mod; return a + ( a >> 31 & mod ); }
inline int mns( int a , int b ) { a -= b; return a + ( a >> 31 & mod ); }
inline void inc( int & a , int b ) { a += b - mod; a += a >> 31 & mod; }
inline void dec( int & a , int b ) { a -= b; a += a >> 31 & mod; }
int _w;

int n , f[N];
char str[N] , tmp[N];
bool mark[N];

int solve( int k ) {
  int res = 0;
  for( int i = 1 ; i <= k ; ++i )
    inc( res , pls( res , str[i] - '0' ) );
  for( int i = 1 , cur = 1 ; i <= n ; ++i , cur = cur >= 2 * k ? 1 : cur + 1 ) 
    if( cur > k ) tmp[i] = str[cur - k] ^ 1;
    else tmp[i] = str[cur];
  for( int i = 1 ; i <= n ; ++i )
    if( tmp[i] ^ str[i] )
      return tmp[i] < str[i] ? pls( res , 1 ) : res;
  return pls( res , 1 );
}

int main( void ) {
  _w = scanf("%d%s",&n,str+1);
  for( int i = 1 ; i <= n ; ++i )
    if( n % i == 0 && ( ( n / i ) & 1 ) )
      f[i] = solve( i ) , mark[i] = 1;
  for( int i = 1 ; i <= n ; ++i ) if( mark[i] ) 
    for( int j = i + i ; j <= n ; j += i ) if( mark[j] )
      dec( f[j] , f[i] );
  int ans = 0;
  for( int i = 1 ; i <= n ; ++i )
    if( mark[i] )
      inc( ans , 2LL * i * f[i] % mod );
  cout << ans;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, unsigned int> shcd;
  vector<string> cardtype{"S", "H", "C", "D"};
  for (int i = 0; i < 4; i++) {
    shcd[cardtype[i]] = ((1 << 13) - 1);
  }

  string type;
  int num;
  for (int i = 0; i < n; i++) {
    cin >> type >> num;
    shcd[type] &= ~(1 << (num - 1));
  }

  for (int i = 0; i < cardtype.size(); i++) {
    for (int j = 0; j < 13; j++) {
      if (shcd[cardtype[i]] & (1 << j)) {
        cout << cardtype[i] << " " << (j + 1) << endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3148
class Combination:
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv


if __name__ == "__main__":
    N, M, K = map(int, input().split())
    MOD = 998244353
    ans = 0
    comb = Combination(1000000, MOD)

    for i in range(K+1):
        ans += M * pow(M-1, N-i-1, MOD) * comb(N-1, i)
        ans %= MOD

    print(ans)



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

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;

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

#define SPRE(x) setprecision(x) // 精度を指定

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	int h,w,n;
	cin >> h >> w >> n;
	vector<vector<int>> c(h,vector<int>(w));
	int i,j;
	i = j = 0;
	bool lef = 0;

	for (int k = 1; k <= n; k++) {
		int tmp;
		cin >> tmp;
		while(tmp > 0){
			if(j < w && j >= 0){
				c[i][j] = k;
				j += 1 + (-2*lef);
				tmp--;
			}
			else {
				i++;
				if(j >= w)
					j = w-1;
				else
					j = 0;
				lef = !lef;
			}
		}
	}
	for (auto&& t : c) {
		for (auto&& o : t) {
			cout << o << ' ';
		}
		cout << '\n';
	}
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;

int main(){
    ll n,m,d;cin>>n>>m>>d;
    ll ans=0;
    if(d<=n){
        if(d==0) ans=n;
        else if(2*d<=n) ans=d+2*(n-2*d)+d;
        else ans=2*(n-d);
    }
    else{
        cout<<0<<endl;
        return 0;
    }
    double res=ans*(m-1)/double(n*n);
    printf("%.16f\n",res);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    int i;
    int a, min=1000000, max=-1000000;
    long int sum=0;
    scanf("%d", &n);
    //input
    for(i=0; i<n; i++){
        scanf("%d", &a);
        sum += a;
        if(min>a){
            min = a;
        }
        if(max<a){
            max= a;
        }
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>


using namespace std;

const int mod = 1000000007;


int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(),s.end());

  vector<vector<int>> dp(n+1, vector<int>(13,0));
  int digit=1;
  dp[0][0] = 1;
  for(int i=0; i<n; i++) {

    // 未確定のとき
    if(s[i] == '?') {
      for(int d=0; d<10; d++) {
        for(int j=0; j<13; j++) {
          dp[i+1][(d*digit + j)%13] += dp[i][j];
          dp[i+1][(d*digit + j)%13] %= mod;
        }
      }
    } 
    // 確定しているとき
    else {
        int d = (s[i] - '0'); // 数値に変換
        for(int j=0; j<13; j++) {
          dp[i+1][(d*digit + j)%13] += dp[i][j];
          dp[i+1][(d*digit + j)%13] %= mod;
        }
    }

    // DPテーブル出力
    // for (int i=0; i<=n; i++) {
    //   for (int j=0; j<13; j++) {
    //     cout << dp[i][j] << " ";
    //   }
    //   cout << endl;
    // }
    // cout << endl;

    digit *= 10;
    digit %= 13;
  }

  cout << dp[n][5] << endl;
}

Measured memory_bytes: 8896
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,k;cin>>n>>k;
	vector<ll> a(n);
	vector<ll> f(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	for(int i = 0; i < n; i++) {
		cin>>f[i];
	}
	sort(ALL(a));
	sort(ALL(f),greater<ll>());
	ll r = 1LL << 60;
	ll l = -1LL;
	//二分探索(目指す最大値の値を達成するために必要な修行の回数を探索)
	while(r - l > 1){
		ll tmp = 0LL;
		ll mid = ((l + r)/2LL);
		for(int i = 0; i < n; i++) {
			tmp += max(0LL,a[i] - mid/f[i]);
		}
		if (tmp <= k){//もっと最大値を小さくできそうな時(修行の回数が余った時)
			r = mid;
		}
		else{//縛りをゆるくする
			l = mid;
		}
	}
	cout << r << endl;
	

	return 0;
}

Measured memory_bytes: 3328
def main():
    N = int(input())
    S = input()
    cnt = 0
    pre = 0
    for i in range(len(S)):
        if S[i] == '(':
            cnt += 1
        else:
            cnt -= 1
            if cnt < 0:
                pre = max(pre, -cnt)
    
    ans = "(" * pre + S
    cnt = 0
    for j in range(len(ans)):
        if ans[j] == '(':
            cnt += 1
        else:
            cnt -= 1

    print(ans + ')' * cnt)

main()

Measured memory_bytes: 38384
//i am too vegetable so i kuaied somebody's code in the Internet. just for this problem.
#include<cstdio>
#include<cstring>
using namespace std;
const int w=20003;
char s[10005];
int x,y,_x,len,p,sum,q,now=1;
bool ws[2][2][40009];
int main(){
    register int i;
    scanf("%s%d%d",s+1,&x,&y),len=strlen(s+1),x+=w,y+=w;
    while(now<=len&&s[now]=='F')++now,++_x;
    ws[0][0][w+_x]=1,ws[1][0][w]=1;
    while(now<=len){
        ++now,sum=0,p^=1,q^=p;
        while(now<=len&&s[now]=='F')++sum,++now;
        for(int i=w-len;i<=w+len;++i)
            ws[p][q][i]=ws[p][q^1][i+sum]|ws[p][q^1][i-sum];
    }
    if(p==1&&ws[0][q^1][x]&&ws[1][q][y]||p==0&&ws[0][q][x]&&ws[1][q][y])puts("Yes");
    else puts("No"); 
    return 0;
}

Measured memory_bytes: 256
S = input()
result = ['0']*len(S)
odd = 0
even = 0
for i, s in enumerate(S):
    if i%2:
        odd += 1
    else:
        even += 1
    if i == len(S)-1:
        result[oddindex] = str(odd)
        result[evenindex] = str(even)
    else:
        next = S[i+1]
        if s=='R' and next=='L':
            if i%2:
                oddindex = i
                evenindex = i+1
            else:
                oddindex = i+1
                evenindex = i

        elif s=='L' and next=='R':
            result[oddindex] = str(odd)
            result[evenindex] = str(even)
            odd = 0
            even = 0

print(' '.join(result))


Measured memory_bytes: 10100