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

//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define int long long
#define mod 1000000007
#define repr(i,x,y) for (__typeof(x) i=x;i>=y;i--)
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
int power(int a , int b)
{
    int res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % mod ;
        }
        b/=2 ;
        a = (a*a) % mod ;
    }
    return res ;
}

//debug
#define TRACE

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

int32_t main()
{
    fast;
    int q , h , s , d ; 
    cin >> q >> h >> s >> d ; 
    int n ; cin >> n ; 
    int one = min(4*q , min(2*h,s)) ;
    int two = min(min(d,2*s),min(4*h,8*q)) ; 
    int ans = (n/2) * two + (n & 1) * one ; 
    cout << ans << endl ; 
    return 0;
}


Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    a, b = gets.chomp.split.map(&:to_i)

    ab = a + b

    if 10 <= ab
      puts "error"
    else
      puts ab
    end

  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	int plus = 0, minus = 0, zero = 0;
	rep(i, 0, N) {
		if (0 < A[i]) plus++;
		else if (A[i] < 0) minus++;
		else zero++;
	}

	ll ans = 0;
	if (minus % 2 == 0) {
		rep(i, 0, N) ans += abs(A[i]);
	}
	else if (0 < zero) {
		rep(i, 0, N) ans += abs(A[i]);
	}
	else {
		int mi = inf;
		rep(i, 0, N) chmin(mi, abs(A[i]));
		rep(i, 0, N) ans += abs(A[i]);
		ans -= mi * 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
ll ans=0;
while(n--)
{
	ll x,y;
	cin>>x>>y;
	ans+=y-x+1;
}
ol(ans);
return 0;
}



Measured memory_bytes: 256
from collections import Counter
from itertools import combinations, starmap
func = lambda x, y, z: x*y*z

def main():
    with open(0) as f:
        N, *S = f.read().split()
    S = [s[0] for s in S if s[0] in list('MARCH')]
    S = Counter(S)
    ans = sum(starmap(func, combinations(S.values(), 3)))
    print(ans)

main()

