akhauriyash/Code-Regression huggingface dataset:
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = nextIntArray();
  for(var i = 1; i < N; i++){
    list[i] += list[i - 1];
  }
  list.unshift(0);
  var map = {};
  for(var i = 0; i < N + 1; i++){
    if(map[list[i] % M] == null){
      map[list[i] % M] = 0;
    }
    map[list[i] % M]++;
  }
  var output = 0;
  var key = Object.keys(map);
  for(var i = 0; i < key.length; i++){
    output += map[key[i]] * (map[key[i]] - 1) / 2;
  }
  myout(output);
}


Measured memory_bytes: 50432
from collections import deque
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = [int(x) for x in input().split()]
c = sorted(c, reverse=True)

q = deque([0])
visited = [False]*n
ans = [-1]*n
ans[0] = c[0]
i = 1

while q:
    v = q.popleft()
    visited[v] = True
    for w in g[v]:
        if not visited[w]:
            ans[w] = c[i]
            i += 1
            q.append(w)

print(sum(c[1:]))
print(*ans)


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var max = L.Max();
            var sum = L.Sum();

            Console.WriteLine(max < sum - max ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
import sys
import numpy as np
H,W = map(int, input().split())
read = sys.stdin.read
grid = np.array(list(map(str,read()))).reshape(H,-1)[:,:-1]

black_ind = np.where(grid == '#')

C = np.zeros([H,W],np.int32)
C[black_ind] = 1

num_orig_black = np.count_nonzero(C)

q = [[0,0,1]]

minimum_pass = -1
while q:
	ch,cw,cd = q.pop(0)
	if ch == H-1 and cw == W-1:
		minimum_pass = cd
		break
	if C[ch,cw] == 1:
		continue
	
	C[ch,cw] = 1

	for nh,nw in [[ch+1,cw],[ch-1,cw],[ch,cw+1],[ch,cw-1]]:
		if 0 <= nh < H and 0 <= nw < W:
			if C[nh,nw] == 0:
				q.append([nh,nw,cd+1])

if minimum_pass == -1:
	print(-1)
else:
	print(W*H - minimum_pass - num_orig_black)



Measured memory_bytes: 14440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    int n = s.size();
    for(int i=1; i<n; i++){
        string t = s.substr(0, n-i);
        // cerr<<t<<endl;
        int u = t.size();
        if(u %2==1) continue;
        string t1 = t.substr(0, u/2);
        string t2 = t.substr(u/2, u/2);
        bool isok = true;
        for(int j=0; j<t1.size(); j++){
            if(t1[j]!=t2[j]){
                isok = false;
            }
        }
        if(isok){
            cout<<u<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod =998244353LL; 
long long modpow(long long a, long long n, long long mod = (1LL << 62)){
	long long res = 1;
	while (n > 0){
		if (n & 1)
		res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main(){
	int n;
	ll ans=0;
	cin >>n;
	int bef;
	map<int,ll>d;
	rep(i,n){
		cin>>bef;
		d[bef]+=0LL;
		d[bef]++;
		if(i==0){
			if (bef==0){
				ans=1LL;
			}
		}else if(bef==0){
			ans=0LL;
		}
	}
	int last=-1;
	auto ter=d.begin();
	repi(itr,d){
		
		if(last+1 != (itr->F)){
			ans=0LL;
		}
		last=(itr->F);
		if((itr->F)==1 or (itr->F)==0){
			continue;
		}
		ter = itr;
		ter--;
		ans*=modpow((ter)->S,(itr)->S,mod);
		ans%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9876
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int T[20];
int A[20], B[20];
int n, m;

int solve() {
    int P[17];
    P[n] = 2;
    for ( int i = n; i > 0; -- i ) P[i-1] = 3 * P[i] + 2;
    
    A[n] = T[n];
    B[n] = 2 - T[n];
    for ( int i = n; i > 1; -- i ) {
        if ( T[i-1] == 0 ) {
            A[i-1] = A[i];
            B[i-1] = B[i] + 2 * P[i] + 2;
        } else if ( T[i-1] == 1 ) {
            A[i-1] = B[i] + P[i] + 1;
            B[i-1] = A[i] + P[i] + 1;
        } else if ( T[i-1] == 2 ) {
            A[i-1] = A[i] + 2 * P[i] + 2;
            B[i-1] = B[i];
        }
    }
    int res = min( A[1], B[1] );
    if ( res > m ) return -1;
    return res;
}

int main() {
    while ( cin >> n >> m && n ) {
        for ( int i = 0; i < 3; ++ i ) {
            int k;
            cin >> k;
            for ( int j = 0; j < k; ++ j ) {
                int t;
                cin >> t;
                T[t] = i;
            }
        }

        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

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

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
	bool is_visited;
} edge;
int main( void ){
	int N; cin >> N;
	vector <int> vec( N );
	rep( i, 0, N ){
		cin >> vec[ i ];
	}
	int cnt = 0;
	rep( i, 1, N - 1 ){
		if (vec[ i ] < vec[ i - 1 ] && vec[ i ] > vec[ i + 1 ] || vec[ i ] > vec[ i - 1 ] && vec[ i ] < vec[ i + 1 ])
			cnt++;
	}
	cout << cnt << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <vector> 
#include <map>
#include <queue>
#include <iostream>
#include <iterator>
#define pb push_back 
#define int long long
using namespace std; 

int32_t main() 
{ 
	int n,q,s=0; 
	cin >> n; 
	vector<int> v(100069,0); 
	for(int i=0, t;i<n;i++)
	{
		cin >> t;
		v[t]++;
		s+=t;
	}
	cin >> q;
	int b, c; 
	while(q--) { 
		cin >> b >> c; 
		s-=v[b]*b;
		s+=v[b]*c;	
		v[c]+=v[b];
		v[b]=0;
		cout<<s<<"\n";
		
	} 

	

	return 0; 
} 


Measured memory_bytes: 4032
import java.util.*;

public class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str[] = new String[n];
        for (int i = 0; i < n; i++) str[i] = sc.next();

        for (int i=0 ;i<n; i++){
            char c[] = str[i].toCharArray();
            Arrays.sort(c);
            str[i] = Arrays.toString(c);
        }

//        for (int i=0; i<n; i++)

        Map<String, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++) {

            if (map.containsKey(str[i])) {
                map.put(str[i], map.get(str[i]) + 1);
            } else {
                map.put(str[i], 1l);
            }
        }

        long sum = 0;
        for (long i: map.values()){
            sum += i*(i-1)/2;
        }
        System.out.print(sum);
//        System.out.print(str[0]);

    }
    }

//    public static boolean comp(char[] c1, char []c2){
//
//        Arrays.sort(c1);
//        Arrays.sort(c2);
//        if (Arrays.equals(c1, c2)){
//            return true;
//        }else{
//            return false;
//        }
//    }
//}

Measured memory_bytes: 74536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
string s;
int N;
const int MN = 500100;
int d[MN];
void sub(int x,int v){
	for(int i=x;;i++){
		if(d[i]<v%10){
			d[i]+=10;
			d[i+1]--;
		}
		d[i]-=v%10;
		v/=10;
		if(v==0) break;
	}
	if(d[x+1]<0){
		d[x+1]+=10;
		d[x+2]--;
	}
}
bool can(int K){
	int lim = K*9;
	rep(i,N){
//		show(i);
		if(lim%10<d[i]){
			lim-=lim%10;
			lim-=10;
			lim+=d[i];
		}else{
			lim-=(lim%10-d[i]);
		}
//		show(lim);
//		cout<<"d = ";
//		for(int i=4;i>=0;i--) cout<<d[i]<<" ";
//		puts("");
		if(lim<0) return 0;
		sub(i,lim);
	}
	for(int i=MN-1;i>=0;i--){
		if(d[i]>0) return 1;
		if(d[i]>0) return 0;
	}
	return 1;
}
int main(){
	cin>>s;
	N=s.size();
	// show(can(1));
	// show(can(2));
	// show(can(3));
	// show(can(4));
	int ub=N,lb=0;
	while(ub-lb>1){
		rep(i,N) d[i]=s[N-1-i]-'0';
		int m=(ub+lb)/2;
		if(can(m)) ub=m;
		else lb=m;
	}
	cout<<ub<<endl;
}


Measured memory_bytes: 2820
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    }
}

Measured memory_bytes: 50800
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int n,k; cin>>n>>k;
    vector<double> p(n);
    for(int i=0;i<n;i++){
        int a; cin>>a;
        p[i]=(a+1)/2.0;
    }

    double ans=0;
    vector<double> s(n);
    s[0]=p[0];
    for(int i=1;i<n;i++){
        s[i]=s[i-1]+p[i];
    }
    if(n==k){
        ans=s[n-1];
    }else{
        for(int i=0;i<n-k;i++){
            ans=max(s[i+k]-s[i],ans);
        }
    }
    printf("%.10f\n",ans);
}

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

int main() {
	long long A, B, C, K;
	cin >> A >> B >> C >> K;
	if (A >= K) cout << K << endl;
	else if (A + B >= K) cout << A << endl;
	else if (A + B + C >= K) cout << A - (K - A - B) << endl;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
string S;
int num[30050][10];
int num2[30050][10];
set<string> U;

signed main(){
	cin>>N>>S;
	REP(i,N-1){
		num[i][S[i]-'0']=1;
		REP(j,10){
			num[i+1][j]=num[i][j];
		}
	}
	num[N-1][S[N-1]-'0']=1;
	for(int i=N-1;1<=i;i--){
		num2[i][S[i]-'0']=1;
		REP(j,10){
			num2[i-1][j]=num2[i][j];
		}
	}
	num2[0][S[0]-'0']=1;
	for(int i=1;i<N-1;i++){
		REP(j,10){
			REP(k,10){
				if(num[i-1][j]==1&&num2[i+1][k]==1){
					string s;
					s+=to_string(j);
					s+=S[i];
					s+=to_string(k);
					DEB(s)END
					U.insert(s);
				}
			}
		}
	}
	cout<<U.size()<<endl;
	return 0;
}


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

/*
例えばにぶたんを使おうとすると？mより大きいのがいくつあるかが判定出来ればいい
全ての値が4e6以下なのもどうにか使いたいはず
2000回それぞれ4e6を参照してやれば確実に出来る
つまり、dp[i]をiが何回出来るかにしてやれば
dp[0]=1;
for(int i=0;i<N;i++)
  for(int j=4e6;j>=0;j--)
    dp[j+v[i]]+=dp[j];
これで最後に真ん中をみてやればいい（真ん中見るのも大変そうだけど）
けどこれだと8e9回ほどかかる
イメージ的にはdpのコピーを作ってv[i]だけ右にずらして足し合わせるんだよね

*/
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int N;cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int sum=0;
  for(int i=0;i<N;i++)sum+=v[i];
  bitset<4000005> bs(1);
  for(int i=0;i<N;i++)bs|=(bs<<v[i]);
  for(int i=(sum+1)/2;;i++)if(bs[i])fin(i);
}


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(ll i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	ll a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	
	rep(i, n) {
		if (c * (n - 1 - i) - d * i <= b - a and b - a <= -c * i + (n - 1 - i) * d) {
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;


int main(){
    int n; cin >> n;
    vector<int> a(n);
    ll sum = 0;
    rep(i,n) {
        cin >> a[i];
        sum += a[i];
    }
    ll left = a[0];
    ll right = sum - left;
    ll ans = abs(right - left);
    for(int i = 1; i < n-1; ++i){
        left += a[i];
        right = sum - left;
        ans = min(ans, abs(right - left));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  vector<int> C(N + 1, 0), S(N + 1, 0), F(N + 1, 0);
  for (int i = 0; i < N - 1; i++) cin >> C[i] >> S[i] >> F[i];

  for (int i = 0; i < N - 1; i++) {
    int t = S[i];
    for (int j = i + 1; j < N; j++) {
      t += C[j - 1];
      int start = S[j];
      if (F[j] == 0) break;
      while (t < start or t % F[j] != 0) {
        t++;
      }
    }
    cout << t << endl;
  }

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

Measured memory_bytes: 256
main = mapM_ process . takeWhile (/= "0 0") . lines =<< getContents
  where process line = do
                          putStrLn $ show $ length [(a,b,c) | a<- [1..n], b<-[1..n], c<-[1..n], a<b, b<c, a+b+c==x]
                          where [n,x] = map (read::String->Int) $ words line

Measured memory_bytes: 5000
from decimal import Decimal
import math

a, b, x = list(map(Decimal, input().split()))

if a * a * b > 2 * x:
    tri = x / a
    c = tri * Decimal(2) / b
    d = (c ** 2 + b ** 2) ** Decimal("0.5")
    cos_a = (b ** 2 + d ** 2 - c ** 2) / (2*b*d)
    print(90 - math.degrees(math.acos(cos_a)))
else:
    tri = (a * a * b - x) / a
    e = tri * Decimal(2) / a
    f = (a ** 2 + e ** 2) ** Decimal("0.5")
    cos_e = (f ** 2 + a ** 2 - e ** 2) / (2*f*a)
    print(math.degrees(math.acos(cos_e)))
#print(cosin)


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

static const unsigned long long MOD = 1000000007LL;

int main() {
    
    char s[100005];
    uint64_t dp[100005][13];

    cin >> s;

    dp[0][0] = 1;
    int n = strlen(s);
    for(int i = 0; i < n; i++) {
        int num;
        if (s[i] != '?') num = s[i] - '0';
        else num = -1;

        for(int j = 0; j < 10; j++) {
            if (num != -1 && num != j) continue;
            for (int k = 0; k < 13; k++) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }

        for(int j = 0; j < 13; j++) {
            dp[i+1][j] %= MOD;
        }
    }
    uint64_t ans = dp[n][5] % MOD;
    cout << ans;

    return 0;
}

Measured memory_bytes: 10496
import sys
def 解():
    iW,iH,iN =[int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iU = iH
    iD = 0
    iL = 0
    iR = iW

    for x,y,a in aD:
        if a == 1:
            iL = max(iL,x)
        elif a == 2 :
            iR = min(iR,x)
        elif a == 3:
            iD = max(iD,y)
        elif a == 4:
            iU = min(iU,y)
    if iD > iU or iL > iR:
        print (0)
    else:
        print((iU-iD)*(iR-iL) )
解()


Measured memory_bytes: 3320
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <time.h>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define MAXN 250
# define eps 1e-3
# define MAXM 500005
# define MOD 1000000007
# define INF 1000000000
# define MIN(a,b) (a)>(b)?(b):(a)
# define MAX(a,b) (a)<(b)?(b):(a)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
typedef long long LL;
typedef unsigned long long ULL;

int main()
{
    char a[55],b[55],c[105];
    scanf("%s%s",a,b);
    int j=0;
    for(int i=0;i<strlen(a);i++)
    {
        c[j++]=a[i];
        if(i<strlen(b))c[j++]=b[i];
    }
    c[j]='\0';
    printf("%s",c);
    return 0;
}























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vl x(n), y(n), a(n), b(n);
  rep(i,n) {
    cin >> x[i] >> y[i];
    a[i] = x[i] - y[i];
    b[i] = x[i] + y[i];
  } 
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ll ans = max(a[n-1] - a[0], b[n-1] - b[0]);
  cout << ans << endl;
}


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

int solve(array<string, 3>& decks)
{
    auto current = 0;
    while (true)
    {
        if (decks[current].empty()) return current;
        const auto next = decks[current][0] - 'a';
        decks[current] = decks[current].substr(1);
        current = next;
    }
}

int main()
{
    auto decks = array<string, 3>{};
    cin >> decks[0] >> decks[1] >> decks[2];

    cout << static_cast<char>('A'+solve(decks)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main()
{
	uint64_t N;
	cin >> N;
	uint64_t count=0;
	for (uint64_t i = 1; i <= N; i++) {
		if (i % 3 == 0 ||i%5==0) {
			continue;
		}
		else {
			count += i;
		}
		
	}

	cout << count;
	return 0;



}



Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  long long n,a,b;
  cin >> n >> a >> b;

  cout << min(a * n, b) << endl; 

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    string S;
    cin >> S;
    rep(i,S.length()){
        if(i%2==0){
            if (S[i] == 'R' || S[i] == 'U' || S[i] == 'D')continue;
            else{
                cout << "No" << endl;
                return 0;
            }
        }else{
            if (S[i] == 'L' || S[i] == 'U' || S[i] == 'D')
                continue;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  long long n, d; cin >> n >> d;
  int c=0;
  for(int i=0;i<n;i++){
    long long x, y; cin >> x >> y;
    if(x*x+y*y<=d*d) c++;
  }
  cout << c << endl;
}

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

int main(){
	int n,a[128];
	int min=0,max=0,cnt=0;
	bool flag[16];

	for(int i=0;i<8;i++){
		flag[i] = false;
	}

	cin >>n;
	for(int i=0;i<n;i++){
		cin >>a[i];
	}
	sort(a,a+n);


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

		if(3200 <= a[i]){
			max++;
			min = 1;
		} else if(2800 <= a[i] && a[i] <= 3199 && !flag[7]){
			flag[7] = true;
		} else if(2400 <= a[i] && a[i] <= 2799 && !flag[6]){
			flag[6] = true;
		} else if(2000 <= a[i] && a[i] <= 2399 && !flag[5]){
			flag[5] = true;
		} else if(1600 <= a[i] && a[i] <= 1999 && !flag[4]){
			flag[4] = true;
		} else if(1200 <= a[i] && a[i] <= 1599 && !flag[3]){
			flag[3] =true;
		} else if(800 <= a[i] && a[i] <= 1199 && !flag[2]){
			flag[2] = true;
		} else if(400 <= a[i] && a[i] <= 799 && !flag[1]){
			flag[1] = true;
		} else if(1 <= a[i] && a[i] <= 399 && !flag[0]){
			flag[0] = true;
		}
	}

	for(int i=0;i<8;i++){
		if(flag[i])
			cnt++;
	}

	if(a[0] < 3200)
		min = 0;

	cout <<cnt+min << " " <<cnt+max <<endl;

	return 0;
}

Measured memory_bytes: 256
/* ************************************************************* */
/*     Author     : Mahabub.Tweety                               */
/*     Email      : mahabubrahman618@gmail.com                   */
/*     University : Comilla University, Bangladesh		         */
/*                  Department of Computer Science & Engineering */
/* ***************************************************************

/*
	Compiled : CNU c++ 14
	Copyright 2019 by Mahabub Rahman & Comilla University Sailor ; all rights reserved.
	Permission is granted for use in non-commercial applications provided this
	copyright notice remains intact   and unchanged.
*/


/*...................................Data_Types............................................*/
#include<bits/stdc++.h>

using namespace std;

#define       ll                  long long int
#define       ull                  unsigned long long int
#define       veci                 vector<int>
#define       vecc                 vector<char>
#define       vecs                 vector<string>
#define       vecl                 vector<long long int>
#define       vecp                 vector<  pair<int,int> >
#define       mapstrint            map< string , int >
#define       mapstrstr            map< string , string >
#define       mapint               map< int, int >
#define       pb                   push_back
#define       pob                  pop_back
////============ CONSTANT ===============////
#define mx9   1000000009
#define mx7   10000007
#define mx6   1000006
#define mx5   100005
#define inf   1<<30                                           //infinity value
#define eps   1e-9
#define mx    (65540)
#define mod   1000000007
////=====================================////

long double PI = acosl(-1);
bool compare_int(int a, int b) //This function is use for descending order.
{
    return (a>b);
}
bool compare_string (string a, string b)
{
    return a.size() < b.size();
}
bool compare_pair(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
ll fact(ll n)
{
    if(n==0 || n==1) return 1;
    else return n*fact(n-1);
}

////======================================////

int main()
{
    int n, k, cnt, ans=0;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        k = i;
        cnt = 0;
        while(k)
        {
            k/=10;
            cnt++;
        }
        if(cnt%2) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

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


int main() {
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, n) {
		int a;
		cin >> a;
		mp[a]++;
	}
	int res = 0;
	for (auto x : mp) {
		if (x.second > x.first) res += x.second - x.first;
		else if (x.second < x.first) res += x.second;
	}
	cout << res << endl;
}

Measured memory_bytes: 4736
#include<iostream>
#include<string>

class DICE{
    public:
        int rear,back,right,left,up,down,TNP;
        void North();
        void East();
        void West();
        void South();
};

//北に1回動くときのサイコロの目の変化を記述
void DICE::North(){
    TNP=up;
    up=rear;
    rear=down;
    down=back;
    back=TNP;
}
//東に1回動くときのサイコロの目の変化を記述
void DICE::East(){
    TNP=up;
    up=left;
    left=down;
    down=right;
    right=TNP;
}
//西に1回動くときのサイコロの目の変化を記述
void DICE::West(){
    TNP=up;
    up=right;
    right=down;
    down=left;
    left=TNP;
}
//南に1回動くときのサイコロの目の変化を記述
void DICE::South(){
    TNP=up;
    up=back;
    back=down;
    down=rear;
    rear=TNP;
}


int main(){
    int Up,Rear,Right,Left,Back,Down;
    DICE DICES[100];
    int i;
    for(i=0;i<2;i++){
        std::cin>>Up>>Rear>>Right>>Left>>Back>>Down;
        DICES[i].up=Up;
        DICES[i].rear=Rear;
        DICES[i].right=Right;
        DICES[i].left=Left;
        DICES[i].back=Back;
        DICES[i].down=Down;
    }  

    for(i=1;i<2;i++){
       if(DICES[i].up==DICES[0].rear||DICES[i].down==DICES[0].rear){
            while(DICES[i].rear!=DICES[0].rear){
                DICES[i].South();
            }
            while(DICES[i].up!=DICES[0].up){
                DICES[i].East();
            }
        }else{
            DICES[i].North();
            while(DICES[i].up!=DICES[0].rear){
                DICES[i].West();
            }
            DICES[i].South();
            while(DICES[i].up!=DICES[0].up){
                DICES[i].East();
            }
        }
        
    }

    if(DICES[0].right==DICES[1].right){
        std::cout<<"Yes"<<std::endl;
    }else{
        std::cout<<"No"<<std::endl;
    }

    return 0;   
}



Measured memory_bytes: 3100
#include<cstdio>
using namespace std;
typedef long long ll;
int n,p,ans,C[3100][3100],S[3100][3100],p2[3100],p22[3100];
int qpow(int x,int a){
	int res=1;
	while (a){
		if (a&1) res=(ll)res*x%p;
		x=(ll)x*x%p; a>>=1;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&p);
	C[0][0]=1; S[0][0]=1;
	for (int i=1;i<=n+1;i++){
		C[i][0]=1;
		for (int j=1;j<=i;j++){
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
			S[i][j]=(S[i-1][j-1]+(ll)S[i-1][j]*j%p)%p;
		}
	}
	int tmp=1;
	p2[n]=1; p22[n]=2;
	for (int i=n-1;i>=0;i--){
		p2[i]=(p2[i+1]<<1)%p;
		tmp=(tmp<<1)%(p-1);
		p22[i]=qpow(2,tmp);
	}
	int op=-1;
	for (int i=0;i<=n;i++){
		op=-op;
		int mul=(C[n][i]*op+p)%p,mul2=1;
		int sum=0;
		for (int j=0;j<=i;j++){
			sum=(sum+(ll)S[i+1][j+1]*p22[i]%p*mul2%p)%p;
			mul2=(ll)mul2*p2[i]%p;
		}
		ans=(ans+(ll)mul*sum%p)%p; 
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 72832
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
const ll maxn = 1e5 + 7;
void solve() {
	ll n;
	cin >> n;
	vl a(n);
	vl m(maxn, 0);
	ll sum = 0;
	rep(i, 0, n) {
		cin >> a[i];
		m[a[i]]++;
		sum += a[i];
	}
	int q;
	cin >> q;
	rep(i, 0, q) {
		ll b, c;
		cin >> b >> c;
		ll psum = sum;
		sum -= (m[b] * b);
		sum += (m[b] * c);
		m[c] += m[b];
		m[b] = 0;
		cout << sum << endl;
	}
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 4760
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N;
    cin >> N;
    int i = 1;

    while (i * i <= N) {
        i++;
    }

    i--;

    cout << i * i << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner s = new Scanner(System.in)) {
			 final int n = s.nextInt();
			 final int m = s.nextInt();
			 
			 System.out.println((n - 1) * (m - 1));
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define p pair<int, int>
#define fi first
#define se second
using namespace std;

// 0-indexed
// now node k
// child node k*2+1 and k*2+2
// parent node (k-1)/2
struct data {
  p a;
};
const p maxint = {2147483647, 0};
data resetdata = {maxint};
struct RMQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RMQ(int newn = 1, data resets = resetdata) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, p newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = min(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  p pick(int a, int b, int k = 0, int l = 0, int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return maxint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    p nowl, nowr;
    int nextlr = k * 2 + 1, med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return min(nowl, nowr);
  }
};

long long n;
RMQ rmq;

long long solve();

int main() {
  cin >> n;
  rmq = RMQ(n);
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    rmq.update(i, {x, i});
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  queue<p> qu;
  qu.push({0, n});
  while(qu.size() > 0) {
    p now = qu.front();
    qu.pop();
    p a = rmq.pick(now.fi, now.se);
    ans += (long long)(a.se - now.fi + 1) *
           (now.se - a.se) * a.fi;
    if(now.fi != a.se) qu.push({now.fi, a.se});
    if(a.se + 1 != now.se) qu.push({a.se + 1, now.se});
  }
  return ans;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    vector<char> L(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> L[0] >> L[1] >>L[2];
    sort(L.begin(), L.end());
    
    
    // ans = min(A, B) + min(C, D);
    // cout << ans<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    if(L[0]=='a' && L[1]=='b' && L[2]=='c' )
	puts("Yes");
    else
    	puts("No");
}



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

int main(){
  int r, c;
  cin >> r >> c;
  int sc[r+1][c+1];

  for(int i=0; i<r; i++){
    sc[i][c] = 0;
    for(int j=0; j<c; j++){
      sc[r][j] = 0;
      cin >> sc[i][j];
      sc[i][c] += sc[i][j];
    }
  }

  sc[r][c] = 0;

  for(int i=0; i<c+1; i++){
    for(int j=0; j<r; j++){
      sc[r][i] += sc[j][i];
    }
  }
  for(int i=0; i<r+1; i++){
    for(int j=0; j<c; j++){
      cout << sc[i][j] << " ";
    }
    cout << sc[i][c] ;
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    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 % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    comb_init();
    for(ll i=0;i<n;i++){
        ans += i * (n-i) * m * m * comb(n*m-2,k-2);
        ans%=MOD;
    }
    for(ll i=0;i<m;i++){
        ans += i * (m-i) * n * n * comb(n*m-2,k-2);
        ans %= MOD;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=s.length();
    ll k;
    cin>>k;
    ll ans=0LL;
    if(n==1){
        cout << k/2<<endl;
        return 0;
    }
    bool maki=true;

    ll num=1LL;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1])maki=false;
        if(i==n-1){
            if(s[i]==s[i-1])num++;
            ans+=(num/2);
        }
        else if(s[i]==s[i-1]){
            num++;
        }
        else{
            ans+=(num/2);
            num=1;
        }
    }
    if(maki){
        cout << n*k/2<<endl;
        return 0;
    }
    //cout<<ans<<endl;
    if(k>1 && s[0]==s[n-1]){
        if(s[0]==s[1])s[0]='1';
        else s[n-1]='1';
        ans+=k-1;
    }
    ///cout << ans<<endl;
    num=1LL;
    ll a=0LL;
    for(int i=1;i<n;i++){
        if(i==n-1){
            if(s[i]==s[i-1])num++;
            a+=num/2;
        }
        else if(s[i]==s[i-1]){
            num++;
        }
        else{
            a+=num/2;
            num=1;
        }
    }
    //cout << a<<endl;
    ans+=(k-1)*a;
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def bubbleSort(A,N):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A,count


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

A,count = bubbleSort(A,N)

for i in range(len(A)):  # output
    if i == len(A) - 1:
        print(A[i])
    else:
        print(A[i], end=' ')

print(count)

Measured memory_bytes: 7804
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;
#define prev prev55

long long n, k, a[500000], b[500000], ans;

long long correct(int l, int r);

long long solve(int l, int r)
{
    if (l + 1 == r)
    {
        if (a[l] % k == 0) return 1;
        return 0;
    }
    if (l >= r) return 0LL;
    int m = (l + r) / 2;
    long long ans = solve(l, m) + solve(m, r);
    vector<int> lens;
    map<int, int> cnts;
    int sigma = 0;
    for (int i = m - 1; i >= l; i--)
    {
        sigma = (sigma + a[i]) % k;
        lens.push_back(sigma);
        cnts[sigma]++;
    }
    //while (lens.size() > k - 2) cnts[lens[lens.size() - 1]]--, lens.pop_back();
    //cout << l << " " << r << endl;
    //cout << "    " << lens.size() << "\n    ";
    //for (int i = 0; i < lens.size(); i++) cout << lens[i] << " ";
    //cout << endl;
    int sigma2 = a[m] % k;
    int st = 1;
    for (int i = m; i < r; i++, st++)
    {
        while (lens.size() + st > k - 1 && lens.size() > 0) cnts[lens[lens.size() - 1]]--, lens.pop_back();
        if (lens.size() == 0) break;
        ans += cnts[(k - sigma2) % k];
        //cout << "    " << cnts[(k - sigma2) % k] << "\n";
        sigma2 = (sigma2 + a[i + 1]) % k;
    }
    //cout << l << " " << r << " : " << ans << " " << correct(l, r) << endl;
    return ans;
}

long long correct(int l, int r)
{
    long long ans = 0;
    for (int i = l; i < r; i++)
    {
        long long summ = 0;
        for (int j = i; j < r; j++)
        {
            summ += a[j];
            if (summ % k == 0 && (j - i + 1) < k) ans++;
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    if (k == 1) {cout << 0; return 0;}
    for (int i = 0; i < n; i++) cin >> a[i], a[i] = (a[i] - 1 + k) % k;
    //cout << correct(0, n) << endl;
    cout << solve(0, n);
}


Measured memory_bytes: 14192
#include<bits/stdc++.h>
using namespace std;
int year, month, day;
int read(){
	int x = 0;
	char ch = getchar();
	while(ch > '9' || ch < '0')ch = getchar();
	while(ch >= '0' && ch <= '9')x = 10 * x + ch - 48, ch =getchar();
	return x;
}
int main(){
	year = read();
	month = read();
	day = read();
	if(year < 2018)printf("Heisei\n");
	else{
		if(year == 2019){
			if(month <= 4)printf("Heisei\n");
			else printf("TBD\n");
		}
		else printf("TBD\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
   int a,b,d,r;
   double f;
   cin >> a;
   cin >> b;
   d = a / b;
   r = a % b;
   f = double(a) / double(b);
   cout << d;
   cout << " ";
   cout << r;
   cout << " ";
   cout << fixed << setprecision(5) << f;
   cout << endl;
}



Measured memory_bytes: 3288
S=input()

L=S.replace("LR","L,R").split(",")
ans=[]
for s in L:
    t=len(s)
    a=(t+1)//2
    b=t//2
    r=s.count("R")
    l=t-r
    if r&1:
        for i in range(r-1):ans+=0,
        ans+=a,
        ans+=b,
        for i in range(l-1):ans+=0,
    else:
        for i in range(r-1):ans+=0,
        ans+=b,
        ans+=a,
        for i in range(l-1):ans+=0,

print(*ans)

Measured memory_bytes: 9468
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
vector<vector<int>> l;

int dp(int i, int j, string& s, string& t) {
  if (i == -1 || j == -1) {
    return 0;
  } else {
    if (l[i][j] != -1) return l[i][j];
    if (s[i] == t[j]) {
      l[i][j] = 1 + dp(i - 1, j - 1, s, t);
    } else {
      int r1 = dp(i - 1, j, s, t);
      int r2 = dp(i, j - 1, s, t);
      l[i][j] = max(r1, r2);
    }
    return l[i][j];
  }
}
int main() {
  string s, t;
  cin >> s;
  cin >> t;
  l.resize(s.length());
  for (int i = 0; i < l.size(); ++i) l[i].resize(t.length(), -1);
  int ansl = dp(s.length() - 1, t.length() - 1, s, t);
  string ans = "";
  int i = s.length() - 1;
  int j = t.length() - 1;
  while (i >= 0 && j >= 0) {
    if (s[i] == t[j]) {
      ans += s[i];
      i--;
      j--;
    } else {
      if (i == 0)
        --j;
      else if (j == 0)
        --i;
      else if (l[i - 1][j] > l[i][j - 1])
        i--;
      else
        j--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}



Measured memory_bytes: 35968
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        int n  = ni();
        int give = 0;

        while(give < n)
            give += 1000;
        pn(give - n);
    }
 
    static final long mod=(long)1e9+7l;

    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}

Measured memory_bytes: 36644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static int maxVal = 1000000 + 1;
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        var arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).OrderBy(v => v).GroupBy(v => v);
        int[] memo = new int[maxVal];
        int count = 0;
        int befVal = -1 ;
        foreach(var element in arr)
        {
            if(memo[element.Key] == 0)
            {
                if (element.Count() == 1)
                {
                    count++;
                }
                for(int i = element.Key; i < maxVal; i+=element.Key)
                {
                    memo[i]++;
                }
            }
            if(befVal == element.Key)
            {
                count--;
            }
            befVal = element.Key;
        }
        Console.WriteLine(count);

    }
}

Measured memory_bytes: 62912
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int i;
#define rep(i,l,r) for(i=(l);i<(r);i++)
#define per(i,r,l) for(i=(r);i>(l);i--)
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	swap(&a,&c);
	swap(&b,&c);
	printf("%d %d %d",a,b,c);
	return 0;
}
int swap(int *a,int *b){
	int temp = *a;
	*a = *b;
	*b = temp;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
N = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(1,N-1):
  if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
    cnt += 1
  
print(cnt)

Measured memory_bytes: 3060