akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#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)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
double dp[330][330][330];
int cnt[4];
int main(){
    int n;cin >> n;
    rep(i,n){
        int a;cin >> a;
        cnt[a]++;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                int nonzero=i+j+k;
                if(nonzero==0){
                    dp[i][j][k]=0;
                    continue;
                }
                dp[i][j][k]=(double)n/nonzero;
                if(i-1>=0) dp[i][j][k]+=dp[i-1][j+1][k]*i/nonzero;
                if(j-1>=0) dp[i][j][k]+=dp[i][j-1][k+1]*j/nonzero;
                if(k-1>=0) dp[i][j][k]+=dp[i][j][k-1]*k/nonzero;
            }
        }
    }
    cout << fixed << setprecision(10);
    cout << dp[cnt[3]][cnt[2]][cnt[1]] << endl;
    return 0;
}

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/


int main()
{
    ll n;
    cin >> n;
    string ans;
    while(1)
    {

        if(n <= 0) break;
        n-=1;
        ll x=n%26;
        char c= 'a'+x;
        ans.pb(c);
        n/=26;
    }
    reverse(all(ans));
    cout << ans;
}


Measured memory_bytes: 3624
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		System.out.println(S / 3600 + ":" + (S / 60) % 60 + ":" + S % 60);
	}
}


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