Measured memory_bytes: 17164
#include <stdio.h> 
int main (void)    
{                  
    int H,A,s;     
    scanf("%d%d",&H,&A);
    s=H/A;         
    if(H%A>0)      
        s=s+1;     
    printf("%d\n",s);                                                
return 0 ;         
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
	int H, W;
	scanf("%d%d", &H, &W);

	char buf[105];
	
	for (int i = 0; i < H; ++i) {
		scanf("%s", buf);
		printf("%s\n%s\n", buf, buf);
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i =0 ; i<n; i++) a[i] = in.nextInt();
        Arrays.sort(a);
        out.println(a[a.length-1]-a[0]);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 33076
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	string S;
	cin >> S;
    bool flg = false;
    rep(i,int(S.size())-1) {
        if (S.substr(i, 2) == "AC") flg = true;
    }
    if (flg) cout << "Yes" << endl;
    else     cout << "No"  << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0;
  string S;
  cin >> S;
  
  for(int i=1; i<S.length(); i++){
    if(S[i]!=S[i-1]){
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int r, g;
	cin >> r >> g;
	cout << g * 2 - r << "\n";
}

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


Measured memory_bytes: 256
N=gets.to_i
sn=Math.sqrt(N)
h=Hash.new(0)
[*1..sn-1].repeated_combination(3).to_a.each do |x,y,z|
  r=x**2+y**2+z**2+x*y+y*z+z*x
  next if r > N
  l = case [x,y,z].uniq.size
  when 1
    1
  when 2
    3
  when 3
    6
  end
  h[r]+=l 
end
#p h
N.times do |i|
  p h[i+1]
end

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

int bit[200000], s, a[200000], b[200000], n;
void add(int k, int x) {
	while (k <= s) {
		bit[k] += x;
		k += k&-k;
	}
}
int sum(int k) {
	int res = 0;
	while (k > 0) {
		res += bit[k];
		k -= k&-k;
	}
	return res;
}
void compress() {
	sort(b, b + n);
	int t = unique(b, b + n) - b;
	rep(i, n)a[i] = lower_bound(b, b + t, a[i]) - b + 1;
	s = t + 1;
}
int main() {
	scanf("%d", &n);
	long long ans = 0;
	rep(i, n) {
		scanf("%d", &a[i]); b[i] = a[i];
	}
	compress();
	rep(i, n) {
		ans += i - sum(a[i]);
		add(a[i], 1);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5584
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import collections

while True:
    N,M = map(int,raw_input().split())
    if N == 0 and M == 0:
        break
    square_count_w = collections.defaultdict(int)
    square_count_h = collections.defaultdict(int)
    heights = []
    widths = []

    for i in range(N):
        height = int(raw_input())
        square_count_h[height] += 1
        sum_h = 0
        for h in heights[::-1]:
            sum_h += h
            square_count_h[height+sum_h] += 1
        heights.append(height)

    for i in range(M):
        width = int(raw_input())
        square_count_w[width] += 1
        sum_w = 0
        for w in widths[::-1]:
            sum_w += w
            square_count_w[width+sum_w] += 1
        widths.append(width)

    ans = 0
    for key,value in square_count_w.items():
        ans += square_count_w[key] * square_count_h[key]

    print(ans)

Measured memory_bytes: 90924
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  vector<int> A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];

  rep(i,N){
    A[i]--;B[i]--;
  }

  vector<ll> an(N,0),bn(N,0);
  rep(i,N) an[A[i]]++;
  rep(i,N) bn[B[i]]++;

  rep(i,N){
    if(an[i]+bn[i]>N){
      cout<<"No"<<endl;
      return 0;
    }
  }
  priority_queue<pair<int,int>> PQ;
  queue<int> Afree,Bfree;
  rep(i,N){
      if(an[i]&&bn[i]) PQ.push(mkp(an[i]+bn[i],i));
      else if(an[i]){
          for(int j=0;j<an[i];j++) Afree.push(i);
      }else if(bn[i]){
          for(int j=0;j<bn[i];j++) Bfree.push(i);
      }
  }

  vector<vector<int>> g(N);
  while(PQ.size()>=2){
      auto f=PQ.top();
      PQ.pop();
      auto s=PQ.top();
      PQ.pop();

      int ft=f.second;
      int st=s.second;
      g[ft].push_back(st);
      an[ft]--;
      bn[st]--;
      if(an[ft]) PQ.push(mkp(an[ft]+bn[ft],ft));
      else{
          rep(i,bn[ft]) Bfree.push(ft);
      }
      if(bn[st]) PQ.push(mkp(an[st]+bn[st],st));
      else{
          rep(i,an[st]) Afree.push(st);
      }
  }

  if(PQ.size()){
      auto f=PQ.top();
      PQ.pop();
      int ft=f.second;

      for(int i=0;i<an[ft];i++){
          int tar=Bfree.front();
          Bfree.pop();
          g[ft].push_back(tar);
      }
      for(int i=0;i<bn[ft];i++){
          int tar=Afree.front();
          Afree.pop();
          g[tar].push_back(ft);
      }
  }

  while(!Afree.empty()){
      int a=Afree.front();
      int b=Bfree.front();
      Afree.pop();
      Bfree.pop();
      g[a].push_back(b);
  }

  vector<int> ans(N);
  for(int i=0;i<N;i++){
      ans[i]=g[A[i]].back();
      g[A[i]].pop_back();
  }

  cout<<"Yes"<<endl;
  rep(i,N) cout<<ans[i]+1<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 21172
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n) cin >> a[i+1];
    //a[1]~a[n]
    int m=0;
    vi b(n+1, 0);

    for(int i=n;i>0;i--){
        int j = i * 2;
        int p = 1;
        
        if(a[i]==1) p*=-1; //もしaが1なら-1をかける

        while(j<=n){
            if(b[j]==1) p *= -1;
            j += i;
        }

        if(p == -1){
            b[i] = 1;
            m++;
        }
    }

    cout << m << endl;

    rrep(i, n){
        if(b[i] == 1) cout << i << endl;
    }



    return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>
#include<string.h>
unsigned long long m,a;
int main(){
  long long i,j,r,n,min,d[2][50]={0};
  char s[50],c[]={"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
  while(scanf("%lld %s",&n,s),n){
    j=n;
    m=0;
    for(i=r=0;i<40;i++)d[0][i]=0;
    min=2*1e18;
    for(i=2;i<=j;i++){
      if(j%i==0)r++;
      else continue;
      d[1][r]=i;
      while(j%i==0){
	j/=i;
	d[0][r]++;
      }
    }//printf("a\n");
    // for(i=1;i<=r;i++)printf("%lld %lld\n",d[1][i],d[0][i]);
    for(i=0;s[i];i++){
      m*=n;
      for(j=0;c[j]-s[i];j++);
      m+=j;
    }//printf("%lld\n",m);
    for(i=1;i<=r;i++){
      a=0;
      for(j=d[1][i];j<=m;j*=d[1][i])a+=m/j;
      a/=d[0][i];//printf("%lld %lld\n",i,a);
      if(min>a)min=a;
    }
  
  printf("%lld\n",min);
  }
  return 0;
}
      

Measured memory_bytes: 604
package main

import "fmt"

func str2num(x string) int {
    bx := []byte(x)
    var sum int = 0

    for i:=0; i<len(bx); i++ {
        sum += int(bx[i] - 0x30)
    }

    return sum
}

func main() {
    var x string

    for {
        fmt.Scanf("%s", &x)
        if x == "0" {
            break
        }

        fmt.Println(str2num(x))
    }
}


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

int main()
{

    int n;
    cin>>n;

    vector<ll>v;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }





    int ans=0;
    for(int i=0; i<v.size(); i++)
    {
        for(int j=i+1; j<v.size(); j++)
        {
            for(int k=j+1; k<v.size(); k++)
            {
                //cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<endl;
                //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;

                if(v[i]+v[j]>v[k]&&v[i]!=v[j]&&v[i]!=v[k]&&v[j]!=v[k]&&v[i]+v[k]>v[j]&&v[k]+v[j]>v[i])
                {
                    //cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<endl;
                    //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;



    return 0;
}


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

#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOUND(u, val) u.find(val) != u.end()

#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>
vector<vi> adj;
ll longest = 0;
vl distances;
vb visited;
void dfs(int vertex) {
    distances[vertex] = 1;
    for (int n : adj[vertex]) {
        if (!visited[n])
            dfs(n);
        distances[vertex] = max(distances[vertex], distances[n] + 1);
    }
    visited[vertex] = 1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    adj.resize(n + 1);
    distances.resize(n + 1);
    visited.resize(n + 1);
    for (int tr = 0; tr < m; tr++) {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
    }

    for (int i = 1; i <= n; i++) {
        if (visited[i]) continue;
        dfs(i);
    }
    ll answer = 0;
    for (int i = 1; i <= n; i++) {
        answer = max(distances[i], answer);
    }
    cout << answer - 1;
}


Measured memory_bytes: 12864
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int cnt = 0;
void bubbleSort(vector<int>&v) {
	bool flag = true;
	while (flag) {
		flag = false;
		rREP(j, 1, v.size()) {
			if (v[j] < v[j - 1]) {
				swap(v[j], v[j - 1]);
				cnt++;
				flag = true;
			}
		}
	}
}

int main() {
	init();

	int N; cin >> N;
	vector<int>vec(N);
	rep(i, 0, N)cin >> vec[i];
	bubbleSort(vec);
	rep(i, 0, N) {
		cout << vec[i];
		if (i == N - 1)cout << "\n";
		else cout << " ";
	}
	cout << cnt << "\n";

	return 0;
}


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

struct TCard
{
    char Suit;
    int  Num;
    bool operator==(const TCard& C)const
    {
        return Suit == C.Suit && Num == C.Num;
    }
    bool operator <(const TCard& C)const
    {
      return Num < C.Num;
    }
};
typedef std::vector<TCard> TList;

int partition(TList& A, int p, int r)
{
  int x = A[r].Num;
  int i = p - 1;
  for(int j = p; j < r; ++j){
    if(A[j].Num <= x){
      i = i + 1;
      std::swap(A[i],A[j]);
    }
  }
  std::swap(A[i+1],A[r]);
  return i+1;
}

void quickSort(TList& A, int p, int r)
{
  if(p < r){
    int q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}
TList Input()
{
    int Count;
    std::cin >> Count;
    TList List(Count);
    for(int i = 0; i < Count; ++i){
        std::cin >> List[i].Suit;
        std::cin >> List[i].Num;
    }
    return List;
}
void Output(const TList& List)
{
    TList::const_iterator It = List.begin();
    std::cout << It->Suit << " " << It->Num;
    for(++It; It != List.end(); ++It){
        std::cout << "\n" << It->Suit << " " << It->Num;
    }
    std::cout << std::endl;
}
void Check(const TList& List, const TList& Stable)
{
    if(std::equal(List.begin(), List.end(), Stable.begin())){
        std::cout << "Stable" << std::endl;
    }else{
        std::cout << "Not stable" << std::endl;
    }
}

int main()
{
    const TList List = Input();
    TList StableList = List;
    std::stable_sort(StableList.begin(), StableList.end());

    TList QuickList = List;
    quickSort(QuickList, 0, QuickList.size() - 1);
    Check(QuickList, StableList);
    Output(QuickList);
    return 0;
}

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

#define MX 205
#define MP 10000005
int x[MX];
vector<int> v;
vector<int> g[MX];
bool vis[MX];
int lnk[MX];
bool f[MP] = {1, 1};

int dfs(int u) {
	for(auto v : g[u]) {
		if(vis[v]) continue;
		vis[v] = true;
		if(lnk[v] < 0 || dfs(lnk[v])) {
			lnk[v] = u;
			return 1;
		}
	}
	return 0;
}

int main() {
	for(int i = 2; i < MP; i++) {
		if(f[i]) continue;
		for(int j = i + i; j < MP; j += i) f[j] = 1;
	} f[2] = 1;
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", x + i);
	for(int i = 0; i < n; i++) {
		if(x[i] + 1 != x[i + 1]) v.push_back(x[i]);
		if(!i || x[i] - 1 != x[i - 1]) v.push_back(x[i] - 1);
	}
	for(int i = 0; i < v.size(); i++)
		for(int j = 0; j < v.size(); j++)
			if(!f[abs(v[i] - v[j])]) g[i].push_back(j);
	int res = 0;
memset(lnk, 0xff, sizeof lnk);
	for(int i = 0; i < v.size(); i++) {
		if(v[i] & 1) continue;
		memset(vis, 0, sizeof vis);
		res += dfs(i);
	}
	int c[2] = {0};
	for(auto u : v) c[u & 1]++;
	c[0] -= res; c[1] -= res;
	res += c[0] / 2 * 2; res += c[1] / 2 * 2;
	c[0] &= 1; c[1] &= 1;
	if(c[0] || c[1]) res += 3;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;


string a,b,c;

char turn(int p)
{
	char ret,temp;
	switch(p)
	{
		case 0:
		if(a.length()==0)
			return 'A';
		temp=a[a.size()-1];
		a.pop_back();
		switch(temp)
		{
			case 'a':
			ret=turn(0);
			break;
			case 'b':
			ret=turn(1);
			break;
			case 'c':
			ret=turn(2);
			break;
		}
		break;
		case 1:
		if(b.length()==0)
			return 'B';
		temp=b[b.size()-1];
		b.pop_back();
		switch(temp)
		{
			case 'a':
			ret=turn(0);
			break;
			case 'b':
			ret=turn(1);
			break;
			case 'c':
			ret=turn(2);
			break;
		}
		break;
		case 2:
		if(c.length()==0)
			return 'C';
		temp=c[c.size()-1];
		c.pop_back();
		switch(temp)
		{
			case 'a':
			ret=turn(0);
			break;
			case 'b':
			ret=turn(1);
			break;
			case 'c':
			ret=turn(2);
			break;
		}
		break;
	}
	return ret;
}

int main()
{
	char ans;
	
	cin>>a;
	cin>>b;
	cin>>c;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	reverse(c.begin(),c.end());
	ans = turn(0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn dfs(yama: usize, a: &Vec<usize>, memo: &mut Vec<i32>) -> i32 {
    if yama == 0 {
        0
    } else if memo[yama] != -1 {
        memo[yama]
    } else {
        let mut res = false;
        for i in 0..a.len() {
            if yama >= a[i] && dfs(yama - a[i], &a, memo) == 0 {
                res = true;
                break;
            }
        }
        memo[yama] = res as i32;
        memo[yama]
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut memo: Vec<i32> = vec![-1; k + 1];
    if dfs(k, &a, &mut memo) == 1 {
        println!("First");
    } else {
        println!("Second");
    }
}


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

const int MAXN = 1e5 + 10;

long long n, a, b, val;
long long v[MAXN];

long long check (int md) {
	long long ret = 0;
	for (int i = 1; i <= n; i++) {
		if (v[i] - md * b > 0) {
			ret += (v[i] - md * b + a - 1) / a;
		}
	}
	return ret;
}

int main (void) {
	scanf("%lld%ld%lld", &n, &a, &b);
	a = a - b;
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &v[i]);
	}
	int st = 1, en = 1e9, md;
	while (st != en) {
		md = (st + en) >> 1;
		if (check(md) <= md) en = md;
		else st = md + 1;
	}
	printf("%d\n", st);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
vector <int> vec(100);
cin >> N;
for (int i=0; i<N; ++i){
    cin >> vec.at(i);
}
// 入力終わり
int sum_a=0, sum_b=0;
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());

for(int i=0; i<N; i+=2){
    sum_a+=vec.at(i);
}
for(int i=1; i<N; i+=2){
    sum_b+=vec.at(i);
}
cout << sum_a - sum_b << endl;

/*
for(int i=0; i<N+10; i++){
    cout << vec.at(i) << endl;
}
*/
}

Measured memory_bytes: 256
S = input()
T = input()
n = len(S)
chars1 = []
chars2 = []
pos1 = {}
pos2 = {}
for i in range(n):
    c1 = S[i]
    c2 = T[i]
    if c1 in pos1:
        chars1[pos1[c1]].append(i)
    else:
        pos1[c1] = len(chars1)
        chars1.append([i])

    if c2 in pos2:
        chars2[pos2[c2]].append(i)
    else:
        pos2[c2] = len(chars2)
        chars2.append([i])
print('Yes' if chars1 == chars2 else 'No')

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=998244353;
int n;
ll a[300005],fac[300005],inv[300005],hv[300005];
bool vis[300005];
vector<int> v;

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int main(){
	n=readint();
	fac[0]=inv[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%cys;
	inv[n]=qpow(fac[n],cys-2);
	for(int i=n-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;
	for(int i=1;i<=n;i++) a[i]=readint();
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		int cnt=0;
		for(int u=i;!vis[u];u=a[u]) cnt++,vis[u]=1;
		v.pb(cnt);
	}
	sort(v.begin(),v.end());
	if(v[0]>2) return printf("0\n"),0;
	if(v[0]==1){
		ll ans=1;
		for(int i=0;i<v.size();){
			int num=v[i],cr=0;
			while(v[i]==num) cr++,i++;
			if(num>1){
				ll tmp=0;
				for(int j=1;j<=cr;j++)
					tmp=(tmp+fac[cr-1]*inv[j-1]%cys*inv[cr-j]%cys*qpow(cr,cr-j)%cys*qpow(hv[num],j)%cys*qpow(num,cr-j))%cys;
				ans=ans*tmp%cys;
			}
			else ans=cr==1?1:qpow(cr,cr-2);
			for(int j=num<<1;j<=n;j+=num) hv[j]+=cr*num;
		}
		printf("%lld\n",ans);
	}
	else{
		ll ans=1;
		for(int i=0;i<v.size();){
			int num=v[i],cr=0;
			while(v[i]==num) cr++,i++;
			if(num>2){
				ll tmp=0;
				for(int j=1;j<=cr;j++)
					tmp=(tmp+fac[cr-1]*inv[j-1]%cys*inv[cr-j]%cys*qpow(cr,cr-j)%cys*qpow(hv[num],j)%cys*qpow(num,cr-j))%cys;
				ans=ans*tmp%cys;
			}
			else ans=qpow(cr,cr-1)*qpow(num,cr-1)%cys;
			for(int j=num<<1;j<=n;j+=num) hv[j]+=cr*num;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 13660
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			String x = scanner.next();
			int b = scanner.nextInt();

			if (x.equals("+"))
				System.out.println(a + b);
			else if (x.equals("-"))
				System.out.println(a - b);
			else if (x.equals("*"))
				System.out.println(a * b);
			else if (x.equals("/"))
				System.out.println(a / b);
			else if (x.equals("?"))
			        break;
		}
	}
}


Measured memory_bytes: 26396
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main() {
    int N;
    string S;
    int K;
    cin >> N;
    cin >> S;
    cin >> K;
    char s = S[K-1];
    for (int i = 0; i < N; i++) {
        if (S[i] != s) S[i] = '*';
    }
    cout << S << '\n';
}



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

typedef long long ll;
const int maxn=505;

int cnt[maxn];
int vis[maxn];
void init(){
    for(int i=2;i<=200;i++){
        for(int j=i+1;j<=200;j++){
            for(int k=j+1;k<=200;k++){
                int temp=i*j*k;
                if(temp%2==1&&temp<=200){
                    cout<<temp<<endl;
                }
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int a,b;
    while(cin>>a>>b){
        cout<<a*b-a-b+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
open System

let n, m, q =
    let l = Console.ReadLine().Split(' ') |> Array.map int
    l.[0], l.[1], l.[2]

let abcd =
    [ 1 .. q ]
    |> List.map (fun _ ->
        let l = Console.ReadLine().Split(' ') |> Array.map int
        l.[0], l.[1], l.[2], l.[3])

let ans =
    let total (arr: int []) =
        [ 0 .. q - 1 ]
        |> List.map (fun i ->
            let a, b, c, d = abcd.[i]
            if arr.[b - 1] - arr.[a - 1] = c then d else 0)
        |> List.sum

    let rec dfs (arr: int []) size =
        if size = n then
            total arr
        else
            let h =
                if size = 0 then 1 else arr.[size - 1]
            [ h .. m ]
            |> List.map (fun i ->
                arr.[size] <- i
                dfs (arr) (size + 1))
            |> List.max

    dfs (Array.init n (fun _ -> 0)) 0

ans |> printfn "%d"


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

using namespace std;
 
int main() {
  
  int k;
 
  while(cin>>k,k) {
	
    int sum = 0;
  
    for(int i = 0; i < k*(k-1)/2; i++) {

	  int c;
	  
      cin >> c;
      sum += c;
    }
 
    cout << sum/(k-1) << endl;
  }
 
  return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>
#include<unordered_map>


using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n, a[112];
	cin >> n;
	int mi = MOD, ma = 0;
	rep(i,n){
		cin >> a[i];
		mi = min(mi, a[i]);
		ma = max(ma, a[i]);
	}
	int ans = MOD;
	for (int i = mi; i <= ma;i++){
		int cnt = 0;
		for (int j = 0; j < n;j++){
			cnt += (a[j] - i) * (a[j] - i);
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#bitでタコ殴りにする
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_

m=998244353    
N,K=map(int,input().split())
bit = Bit(N)
bit.add(1,1)#初期値　はじめは１
period = []
for _ in range(K):#動ける区間の記憶
    l,r=map(int,input().split())
    period.append((l,r))
for i in range(2,N+1):#2からNまで見ていく。もらうDP
    for l,r in period:
        rx = max(0,i-l)
        lx = max(0,i-r-1)
        if rx==0:
            tmp_r = 0
        else:
            tmp_r = bit.sum(rx)
        if lx == 0:
            tmp_l = 0
        else:
            tmp_l = bit.sum(lx)
        bit.add(i,(tmp_r-tmp_l)%m)
ans = (bit.sum(N)-bit.sum(N-1))%m
print(ans)





Measured memory_bytes: 75860
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>

using namespace std;

int main(){
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)){
       cout<<"Yes"<<endl;
   }
   else cout<<"No"<<endl;
}

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

int main(){
	int n, k, p = 1;
	scanf("%d%d", &n, &k);
	for(int i = 0;i < n;i++){
		if(p < k)p *= 2;
		else p += k;
	}
	printf("%d\n", p);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//include <algorithm>
using namespace std;
int gcd( int a, int b ){
	if( b == 0 ){
		return a;
	}else{
		return gcd( b, a % b );
	}
}
int lcm( int a, int b ){
	return ( a / gcd( a, b ) ) * b;
}
int main(){
	int a, b;
	while( cin >> a >> b ){
		cout << gcd(a,b) << ' ' << lcm(a,b) << endl;
	}
}

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

// Union-Find
struct UnionFind {
    vector<int> par;
    vector<int> scale1;
    vector<int> rank;
    // par[i]はiの親の番号
    // scale[i]はiが親の時にのみ意味を持ち, その木の要素の数
    // rank[i]はiが親の時にのみ意味を持ち, その木のrank(union操作に使う)

    //最初は全てが根であるとして初期化
    UnionFind(int N) : par(N), scale1(N,1), rank(N,0){
        for(int i = 0; i < N; i++) par[i] = i;
    }

    // データxが属する木の根を再帰で得る
    int root(int x){
        if (par[x] == x) return x;
        par[x] = root(par[x]); // 親を根にする付け替えによって次回以降の参照を高速化
        return par[x];
    }

    // xとyの木を併合
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(rank[rx] > rank[ry]){
            par[ry] = rx;
            scale1[rx] += scale1[ry];
        }else if(rank[rx] < rank[ry]){
            par[rx] = ry;
            scale1[ry] += scale1[rx];
        }else{
            par[ry] = rx;
            scale1[rx] += scale1[ry];
            rank[rx]++;
        }
    }

    // 2つのデータx, yが属する木が同じならtrueを返す関数
    bool same(int x, int y){
        return root(x) == root(y);
    }

    // xの属する木の要素の数を返す関数
    int scale(int x){
        return scale1[root(x)];
    }
};


int main() {
    int N,M;
    cin >> N >> M;
    vector<int>A(M);
    vector<int>B(M);
    for (int i = 0; i < M; ++i) {
      cin >> A[i] >> B[i];
    }

    UnionFind tree(N);
    vector<ll>ans(M);
    ll temp = N;
    temp = (temp * (temp-1)) / 2; // このオーバーフローのせいで30分溶かした
    for(int i = M - 1; i >= 0; --i){
        ans[i] = temp;
        if(! tree.same(A[i]-1, B[i]-1)){
            ll aS = tree.scale(A[i]-1);
            ll bS = tree.scale(B[i]-1);
            temp = temp - aS * bS;
            tree.unite(A[i]-1, B[i]-1);
        }
    }

    for (int i = 0; i < M; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
S = input()
ans = ""
for i in range(len(S)):
    if 97<=ord(S[i])<=122:
        ans += chr(65+int(ord(S[i]))-97)
    elif 65<=ord(S[i])<=90:
        ans += chr(97+int(ord(S[i]))-65)
    else:
        ans += S[i]
print(ans)


Measured memory_bytes: 5560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
ll f(ll b,ll n){
    ll res = 0;
    while (n > 0){
        res += n%b;
        n /= b;
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,s;
    cin >> n >> s;
    if (n < s){
        PRINT(-1);
        return 0;
    }
    else if (n == s){
        PRINT(n+1);
        return 0;
    }
    ll k = n-s;
    vector<ll> ans;
    rep(i,1,sqrt(k)+1){
        if (k%i == 0){
            if (f(i+1,n) == s){
                ans.push_back(i+1);
            }
            if (f(k/i+1,n) == s){
                ans.push_back(k/i+1);
            }
        }
    }
    if (ans.empty()) PRINT(-1);
    else{
        SORT(ans);
        PRINT(ans[0]);
    }
}


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

int main() {
  int n, l;
  cin >> n >> l;
  string s[n], a;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  sort(s, s + n);

  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
mod = 10**9+7
S = int(input())
if S <= 2:
  print(0)
  exit()
A = [[0 for j in range(666)] for i in range(S-2)]
for i in range(S-2):
  A[i][0] = 1
  for j in range(1,i//3+1):
    A[i][j] = (A[i-1][j]+A[i-3][j-1])%mod
ans = 0
for j in range (666):
  ans += A[S-3][j]
  ans %= mod
print(ans)

Measured memory_bytes: 78324
n = int(input())
a = input()
b = a

while "()" in b:
    b = b.replace("()","")

left = b.count(")")
right = b.count("(")
l = []
r = []

for i in range(left):
    l.append("(")

for j in range(right):
    r.append(")")

ans = ["".join(l), a, "".join(r)]
print("".join(ans))

Measured memory_bytes: 3188
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[allow(dead_code)]
fn lcm(a: i64, b: i64) -> i64 {
    a*b / gcd(a, b)
}

use std::cmp;
fn main() {
    input! { n: usize, a: [i64;n] }

    let mut k =0;
    for i in 0..n {
        if i as i64 + 1 != a[i] { k+=1; }
    }
    if k > 2 { println!("NO"); } else { println!("YES"); }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;


ll H, W;
string s[444];
ll clr[444][444];

vector<P> g[444][444];

void dfs(ll c, ll x, ll y) {
  clr[x][y]=c;
  ll i;
  
  for(i=0; i<g[x][y].size(); i++) {
    P p=g[x][y][i];
    
    if(clr[p.first][p.second]!=-1) continue;
    dfs(c, p.first, p.second);
  }
  
}


int main(void) {
  cin >> H >> W;
  ll i, j;
  
  for(i=0; i<H; i++) {
    cin >> s[i];
    s[i]+='x';
  }
  s[H]=string(W+1, 'x');
  
  
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(s[i][j]!=s[i+1][j]) {
        g[i][j].push_back({i+1, j});
        g[i+1][j].push_back({i, j});
      }
      
      if(s[i][j]!=s[i][j+1]) {
        g[i][j].push_back({i, j+1});
        g[i][j+1].push_back({i, j});
      }
    }
  }
  
  memset(clr, -1, sizeof(clr));
  ll c=0;
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(clr[i][j]!=-1) continue;
      
      dfs(c, i, j);
      c++;
    }
  }
  
  ll bc[444*444]={};
  ll wc[444*444]={};
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(s[i][j]=='#') bc[clr[i][j]]++;
      if(s[i][j]=='.') wc[clr[i][j]]++;
    }
  }
  
  ll ans=0;
  for(i=0; i<444*444; i++) ans+=bc[i]*wc[i];
  
  pt(ans);
}






Measured memory_bytes: 29696
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }
    
    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask>>i&1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    string O, E;
    cin >> O;
    cin >> E;

    string Ans;
    int i;
    if(O.length() == E.length()){
        for(i = 0; i < O.length(); i++){
            Ans += O[i];
            Ans += E[i];
        }
    }
    else{
        for(i = 0; i < E.length(); i++){
            Ans += O[i];
            Ans += E[i];
        }
        Ans += O[i];
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[4];
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	if(a[1]==a[2]&&a[2]!=a[3])
		cout<<"Yes"<<endl;
	else if(a[2]==a[3]&&a[1]!=a[2])
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
	return 0;
}

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

int MAX = 510000;
long long modnum = 1e9 + 7;
std::vector< long long > fac(MAX);
std::vector< long long > finv(MAX);
std::vector< long long > inv(MAX);

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % modnum;
        inv[i] = modnum - inv[modnum%i] * (modnum / i) % modnum;
        finv[i] = finv[i - 1] * inv[i] % modnum;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % modnum) % modnum;
}

int main(){
    int N, K;
    std::cin >> N >> K;
    if(K > N - 1){
        K = N - 1;
    }
    
    COMinit();
    
    long long ans = 0;
    for(int i=1; i<=K; i++){
        long long tmp = COM(N, i);
        tmp = (tmp * COM(N-1, i)) % modnum;
        ans = (ans + tmp) % modnum;
    }
    if(K >= 2){
         ans++;
    }
    
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 12160