int main(){
  int N;
  
  cin>>N;
  int A[2*N];
  for(int i=0;i<2*N;i++){
    cin>>A[i];
  }
  for(int j=0;j<2*N;j++)
    for(int i=0;i<2*N-1;i++)
      if(A[i]>A[i+1]){
	int x = A[i];
	A[i]=A[i+1];
	A[i+1]=x;
      }
  int ans=0; 
 for(int i=0;i<2*N;i+=2){
   ans+=A[i];
 }

 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 256
/*
 * @Author: Kaustav Vats  
 */
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;


class Main {

    public static void PrintIntArray(int[] Arr) {
        for (int i=0; i<Arr.length; i++) {
            System.out.print(Arr[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) throws IOException{
        Reader.init(System.in);
        int N = Reader.nextInt();
        int[][] Arr = new int[2][N];
        for (int i=0; i<N; i++) {
            Arr[0][i] = Reader.nextInt();
            Arr[1][i] = Arr[0][i];
        }
        int count = 0;
        Arrays.sort(Arr[1]);
        for (int i=0; i<N; i++) {
            if (Arr[0][i] != Arr[1][i]) {
                count++;
            }
        }
        if (count == 0 || count == 2) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
}


/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

Measured memory_bytes: 21332
from fractions import gcd
N, M = map(int, input().split())
S = list(map(int, input().split()))

temp = S[0]
cnt = 0
while temp%2 == 0:
    temp //= 2
    cnt += 1
temp = S[0]
for i in range(1, N):
    temp = temp*S[i]//gcd(temp, S[i])
    if S[i]%(2**cnt) == 1 or (S[i]//(2**cnt))%2 == 0:
        print(0)
        break
else:      
    if temp//2 > M:
        print(0)
    else:
        print((M-temp//2)//temp+1)

Measured memory_bytes: 16296
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll b[2001][2001],w[2001][2001];
int main(){
    ll n,k;
    cin>>n>>k;
    ll xi,yi,cntb=0,cntw=0;
    char ci;
    ll k2=k*2;
    rep(i,n){
        cin>>xi>>yi>>ci;
        if(ci=='B'){
            ++b[xi%k2+1][yi%k2+1];++cntb;
        }
        else ++w[xi%k2+1][yi%k2+1],++cntw;
    }
    
    rep(i,2*k)rep(j,2*k){
        b[i+1][j+1]+=b[i][j+1]+b[i+1][j]-b[i][j];
        w[i+1][j+1]+=w[i][j+1]+w[i+1][j]-w[i][j];
    }
    
    ll mx=0;
    FOR(mod1,0,k+1)FOR(mod2,0,k+1){
        ll cnt=0,cnt2=0;
            cnt+=b[mod1+k][mod2+k]-b[mod1+k][mod2]-b[mod1][mod2+k]+b[mod1][mod2];
            cnt+=b[k2][k2]-b[k2][mod2+k]-b[mod1+k][k2]+b[mod1+k][mod2+k];
            cnt+=b[mod1][mod2]-b[0][mod2]-b[mod1][0]+b[0][0];
            cnt+=b[k2][mod2]-b[mod1+k][mod2]-b[k2][0]+b[mod1+k][0];
            cnt+=b[mod1][k2]-b[mod1][mod2+k]-b[0][k2]+b[0][mod2+k];
            cnt2+=w[mod1+k][mod2+k]-w[mod1+k][mod2]-w[mod1][mod2+k]+w[mod1][mod2];
            cnt2+=w[k2][k2]-w[k2][mod2+k]-w[mod1+k][k2]+w[mod1+k][mod2+k];
            cnt2+=w[mod1][mod2]-w[0][mod2]-w[mod1][0]+w[0][0];
            cnt2+=w[k2][mod2]-w[mod1+k][mod2]-w[k2][0]+w[mod1+k][0];
            cnt2+=w[mod1][k2]-w[mod1][mod2+k]-w[0][k2]+w[0][mod2+k];
            cnt=max(cnt+cntw-cnt2,cntb-cnt+cnt2);
        mx=max(cnt,mx);
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 62848
#include<iostream>
#include<cmath>
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";
  else
    cout << "No";
  return 0;
}


Measured memory_bytes: 256
N = int(input())
L = []
c = N
for i in range(64):
  d = c%2
  L.append(d)
  if i%2 == 0:
    c = (c-d)//2
  else:
    c = (c+d)//2
L = list(reversed(L))
try:
  i = L.index(1)
  L = L[i:]
  s = "".join(map(str, L))
  print(s)
except:
  print("0")


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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] += 'a' - 'A';
    cout << s << endl;
}

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

/* BIT */
template <class Abel> struct BIT {
    vector<Abel> dat;
    Abel UNITY_SUM = 0;						// to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) {
        dat.resize(n + 1);
        for (int i = 0; i < (int)dat.size(); ++i) dat[i] = UNITY_SUM;
    }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
};

int main() {
    /* 入力 */
    int N, K;
    long long L;
    cin >> N >> K >> L;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    
    /* 二分探索 */
    int low = 0, high = N;
    while (high - low > 1) {
        /* mid 以下の値が L 個あるかを判定する */
        int mid = low + (high - low) / 2;
        
        /* しゃくとり法で、mid 以下の値が K 個以上あるような区間を数え上げる */
        BIT<int> bit(N+1);
        int right = 0;
        long long num = 0;
        for (int left = 0; left < N; ++left) {
            while (right < N && bit.sum(mid) < K) {
                bit.add(a[right], 1);
                ++right;
            }
            if (bit.sum(mid) < K) break;
            num += N - right + 1;
            bit.add(a[left], -1);
        }
        
        if (num >= L) high = mid;
        else low = mid;
    }
    
    cout << high << endl;
}


Measured memory_bytes: 4392
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll n;
    cin>>n;
    lvec a(n);
    rep(i,n) cin>>a[i];
    lvec gcdl(n+1,0),gcdr(n+1,0);
    for(int i=0;i<n;i++) gcdl[i+1]=__gcd(gcdl[i],a[i]);
    for(int i=n;i>0;i--) gcdr[i-1]=__gcd(gcdr[i],a[i-1]);
    ll ans=0;
    for(int i=0;i<n;i++){
        ll cnt;
        cnt=__gcd(gcdl[i],gcdr[i+1]);
        if(cnt>ans) ans=cnt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
n,m = gets.split.map(&:to_i)
k = []
for i in 0..m-1
k[i] = gets.split.map(&:to_i)
end
k.sort!
for j in 1..n
  cnt = 0
  for i in 0..m-1
  if k[i].include?(j)
    cnt += 1
  end
  end
  puts cnt
end

Measured memory_bytes: 3836
#include<stdio.h>

int main()
{
	int a[100];
	int b[100];
	int min = 101;
	int x = 0;
	int i,n;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		x += a[i];
		if (a[i] % 10 != 0 && min > a[i]) {
			min = a[i];
		}
	}
	if (x % 10 != 0) {
		printf("%d", x);
	}
	else {
if(min==101){
printf("0");
}else{
		printf("%d", x - min);
	}}
	
    return 0;
}

Measured memory_bytes: 128
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

g = reduce(gcd, A)
if K % g == 0:
    flag = True
else:
    flag = False
if max(A) < K:
    flag = False    

print('POSSIBLE' if flag else 'IMPOSSIBLE')


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

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

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

  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=n1;i<(int)(n2);i++)
using namespace std;

signed main()
{
  string S;
  cin >> S;
  string T;
  cin >> T;

  int N;
  N = S.length();

  int count = 0;
  Rep(i, N){
	  if(S[i] == T[i]) count++;
  }

  cout << count;
  return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn=1e5+10;
ll g[maxn],n,c,x[maxn],v[maxn],ans,s[maxn],q[maxn],mx1,mx2,y[maxn],f[maxn];

int main(){
	scanf("%lld%lld",&n,&c);

	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&x[i],&v[i]);
		s[i]=s[i-1]+v[i];
		y[n-i+1]=c-x[i];	
	}
	for(int i=1;i<=n;i++)
		q[i]=q[i-1]+v[n-i+1];
	for(int i=1;i<=n;i++){
		mx1=max(mx1,s[i]-x[i]);
		mx2=max(mx2,q[i]-y[i]);
		f[i]=mx1,g[i]=mx2;
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,f[i]);
		ans=max(ans,g[i]);
		ans=max(f[i]-x[i]+g[n-i],ans);
		ans=max(g[i]-y[i]+f[n-i],ans);	
	}
//	for(int i=1;i<=n;i++) printf("%lld %lld\n",f[i],g[i]);
	printf("%lld",ans);
	return 0;	
//	system("pause");
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int x[3];

int main(){
    int a, b;
    cin >> a >> b;
    if((a*b)%2 != 0)
        cout << "Yes";
    else 
        cout << "No";
    
}
	


Measured memory_bytes: 256
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
q = int(input())
rl = [map(int, input().split()) for _ in range(q)]

li = get_sieve_of_eratosthenes(10**5+1)
pli = [False] * (10**5+1)

for i in li:
  pli[i] = True

# print(pli)
  
# print(li)
cpli = [0] * (10**5+1)

cnt = 0
for i in range(10**5+1):
  if i % 2 == 1 and pli[i] and pli[(i + 1) // 2]:
    cnt += 1
  cpli[i] = cnt

# print(cpli)
  
for l, r in rl:
  print(cpli[r] - cpli[l-1])


Measured memory_bytes: 52836
#include<iostream>

using namespace std;

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int comb = 0;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if ((i * 500) + (j * 100) + (k * 50) == x)comb++;
			}
		}
	}
	cout << comb << endl;

	return 0;
}

Measured memory_bytes: 256
def intinput():
    return map(int,input().split())

n,m=intinput()
a = [[0,0] for _ in range(n)]
for i in range(n):
    a[i] = list(intinput())
a.sort()
i=0
f=0
while m>0:
    if m>=a[i][1]:
        m -= a[i][1]
        f += a[i][1]*a[i][0]
    else:
        f += a[i][0]*m
        m=0
    i+=1
print(f)

Measured memory_bytes: 27820
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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; }

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    int n;
    cin >> n;
    ll t[n+1];

    lset(t,0);
    for(int j = 2;j <= n;j++){
        int num = j;
        for(int i = 2;i <= j;i++){
            while(num%i == 0){
                t[i]++;
                t[i]%=mod;
                num/=i;
            }
        }
    }
    ll ans = 1;
   rep(i,n+1){
       ans =(ans * (t[i]+1)%mod);
   }
    
    pri(ans);



    
    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        for(int i = 0; i < n; i++) {
            int[] a = new int[31];
            for(int j = 1; j < 31; j++) {
                a[j] = stdIn.nextInt();
            }
            System.out.println(solv(a,0));
        }
    }
     
    static int solv(int[] ck, int count) {
        if(check(ck)) {
            return count;
        }
        if(count >= 9) return 99;
        int max = 20;
        int[] a = ck;
        int[] b = new int[a.length];
        for(int i = 0; i < a.length; i++) {
            b[i] = a[i];
        }
        swap(a,1,28);
        swap(a,2,29);
        swap(a,3,30);
        swap(a,15,16);
        swap(a,21,19);
        max = Math.min(solv(a,count+1),max);
        for(int i = 0; i < a.length; i++) {
            a[i] = b[i];
        }
        swap(a,7,22);
        swap(a,8,23);
        swap(a,9,24);
        swap(a,13,18);
        swap(a,10,12);
        max = Math.min(solv(a,count+1),max);
        for(int i = 0; i < a.length; i++) {
            a[i] = b[i];
        }
        swap(a,1,24);
        swap(a,4,27);
        swap(a,7,30);
        swap(a,16,18);
        swap(a,10,21);
        max = Math.min(solv(a,count+1),max);
        for(int i = 0; i < a.length; i++) {
            a[i] = b[i];
        }
        swap(a,3,22);
        swap(a,6,25);
        swap(a,9,28);
        swap(a,12,19);
        swap(a,13,15);
        max = Math.min(solv(a,count+1),max);
         
        return max;
    }
     
    static void swap(int[] a, int f, int t) {
        int tmp = a[f];
        a[f] = a[t];
        a[t] = tmp;
    }
     
    static boolean check(int[] a) {
        int b = a[1];
        for(int i = 1; i < 10; i++) {
            if(b != a[i]) {
                return false;
            }
        }
        b = a[22];
        for(int i = 23; i < 31; i++) {
            if(b != a[i]) {
                return false;
            }
        }
        if(a[10] != a[12]) return false;
        if(a[13] != a[15]) return false;
        if(a[18] != a[16]) return false;
        if(a[21] != a[19]) return false;
        if(a[14] != a[15]) return false;
        if(a[11] != a[12]) return false;
        if(a[17] != a[18]) return false;
        if(a[21] != a[20]) return false;
         
        return true;
    }
}

Measured memory_bytes: 154320
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int asort(const void *a, const void *b) {
  ll x = *(ll *)a, y = *(ll *)b;
  if (x > y) return 1;
  if (x < y) return -1;
  return 0;
}

int
main(int argc, char *argv[])
{
  int n; double a[100];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lf", &a[i]);

  double x = 0;
  for (int i = 0; i < n; i++) {
    x += 1.0 / a[i];
  }

  printf("%lf\n", 1.0 / x);

  return 0;
}


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

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> p(n); REP(i, n) cin >> p[i];
  int ans = 0;
  FOR(i, 1, n - 1) {
    vector<int> tmp{p[i - 1], p[i], p[i + 1]};
    sort(ALL(tmp));
    if (tmp[1] == p[i]) ++ans;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>

ld gs_search(function<ld(ld)> f, ld l, ld r, ld prec)
{
    ld g, lm, rm, flm, frm;
    g = (sqrt(5) - 1.0) / 2.0;
    lm = l + (1 - g) * (r - l);
    rm = l + g * (r - l);
    flm = f(lm);
    frm = f(rm);
    while (fabs(r - l) > prec)
    {
        if (flm > frm)
        {
            l = lm;
            lm = rm, flm = frm;
            rm = l + g * (r - l), frm = f(rm);
        }
        else
        {
            r = rm;
            rm = lm, frm = flm;
            lm = l + (1 - g) * (r - l), flm = f(lm);
        }
    }
    return (l + r) / 2;
}

typedef struct _P
{
    ld x, y;
    char d;
    _P() {}
    _P(ld _x, ld _y, char _d) : x(_x), y(_y), d(_d){};
} P;
int n;
vector<P> p;
P move_point(P x, ld t)
{
    if (x.d == 'U')
        return P(x.x, x.y + t, x.d);
    else if (x.d == 'D')
        return P(x.x, x.y - t, x.d);
    else if (x.d == 'L')
        return P(x.x - t, x.y, x.d);
    else if (x.d == 'R')
        return P(x.x + t, x.y, x.d);
}
ld func(ld t)
{
    ld xmin = 1e18, xmax = -1e18, ymin = 1e18, ymax = -1e18;
    forn(i, n)
    {
        P y = move_point(p[i], t);
        xmin = min(xmin, y.x), xmax = max(xmax, y.x);
        ymin = min(ymin, y.y), ymax = max(ymax, y.y);
    }
    return (xmax - xmin) * (ymax - ymin);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    p = vector<P>(n);
    forn(i, n) cin >> p[i].x >> p[i].y >> p[i].d;
    ld res = gs_search(func, 0, 1e18, 1e-11);
    cout << setprecision(10) << fixed;
    cout << func(res) << endl;
    return 0;
}

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

int s[1002];

#define gc() getchar_unlocked()
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, is;
	double m, fs, a;
	
	while (n = in()) {
		is = 0; for (i = 0; i < n; i++) is += s[i] = in();
		m = (double)is/n;
		fs = 0; for (i = 0; i < n; i++) {
			a = s[i]-m;
			fs += a*a;
		}
		printf("%.8lf\n", sqrt(fs/n));
	}
	return 0;
}


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


def solve(X: int, Y: int, Z: int):
    print(Z,X,Y)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<Long> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            long a = sc.nextInt();
            list.add(a);
        }
        Collections.sort(list);

        long halfl = list.get(n/2-1);
        long halfh = list.get(n/2);

        long result = halfh - halfl;

        System.out.println(result);



    }
}


Measured memory_bytes: 60512
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  
  int ans=1;
  
  
  for(int i=1;i<N;i++){
    bool res=true;
    for(int j=0;j<=i;j++){
      if(H[i]<H[j]){
        res=false;
      }
    }
    if(res){
      ans++;
  }
  }
  
  cout<<ans<<endl;
}

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

using namespace std;

void solve(int N, int L, vector<string> S) {
  sort(S.begin(), S.end());
  rep(i, N)
    cout << S[i];
  cout << endl;
}

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

  int N, L;
  cin >> N >> L;

  vector<string> S(N);
  for(int i = 0 ; i < N ; i++)
    cin >> S[i];

  solve(N, L, move(S));
  return 0;
}


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

using namespace std;

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

int N, M, K;
vector<int> A, B, C, D;
vector<int> G[(int)1e5 + 5];
vector<int> R[(int)1e5 + 5];

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};

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

    UnionFind uf(N);

    A.resize(M);
    B.resize(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;

        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);

        uf.connect(A[i], B[i]);
    }

    C.resize(K);
    D.resize(K);
    rep(i, K) {
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;

        // 繋がっている場合 push する
        if (uf.root(C[i]) == uf.root(D[i])) {
            R[C[i]].push_back(D[i]);
            R[D[i]].push_back(C[i]);
        }
    }

    rep(i, N) {
        // 友達でもない
        // ブロックもしてない

        // 同じグループ
        // cout << uf.size(i) << endl;
        int ans = uf.size(i);
        ans -= G[i].size();
        ans -= R[i].size();
        ans--;

        cout << ans << endl;
    }
}

Measured memory_bytes: 13816
#include<stdio.h>
int main()
{
	int r, g, b, n;
	scanf("%d %d %d %d", &r, &g, &b, &n);
	int ans = 0;
	int i, j;
	for (i = 0; i <= 3000; i++)
		for (j = 0; j <= 3000; j++)
			if(n-i*r-j*g>=0)
				if((n-i*r-j*g)%b==0)
				ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main() {
	int a, b, i;
  scanf("%d %d", &a, &b);
  for(i = 0;i <= a;i += 1){
  	if(4*a - 2*i == b){
    	printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0; 
}

Measured memory_bytes: 1640
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int N, Q;
        cin >> N >> Q;
        string S;
        cin >> S;
        vector<int> l(Q), r(Q);
        for (int i = 0; i < Q; i++)
        {
                cin >> l[i] >> r[i];
        }

        vector<int> vec(N + 1, 0);
        for (int i = 1; i < N + 1; i++)
        {

                vec[i + 1] = vec[i];
                if (S[i - 1] == 'A' && S[i] == 'C')
                {
                        vec[i + 1]++;
                }
        }

        for (int i = 0; i < Q; i++)
        {

                cout << vec[r[i]] - vec[l[i]] << endl;
        }
        return 0;
}


Measured memory_bytes: 2176
const input = require("fs").readFileSync("/dev/stdin", "utf8")
;(input => {
    const S = input.split("\n")[0]
    const mod = 2019
    const map = Array(2019).fill(0)
    map[0] = 1
    let c = 0
    let p = 1
    let m = 0

    for (let i = S.length - 1; i >= 0; i--) {
        m = (m + S[i] * p) % mod
        c += map[m]
        map[m]++
        p = p * 10 % mod
    }

    console.log(c)

})(input)


Measured memory_bytes: 32556
def main():
    N = int(input())
    count = 0
    ans = 'No'
    for i in range(N):
        A,B = map(int,input().split())
        if A == B:
            count += 1
        else:
            count = 0
        if count == 3:
            ans = 'Yes'
            break
    
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    // map<int,int> mp;
    int n;
    cin >> n;
    vector<ll>x(n),a(n);
    rep(i,n)cin >> x[i];
    a = x;
    sort(x.begin(),x.end());
    // rep(i,n){
    //     mp[x[i]]++;
    // }
    int mid = (n/2);
    rep(i,n){        
        if(a[i]<x[mid]){
            cout<<x[mid]<<endl;
        }else{
            cout << x[mid-1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define N 109
using namespace std;

int m,n,a[N][N],b[N][N]; bool vis[N][N];
int main(){
	scanf("%d%d",&m,&n);
	int i,j,x,y;
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) scanf("%d",&a[i][j]);
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++)
			for (x=0; x<=100; x++)
				for (y=0; y<=100; y++) b[x][y]=max(b[x][y],a[i][j]-i*x-j*y);
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++)
			for (x=0; x<=100; x++)
				for (y=0; y<=100; y++)
					if (b[x][y]==a[i][j]-i*x-j*y) vis[i][j]=1;
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) if (!vis[i][j]){
			puts("Impossible"); return 0;
		}
	puts("Possible");
	printf("202 %d\n",200+101*101);
	for (i=1; i<=100; i++) printf("%d %d X\n",i,i+1);
	for (i=102; i<=201; i++) printf("%d %d Y\n",i+1,i);
	for (i=0; i<=100; i++)
		for (j=0; j<=100; j++) printf("%d %d %d\n",i+1,j+102,b[i][j]);
	puts("1 102");
	return 0;
}


Measured memory_bytes: 384
import copy
h,w,k=map(int,input().split())
data=[input() for i in range(h)]
ans=0
for i in range(2**h):
    for j in range(2**w):
        cp=copy.deepcopy(data)
        cnt=0
        for a in range(h):
          for l in range(w):
            if i>>a&1==1 and j>>l&1==1 and cp[a][l]=="#":
              cnt+=1
        if k==cnt:
          ans+=1
print(ans)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
int main (){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  int c[27][n];
  for(int i=0;i<27;i++)
    for(int j=0;j<n;j++)
      c[i][j]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<s[i].size();j++)
      c[s[i][j]-'a'][i]++;
  }
  string ans;
  for(int i=0;i<27;i++){
    int num=1000000;
    for(int j=0;j<n;j++){
      num = min(num,c[i][j]);
    }
    for(int j=0;j<num;j++){
      ans+=('a'+i);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  
  int64_t X, K, D; cin >> X >> K >> D;
  
  X = abs(X);
  
  if (K < X / D) { cout << X - K * D << endl; return 0; }
  
  int64_t tmp = X / D;
  
  if ((tmp % 2) == (K % 2)) cout << X - D * tmp << endl;
  
  else cout << abs(X - D * (tmp + 1)) << endl;
  
}

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

int main()
{
	int N;
	scanf("%d", &N);

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		char str[8];
		sprintf(str, "%d", i);
		if (strlen(str) % 2 == 1) {
			ans++;
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
/* kadai 3_2
   nabe9393 */
 
#include<stdio.h>
 
int main(void){
  int number_pen;
  scanf("%d", &number_pen); //入力
  if (number_pen % 10 == 3){ //１のくらいが３の時はBON
    printf("bon\n");
  }
  else if (number_pen % 10 == 0 || number_pen % 10 == 1 || number_pen % 10 == 6 || number_pen % 10 == 8){ //1のくらいが0,1,6,8の時はPON
    printf("pon\n");
  }
  else{ //それ以外はHON
    printf("hon\n"); 
  }
return 0;
}

Measured memory_bytes: 1664
n,m,l=map(int,input().split())
P=[]
Q=[]
R=[]
e=0

for i in range(1,n+1):
    P.append(input().split())
    
    
for j in range(1,m+1):
    Q.append(input().split())
   
    
for k in range(1,n+1):
    a=P[k-1]
    
    for p in range(1,m+1):
        b=Q[p-1]
        c=a[p-1]
        
        for q in range(1,l+1):
            d=int(c)*int(b[q-1])
            R.append(d)
          
    for r in range(l):
        for s in range(m):
            e+=R[r+l*s]
    
        if r<l-1:
            print(e,end=' ')
        else:
            print(e)
        e=0
    R=[]


Measured memory_bytes: 7456
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    vector<double> arr(n, 0.0);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    for(int i = 1; i < n; i++) {
        arr[i] = (arr[i] + arr[i-1]) / 2.0;
    }
    cout << fixed << setprecision(12) << arr.back() << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<list>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<limits>
#include<cctype>
#include<unordered_map>
#include<complex>
#pragma warning(disable:4996)
using namespace std;

#define debug(i) cout<<"<debug> "<<#i<<" "<<i<<" <\\debug>"<<endl
#define mfor(i,a,b) for(int i=(a);i<=(b);i++)
#define mrep(i,a,b) for(int i=(a);i>=(b);i--)
#define lll __int128
#define Re register
#define mem(a,b) memset(a,(b),sizeof(a))
#define Design ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
typedef pair<int, int> intpair;
typedef pair<long long int, long long int> llpair;
typedef long long int ll;
const double pi = acos(-1);
const double eps = 1e-5;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;

const int maxn = 2000010;

struct interval
{
	int p;
	int x;
	int ty;
    interval(int p, int x, int ty) :p(p), x(x), ty(ty) {}
	bool operator < (interval s)const
	{
		return p < s.p;
	}
};

struct TreeArray
{
    int n;
    ll sum[maxn];

    TreeArray()
    {
        memset(sum, 0, sizeof(sum));
    }

    inline int lowbit(int x)
    {
        return x & (-x);
    }

    void update(int x, int k)
    {
        for (int i = x; i <= n; i += lowbit(i)) sum[i] += k;
    }

    ll get_sum(int x)
    {
        ll res = 0;
        for (int i = x; i; i -= lowbit(i))
        {
            res += sum[i];
        }
        return res;
    }

    ll query(int l, int r)
    {
        return get_sum(r) - get_sum(l - 1);
    }

    int build(int* a)
    {
        for (int i = 1; i <= n; i++)
        {
            update(i, a[i] - a[i - 1]);
        }
    }

    int update(int l, int r, int k)
    {
        update(l, k);
        update(r + 1, k);
    }
}ta;

int pos[maxn];
int l[maxn];
int r[maxn];
int a[maxn];
vector<interval>s;

int main()
{
	Design;
    int x;
    cin >> x;
    cout << !x;
	return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

vector<pair<char, int>> a, b, c;

void read(vector<pair<char, int>> &v) {
	char c; int d;
	while (true) {
		cin >> skipws >> c;
		if (c == '$') return;
		cin >> d;
		v.push_back({c, d});
	}
}

int main() {
	read(a); read(b); read(c);

	for (int st = 0; st <= (int)a.size() - (int)b.size(); st++) {
		int midlen = b.size() - 2;
		bool ok = true;
		for (int i = 0; i < midlen; i++) {
			ok = ok && a[st + i + 1] == b[i + 1];
		}
		if (ok && b.size() > 1) {
			if (a[st].first == b.front().first && a[st + b.size() - 1].first == b.back().first &&
				a[st].second >= b.front().second && a[st + b.size() - 1].second >= b.back().second) {
				// do replacement
				//cerr << "Replacement" << endl;
				vector<pair<char, int>> na;
				for (int i = 0; i < st; i++) na.push_back(a[i]);
				if (a[st].second > b.front().second) na.push_back({ b.front().first, a[st].second - b.front().second });
				for (auto p : c) na.push_back(p);
				if (b.size() > 1 && a[st + b.size() - 1].second > b.back().second) na.push_back({ b.back().first, a[st + b.size() - 1].second - b.back().second });
				for (int i = st + b.size(); i < a.size(); i++) na.push_back(a[i]);
				a = na;
				break;
			}
		} else if (ok) {
			if (a[st].first == b.front().first && a[st].second >= b.front().second) {
				vector<pair<char, int>> na;
				for (int i = 0; i < st; i++) na.push_back(a[i]);
				for (auto p : c) na.push_back(p);
				if (a[st].second > b.front().second) na.push_back({ a[st].first, a[st].second - b.front().second });
				for (int i = st + b.size(); i < a.size(); i++) na.push_back(a[i]);
				a = na;
				break;
			}
		}
	}

	// simplify (condense) a
	{
		vector<pair<char, int>> na;
		pair<char, int> b = a[0];
		for (int i = 1; i < a.size(); i++) {
			if (a[i].first == b.first) b.second += a[i].second;
			else {
				na.push_back(b);
				b = a[i];
			}
		}
		na.push_back(b);
		a = na;
	}
	
	// output a
	for (auto p : a) cout << p.first << " " << p.second << " ";
	cout << "$" << endl;
}



Measured memory_bytes: 3168
local n = io.read("*n", "*l")
local s = io.read()
local t = {}
for i = 1, n do t[i] = s:sub(i, i) == "(" and 1 or - 1 end
local mmi = math.min
while true do
  local minval = 0
  local curval = 0
  for i = 1, n do
    curval = curval + t[i]
    minval = mmi(minval, curval)
  end
  if minval < 0 then
    for i = 1, -minval do
      table.insert(t, 1, 1)
    end
    n = n - minval
  elseif 0 < curval then
    for i = 1, curval do
      table.insert(t, -1)
    end
    n = n + curval
  else
    break
  end
end
for i = 1, n do
  t[i] = t[i] == 1 and "(" or ")"
end
print(table.concat(t))


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define mo 998244353
using namespace std;
long long fac[20010],nifac[20010],f[20010];
char s[20010],t[20010];
long long getmi(long long a,long long x)
{
	long long ans=1;
	while (x)
	{
		if (x&1) ans=ans*a%mo;
		a=a*a%mo;
		x>>=1;
	}
	return ans;
}
long long C(int n,int m){return fac[n]*nifac[m]%mo*nifac[n-m]%mo;}
long long A(int n,int m){return fac[n]*nifac[n-m]%mo;}
int main()
{
	scanf("%s\n%s",s+1,t+1);int len=strlen(s+1),same=0,diff=0;
	fac[0]=nifac[0]=1;
	for (int i=1;i<=len;i++)
	{
		same+=((s[i]=='1')&&(t[i]=='1'));
		diff+=((s[i]=='1')&&(t[i]=='0'));
		fac[i]=fac[i-1]*i%mo;
		nifac[i]=getmi(fac[i],mo-2);
	}
	f[0]=1;
	for (int i=1;i<=diff;i++)
	for (int j=1;j<=same;j++) f[j]=(f[j]+i*f[j-1])%mo;
	long long ans=0;
	for (int i=0;i<=same;i++) ans=(ans+f[i]*nifac[diff+i])%mo;
	printf("%lld\n",ans*fac[diff]%mo*fac[diff]%mo*fac[same]%mo*fac[same+diff]%mo);
}
	
	
	
	
	
	


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stdio.h>
#include <string.h>

#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int result = 0;
    if ( n >= 2){
        result += n * (n - 1) / 2;
    }
    if (m >= 2){
        result += m * (m - 1) / 2;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {
	int H,W;
	int[] dy = {1,-1,0,0};
	int[] dx = {0,0,1,-1};
	public void solve() {
		while(true){
			H = nextInt();
			W = nextInt();

			if(H + W == 0)break;
			char[][] ch = new char[H][];
			for(int i = 0;i < H;i++){
				ch[i] = next().toCharArray();
			}

			boolean[][] used = new boolean[H][W];
			int ans = 0;
			for(int i = 0;i < H;i++){
				for(int j = 0;j < W;j++){
					if(used[i][j])continue;
					ans++;
					Queue<Integer> q = new ArrayDeque<Integer>();
					q.add(i * 100 + j);
					while(q.size() > 0){
						int point = q.poll();
						int y = point / 100;
						int x = point % 100;
						if(used[y][x])continue;
						used[y][x] = true;

						for(int k = 0;k < 4;k++){
							int ny = dy[k] + y;
							int nx = dx[k] + x;
							if(ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
							if(ch[i][j] != ch[ny][nx])continue;
							q.add(ny * 100 + nx);
						}
					}
				}
			}
			out.println(ans);
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 26972
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main(void) {
	int N,cnt = 0;
	ll mi = INF, sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		ll s; cin >> s;
		if (s < 0)cnt++;
		sum += abs(s);
		mi = min(mi, abs(s));
	}

	if (cnt % 2 == 0)cout << sum << endl;
	else cout << sum - 2*mi << endl;

}


Measured memory_bytes: 256
n=int(input())
A=list(map(int, input().split()))
#A=input().split()

print(" ".join([str(i) for i in A]))
for i in range(1,len(A)):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(" ".join([str(i) for i in A]))



Measured memory_bytes: 5608
import sys
N = int(input())
b = list(map(int, sys.stdin.readline().rstrip().split()))
a = []
# print(b)
cnt = 0
while(cnt < 110):
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            a.append(i+1)
            b.pop(i)
            break
    cnt += 1
    # print(a)

if len(a) != N:
    print(-1)
else:
    for i in range(N-1, -1, -1):
        print(a[i])

Measured memory_bytes: 3316