akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <sstream>
using namespace std;
#define rep(i,n) for (int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector <int> ans(n);
    rep(i,n) ans[a[i]-1] = i+1;
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=1000000000+7;
ll fact(ll x){
    if(x==1 || x==0)return 1;
    else return (x*fact(x-1))%mod;
}

int main(){
    ll n,m;
    cin>>n>>m;
    if(n>m+1 || m>n+1)cout<<0;
    else{
        if(n==m)cout<<(fact(n)*fact(m)*2)%mod;
        else cout<<(fact(n)*fact(m))%mod;
    }
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<stack>
#include<cmath>
#include<queue>
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
   while(~scanf("%d%d",&a,&b))
   {
       c=a*(a-1)/2;
       d=b*(b-1)/2;
       printf("%d\n",c+d);

   }
}



Measured memory_bytes: 256
N,K = [int(i) for i in input().rstrip().split(' ')]
R,S,P = [int(i) for i in input().rstrip().split(' ')]
r = 0
T = input()
te = ["p","r","s"]
point = {"p":P,"r":R,"s":S}
Play = []
for i,t in enumerate(T):
    best = te[te.index(t)-1]
    if Play[i-K] != best if i >= K else True:
        Play += [best]
        r += point[best]
    else:
        Play += ["#"]
print(r)

Measured memory_bytes: 4212
/*
	##############################
	## Author: Pratyush Gaurav ###
	## College: NIT ROURKELA #####
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long/*--------------------*/lli;
typedef long double/*------------------*/ld;
typedef unsigned long long/*-----------*/ulli;
typedef pair<lli, lli >/*--------------*/plli;
typedef vector<plli >/*----------------*/vplli;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define lb/*---------------------------*/lower_bound
#define ub/*---------------------------*/upper_bound
#define pb/*---------------------------*/push_back
#define popb/*-------------------------*/pop_back

#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define opt/*--------------------------*/ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz/*---------------------------*/size()

#define MP/*---------------------------*/make_pair
#define bs/*---------------------------*/binary_search
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define sqr(x)/*-----------------------*/(x)*(x)
#define all(a)/*-----------------------*/a.begin(),a.end()

#define ff/*---------------------------*/first
#define ss/*---------------------------*/second

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(lli)2000000000000
#define MOD/*--------------------------*/(lli)1000000007
#define MAXN/*-------------------------*/200005

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}
lli cnt[MAXN];

int main()
{
	opt;
	lli i,n,k;
	cin >> n >> k;
	vector<lli> v(n),a;
    rep(i,n)
    {
        cin >> v[i];
        cnt[v[i]]++;
    }
    lli Cnt = 0,ans = 0;
    rep(i,MAXN)
    {
        if(cnt[i])
            a.pb(cnt[i]);
    }
    sort(all(a));
    if(a.size() <= k)
    {
        cout << 0 << endl;
        return 0;
    }
    rep(i,a.size()-k)
        ans += a[i];
    cout << ans << endl;
	return 0;
}










Measured memory_bytes: 5620
#include <stdio.h>

int main(void){
    int mon,day,sum;
    while(1){
        scanf("%d %d",&mon,&day);
        sum=0;
        if(mon == 0)
            break;
        mon--;
        while(mon != 0){
        switch(mon){
            case 1:case 3:case 5:case 7:case 8:case 10:case 12:
                sum+=31;
                break;
            case 4:case 6:case 9:case 11:
                sum+=30;
                break;
            case 2:
                sum+=29;
                break;
        }
        mon--;
        }
        sum+=day;
        sum%=7;
        switch(sum){
            case 1:
                printf("Thursday\n");
                break;
            case 2:
                printf("Friday\n");
                break;
            case 3:
                printf("Saturday\n");
                break;
            case 4:
                printf("Sunday\n");
                break;
            case 5:
                printf("Monday\n");
                break;
            case 6:
                printf("Tuesday\n");
                break;
            case 0:
                printf("Wednesday\n");
                break;
        }
        }
    return 0;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 1450555;
const int M = 1155;
const int L = 20;

void solve() {
    ll n;
    cin >> n;

    VI v;
    while (n > 0){
        int x = n%26;
        if (x == 0) x = 26;
        v.PB(x);
        n = (n-x) / 26;
    }

    reverse(ALL(v));

    for (auto now : v){
        cout << char(now+'a'-1);
    }

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
let string_to_list str =
  let rec loop i limit =
    if i = limit then []
    else (String.get str i) :: (loop (i + 1) limit)
  in
  loop 0 (String.length str)

let fwd arr_length n = if n = (arr_length - 1) then 0 else n+1
let prev arr_length n = if n = 0 then arr_length - 1 else n-1
let flip c = if c = 'S' then 'W' else 'S'
let print_chars arr = Array.iter (fun x -> Printf.printf "%c" x) arr; Printf.printf "\n"
           
let fill arr arr_length n by =
  arr.(fwd arr_length n) <- 
    if (arr.(n) == 'S' && by = 'o') || (arr.(n) == 'W' && by = 'x') then
      arr.(prev arr_length n)
    else
      flip arr.(prev arr_length n)

let rec extend answers ans_length cursor ret = match answers with
  | [] -> ret
  | x::rest ->
     fill ret ans_length cursor x;
     extend rest ans_length (cursor+1) ret

let check arr arr_length by n =
  if (arr.(n) == 'S' && by = 'o') || (arr.(n) == 'W' && by = 'x') then
    arr.(fwd arr_length n) = arr.(prev arr_length n)
  else
    arr.(fwd arr_length n) <> arr.(prev arr_length n)

let make_list f t step =
  let rec make_list_inner c t lst =
    if c >= t then lst else make_list_inner (c+step) t (c::lst)
  in
  List.rev (make_list_inner f t [])

let check_all pos_ans length pairs =
  let checks = List.map (fun (x,y) -> check pos_ans length y x) pairs in
  List.fold_left (fun x y -> x && y) true checks

let array_make length a b =
  let ret = (Array.make length a) in
  ret.(length - 1) <- b;
  ret

let solve str =
  let str_list = (string_to_list str) in
  let length = List.length str_list in
  let pairs = List.combine (make_list 0 length 1) str_list in
  let pos_ans = extend str_list length 0 (array_make length 'S' 'S') in
  if check_all pos_ans length pairs then pos_ans else
    let pos_ans = extend str_list length 0 (array_make length 'S' 'W') in
    if check_all pos_ans length pairs then pos_ans else
      let pos_ans = extend str_list length 0 (array_make length 'W' 'W') in
      if check_all pos_ans length pairs then pos_ans else
        let pos_ans = extend str_list length 0 (array_make length 'W' 'S') in
        if check_all pos_ans length pairs then pos_ans else
          [||]
  
let () =
  let _ = read_int() in
  let str = read_line () in
  let ans = solve str in
  if ans = [||] then
    Printf.printf ("-1")
  else
    Array.iter (fun x -> Printf.printf "%c" x) ans;
  Printf.printf "\n"
;;


Measured memory_bytes: 24960
#include <iostream>
using namespace std;
int solve(int p,int q,int r,int a,int n){
	int k=0;
	for(int i=max(r,q/p); i<=a; i++){
		if(i*p==q)k++;
		else if(n!=1)k+=solve(i*p-q,i*q,i,a/i,n-1);
	}
	return k;
}
int main(){
	int p,q,a,n;
	while(cin>>p>>q>>a>>n,p)cout<<solve(p,q,1,a,n)<<endl;
	return 0;
}

Measured memory_bytes: 1160
use itertools::Itertools;
fn main() {
    proconio::input! {
        n: usize,
        xls: [(i64, i64); n],
    }
    let ranges = xls
        .iter()
        .map(|(x, l)| (x - l..x + l))
        .sorted_by_key(|x| x.end)
        .collect_vec();
    let mut count = n;
    let mut cur = ranges[0].end;
    for range in ranges.iter().skip(1) {
        if range.start < cur {
            count -= 1;
        } else {
            cur = range.end;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 7776
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1000000007;
const ll INF=1e15;
const int BIG=1e7;


int par[100001];
int rnk[100001];
int size[100001];
int N;

void shoki(){
    for(int i=0;i<=N;i++) {par[i]=i; rnk[i]=0; size[i]=1;}
}

int sch(int x){
    if(par[x]==x) return x;
    else return par[x]=sch(par[x]);
}

void con(int A,int B){
    A=sch(A);
    B=sch(B);
    if(A==B) return;
    if(rnk[A]>rnk[B]) swap(A,B);
    par[A]=B;
    size[B]+=size[A];
    size[A]=size[B];
    if(rnk[A]==rnk[B]) rnk[B]++;

    return;
}

int is_size(int k){
    return size[sch(k)];
}

bool same(int A,int B){
    return sch(A)==sch(B);
}
int main(){
    int M;
    cin>>N>>M;
    shoki();
    for(int i=0;i<M;i++){
        int x,y,z;
        cin>>x>>y>>z;
        con(x,y);
    }
    unordered_set<int> ans;
    for(int i=1;i<=N;i++) {
        int p=sch(i);
        ans.insert(p);
        //cout<<p<<endl;
    }
        
    cout<<ans.size()<<endl;


}

Measured memory_bytes: 5540
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;

LL a[2005];
LL b[2005][2005];

int main()
{
	int n;
	LL x,sum = 1LL << 60LL;
	cin >> n >> x;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++)
	{
		b[i][0] = a[i];
		for(int k = 1;k <= n - 1;k++)
		{
			int pos = i - k;
			if(pos <= 0) pos += n;
			b[i][k] = min(b[i][k - 1],a[pos]);
		}
	}
	for(int k = 0;k <= n - 1;k++)
	{
		LL ans = 0;
		for(int i = 1;i <= n;i++)
			ans += b[i][k];
		sum = min(sum,ans + k * x);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 31616
import sys

N=int(input())
s=list(map(int,input().split()))

s=s+[10**6]
ans=[0]*N


for i in range (N):
    m=-1
    for j in range (N-i):
        if s[j]==j+1:
            m=j
    if m<0:
        print(m)
        sys.exit()
    
    ans[N-i-1]=m+1
    
    for j in range (m,N):
        s[j]=s[j+1]
        
    
for i in range(N): print(ans[i]) 

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

using vi = vector<int>;

int main()
{
    vi v(13);

    for(auto x : {1, 3, 5, 7, 8, 10, 12}) v[x] = 1;
    for(auto x : {4, 6, 9, 11}) v[x] = 2;
    for(auto x : {2}) v[x] = 3;

    int a, b; cin >> a >> b;

    if(v[a] == v[b]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;


//----------------------------------------------------------------
signed main(){

	ll n;
	cin >> n;
	int u[13] = {0};
	vll d(n);
	rep(i,n){
		ll v;
		cin >> v;
		d[i] = v;
		u[v]++;
		if(v == 0 || u[v] > 2 || u[12] > 1){
			cout << 0 << endl;
			return 0;
		}
	}

	if(n > 24){
		cout << 0 << endl;
		return 0;
	}

	d.pb(0);
	n++;
	vll t(n);
	ll ans = 0;
	ll res;
	int f = 0;
	for(int bit = 0;bit < (1LL<<n);bit++){
		res = INF;
		f = 0;
		int x[25] = {0};
		rep(i,n){
			if(bit & (1LL<<i)){
				t[i] = d[i];
			}else{
				t[i] = 24-d[i];
			}
			x[t[i]]++;
			if(x[t[i]] >= 2){
				f = 1;
				break;
			}
			
		}
		if(f)continue;

		rep(i,n){
			for(int j = i+1;j<n;j++){
				res = min(res,min(abs(t[i]-t[j]),24-abs(t[i]-t[j])));
			}
		}
		ans = max(ans,res);
	}

	cout << ans << endl;	

	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_c
// rm -r -f test;oj dl https://abc054.contest.atcoder.jp/tasks/abc054_d

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

int main()
{
  int x[5];
  for ( int i=0; i<5; i++ )
    scanf("%d", &x[i]);
  for ( int i=0; i<5; i++ )
    if ( x[i]==0 )
      printf("%d\n", i+1);
  return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define MAX 10000000000
#define rep(i,n) for(int i = 0; i < n;i++)
ll v, n, c, e, u, k, ans = MAX,sum;
int digsum(int n) {
    int res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}
int main(void) {
	int n, a, b;cin >> n;
    for(int i = 1;i < n;i++) {
        a = i;b = n - i;
        sum = digsum(a) + digsum(b);
        ans = min(sum, ans);
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
    int A,B,C,S,areaTriangle;
    cin>>A>>B>>C;
    S=(A+B+C)/2;
    areaTriangle=sqrt(S*(S-A)*(S-B)*(S-C));
    cout<<areaTriangle;
}



Measured memory_bytes: 256
a,b=gets.split.map &:to_i
aa=[]
a.times do
  aa<< gets.chomp
end
ab=[]
b.times do
  ab<< gets.chomp
end
jd=true
(a-b+1).times do |i|
  (a-b+1).times do |j|
    jd=true
    b.times do |k|
      b.times do |l|
        if aa[i+k][j+l]!=ab[k][l]
          jd=false
          break
        end
      end
      break if !jd
    end
    break if jd
  end
break if jd
end
puts jd ? :Yes : :No

Measured memory_bytes: 1788
package main

import (
	"fmt"
	"math"
)

func main() {
	var s string
	fmt.Scan(&s)

	countOdd := 0
	countEven := 0
	for i := range s {
		if i%2 == 0 {
			if s[i] == '0' {
				countOdd++
			}
		} else {
			if s[i] == '1' {
				countOdd++
			}

		}
	}
	for i := range s {
		if i%2 == 0 {
			if s[i] == '1' {
				countEven++
			}
		} else {
			if s[i] == '0' {
				countEven++
			}
		}
	}

	fmt.Println(math.Min(float64(countOdd), float64(countEven)))
}


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

string s;
vector<vector<bool>> visited;
vector<vector<set<int>>> dp;

void init() {
	visited = vector<vector<bool>>(210, vector<bool>(210, false));
	dp = vector<vector<set<int>>>(210, vector<set<int>>(210));
}

bool number(int l, int r) {
	if(r <= l) return false;
	int ret = 0;
	for(int i = l; i < r; ++i) {
		ret *= 10;
		if(s[i] < '0' or '9' < s[i]) return false;
		ret += (s[i] - '0');
	}
	// fprintf(stderr, "[%d, %d) : %d\n", l, r, ret);
	throw ret;
}

set<int> dfs(int l, int r) {
	if(r <= l) return {};
	if(visited[l][r]) return dp[l][r];
	if(s[l] == '(') {
		int depth = 0;
		bool flg = 1;
		for(int i = l; i < r; ++i) {
			if(s[i] == '(') {
				depth++;
				continue;
			}
			if(s[i] == ')') {
				depth--;
				continue;
			}
			if(depth == 0) {
				flg = 0;
			}
		}
		if(flg and s[r - 1] == ')') return dfs(l + 1, r - 1);
	}
	// fprintf(stderr, "[%d, %d)\n", l, r);
	try {
		number(l, r);
	}
	catch(int num) {
		dp[l][r].insert(num);
		visited[l][r] = true;
		return dp[l][r];
	}
	set<int> ret;
	int depth = 0;
	for(int i = l; i < r; ++i) {
		if(s[i] == '(') {
			depth++;
			continue;
		}
		if(s[i] == ')') {
			depth--;
			continue;
		}
		if(depth > 0) continue;
		if('0' <= s[i] and s[i] <= '9') continue;
		int lid = l, ldepth = 0;
		for(int j = i - 1; j >= l; --j) {
			if(s[j] == ')') {
				ldepth++;
			}
			if(s[j] == '(') {
				lid = j;
				ldepth--;
			}
			if(ldepth < 0) break;
			lid = l;
		}
		set<int> left = dfs(lid, i);
		int rid = r, rdepth = 0;
		for(int j = i + 1; j < r; ++j) {
			if(s[j] == '(') {
				rdepth++;
			}
			if(s[j] == ')') {
				rid = j + 1;
				rdepth--;
			}
			if(rdepth < 0) break;
			rid = r;
		}
		set<int> right = dfs(i + 1, rid);
		if(s[i] == '+') {
			for(int ll : left) {
				for(int rr : right) {
					ret.insert(ll + rr);
				}
			}
		}
		if(s[i] == '-') {
			for(int ll : left) {
				for(int rr : right) {
					ret.insert(ll - rr);
				}
			}
		}
		if(s[i] == '*') {
			for(int ll : left) {
				for(int rr : right) {
					ret.insert(ll * rr);
				}
			}
		}
		if(s[i] == '/') {
			for(int ll : left) {
				for(int rr : right) {
					if(rr == 0) continue;
					ret.insert(ll / rr);
				}
			}
		}
	}
	dp[l][r] = ret;
	visited[l][r] = true;
	// fprintf(stderr, "[%d, %d)\n", l, r);
	// for(int i : dp[l][r]) {
	// 	cerr << i <<endl;
	// }
	return dp[l][r];
}

int main() {
	while(cin >> s and s != "#") {
		init();
		int n = s.size();
		set<int> ans = dfs(0, n);
		// for(int i : ans) {
		// 	cerr << i <<endl;
		// }
		cout << ans.size() << endl;
	}
	return 0;
}


Measured memory_bytes: 7244
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, l; cin >> n >> l;
    vector<string> v(n);
    rep(i, n) cin >> v[i];
    sort(ALL(v));
    string ans = "";
    rep(i, n) ans += v[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
using namespace std;
typedef int64_t ll;
typedef vector<ll> vll;
int64_t gcd64(int64_t a, int64_t b);
int64_t lcm64(int64_t a, int64_t b);
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll N;
        in >> N;
        vll T(N);
        rep (i, N) {
            in >> T[i];
        }
        
        ll ans = 1;
        rep(i, N) {
            ans = lcm64(ans, T[i]);
        }
        out << ans << endl;
    }
};
void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}

// ユークリッドの互除法：O(log2 max(a,b))
int64_t gcd64(int64_t a, int64_t b) {
    int64_t res = 0;
    if (b == 0) {
        res = a;
    }
    else {
        res = gcd64(b, a % b);
    }
    return res;
}
// 最小公倍数
int64_t lcm64(int64_t a, int64_t b) {
    int64_t res = 0;
    res = a / gcd64(a, b) * b;
    return res;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();


		int cnt = 0;
		int max = 0;
		for (int i = 0; i < s.length(); i++) {
			for (int j = 0; j < s.length() - i; j++) {
				if (s.charAt(i + j) == 'A' || s.charAt(i + j) == 'T' || s.charAt(i + j) == 'G' || s.charAt(i + j) == 'C') {
					cnt++;
				} else {
					break;
				}
			}
			if (max < cnt) {
				max = cnt;
			}
			cnt = 0;
		}

		System.out.println(max);
	}

}

Measured memory_bytes: 23764
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
string strin(){string s;cin>>s;return s;}
char chin(){char c;cin>>c;return c;}
ll lin() {ll x;scanf("%lld",&x);return x;}


int main(){
    int x=in();
    int cnt=1;
    while(x>0){
        x-=cnt;
        cnt++;
    }
    cout<<cnt-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	string s;
	cin >> s;
	int count = 0;
	for(int i = 0; i < s.size(); i++) {
		if(i % 2 == 0 && s[i] == '0') count++;
		else if(i % 2 == 1 && s[i] == '1') count++;
	}
	cout << min(count, (int)s.size() - count) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	int res = 0;
	//res = 1;
	while (A <= B) {
		A *= 2;
		res++;
	}
	cout << res << endl;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n, INT32_MAX);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    int minV = INT32_MAX;
    for(int j = 1; j <= 2; j++){
      if(dp[i - j] + abs(h[i] - h[i - j]) < minV) minV = dp[i - j] + abs(h[i] - h[i - j]);
    }
    dp[i] = minV;
  }
  cout << dp[n - 1];
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int a,b;
    string c;
    while(true){
    cin>>a>>c>>b;
    if(c=="+")
     cout<<a+b<<endl;
    if(c=="-")
     cout<<a-b<<endl;
    if(c=="*")
     cout<<a*b<<endl;
    if(c=="/")
     cout<<a/b<<endl;
     if(c=="?")
     break;
    }
    return 0;
}


Measured memory_bytes: 3148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			List<List<int>> adj = new List<List<int>>();
			for(int i = 0;i < N;i++)
			{
				adj.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToList());
			}

			var ans = WarshallFloyd(adj);

			int ret = 0;
			for(int i = 0;i < N;i++)
			{
				for(int j = 0;j < N;j++)
				{
					if (adj[i][j] != ans[i][j]) ret = -1;
				}
			}
			if (ret == -1) Console.WriteLine(-1);
			else
			{
				long count = 0;
				for(int i = 0;i < N;i++)
				{
					for(int j = i + 1;j < N;j++)
					{
						count += ans[i][j];
					}
				}
				Console.WriteLine(count - minus);
			}
			//Console.ReadLine();
		}

		static long minus;

		public static List<List<int>> WarshallFloyd(List<List<int>> adjacencyMatrix)
		{
			var retMatrix = new List<List<int>>();
			foreach (var a in adjacencyMatrix)
			{
				var list = new List<int>();
				list.AddRange(a);
				retMatrix.Add(list);
			}
			int n = retMatrix.Count;
			minus = 0;
			var dic = new HashSet<int>();
			for (int k = 0; k < n; k++)
			{
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						if (i != k && j != k && i < j &&  adjacencyMatrix[i][j] == retMatrix[i][k] + retMatrix[k][j] && !dic.Contains(i * 400 + j))
						{
							dic.Add(i * 400 + j);
							minus += adjacencyMatrix[i][j];
						}
						retMatrix[i][j] = Math.Min(retMatrix[i][j], retMatrix[i][k] + retMatrix[k][j]);
					}
				}
			}
			return retMatrix;
		}
	}
}

Measured memory_bytes: 24024
N = int(input())
H = [int(h) for h in input().split()]

for i in range(1, N + 1):
    print('node {}: '.format(i), end='')
    print('key = {}, '.format(H[i - 1]), end='')
    if i // 2 > 0:
        print('parent key = {}, '.format(H[i // 2 - 1]), end='')
    if i * 2 <= N:
        print('left key = {}, '.format(H[i * 2 - 1]), end='')
    if i * 2 + 1 <= N:
        print('right key = {}, '.format(H[i * 2 + 1 - 1]), end='')
    print()


Measured memory_bytes: 5720
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	X := nextInt64()
	c := int64(100)
	i := 0

	for c < X {
		c = int64(float64(c) * 1.01)
		i++
	}
	fmt.Println(i)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 1788
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static int col;
        static List<Edge>[] graph;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            graph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray();
            var edges = new List<Edge>();
            
            for (var i = 0; i < n - 1; i++) {
               var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
               var edge = new Edge(){From=--t[0], To=--t[1]};
               
               graph[edge.From].Add(edge);
               graph[edge.To].Add(edge);
               edges.Add(edge);
            }
            
            col = graph.Max(z => z.Count);
            Console.WriteLine(col);
            
            Dfs(0, int.MaxValue, -1);
            
            foreach (var v in edges)
               Console.WriteLine(v.Color);
        }

        static void Dfs(int node, int from, int fromColor)
        {
            var color = 1;
            for (var i = 0; i < graph[node].Count; i++) {
                var edge = graph[node][i];
                var to = edge.From ^ edge.To ^ node;
                if (from == to) continue;
                if (color == fromColor) color++;
                edge.Color = color;
                Dfs(to, node, color);
                color++;
            }
        }
    }

    class Edge
    {
       public int From {get; set;}
       public int To {get; set;}
       public int Color {get; set;}
    }
}


Measured memory_bytes: 37336
#include<iostream>
#include<vector>
#include<string>

using namespace std;

class Fenwick {
public:
  	vector<vector<int>> f;
  	string str;
  
    Fenwick(int n, char s[]) {
      	f.resize(n + 1);
      	str = string(s);
      	for (int i = 0; i <= n; ++i) f[i].resize(26);
      	for (int i = 0; i < n; ++i)
          for (int j = i + 1; j <= n; j += j & (-j))
            f[j][s[i] - 'a']++;
    }
    
    void update(int n, char c) {
      	if (c == str[n-1]) return;
      	for (int i = n; i < f.size(); i += i & (-i)) {
          f[i][c - 'a']++;
          f[i][str[n-1] - 'a']--;
        }
      	str[n-1] = c;
    }
  
    void sum(int n, int arr[]) {
      	for (int i = n; i > 0; i -= i & (-i))
          for (int j = 0; j < 26; ++j)
            arr[j] += f[i][j];
    }
  
    int query(int l, int r) {
      int qa[26] = {}, qb[26] = {}, s(0);
      sum(l - 1, qa);
      sum(r, qb);
      for (int i = 0; i < 26; ++i) 
        if (qa[i] != qb[i]) s++;
      return s;
    }
};

int main() {
  int n, q, t, x, y;
  cin >> n;
  char s[n], c;
  for (int i = 0; i < n; ++i) cin >> s[i];
  Fenwick f(n, s);
  cin >> q;
  while (q--) {
    cin >> t >> x;
    if (t == 1) {
      cin >> c;
      f.update(x, c);
    } else {
      cin >> y;
      cout << f.query(x, y) << '\n';
    }
  }
  return 0;
}

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

int main() {
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for (int i=0; i<s.size(); i++){
        if (s[i] != t[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3924
from sys import stdin

N, M = map(int, stdin.readline().split())
X = list(map(int, stdin.readline().split()))

if N >= M:
    print(0)
    exit()

X.sort()
dists = []

for i in range(M - 1):
    dists.append(X[i + 1] - X[i])

# print(dists)

dists.sort(reverse=True)

ans = 0

for i in range(N - 1, M - 1):
    ans += dists[i]

print(ans)


Measured memory_bytes: 13188
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    ll n;
    cin>>n;
    string s=to_string(n);
    string j;
    ll mn=s.length();
    for(ll i=2;i*i<=n;i++)
    {
        if(n % i == 0)
        {
            s=to_string(i);
            j=to_string(n/i);
            mn=min(mn,(ll)max(s.length(),j.length()));
        }
    }
    cout<<mn;
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

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

#define mmod 1000000007
#define MAXN 333555

const int GP = 1;
const int GB = 2;

long long n;
long long k[MAXN];
long long c[5][MAXN];
vector<int> changed[5];

void fastmod(long long &x) {
    if (x >= mmod) {
        x %= mmod;
    }
}

void reset(int group) {
    for(int i=0; i<changed[group].size(); i++) {
        c[group][changed[group][i]] = 0;
    }
    changed[group].clear();
}

void add(int pos, long long val, int group) {
    for(int x = pos+1; x <= n; x += x & -x) {
        c[group][x] += val;
        fastmod(c[group][x]);
        changed[group].push_back(x);
    }
}

long long sum(int pos, int group) {
    long long s = 0;
    for(int x = pos+1; x > 0; x -= x & -x) {
        s += c[group][x];
        fastmod(s);
    }
    return s;
}

int main() {

    long long p, b;

    scanf("%lld%lld%lld", &n, &p, &b);

    int lastP = 0;
    int lastB = 0;
    for(int i=1; i<=n; i++) {
        scanf("%lld", &k[i]);

        if (i == 1) {
            add(0, 1, GP);
            add(0, 1, GB);
        } else {

            while(lastP+1 < i-1 && k[i] - k[lastP+1] >= p) lastP++;
            while(lastB+1 < i-1 && k[i] - k[lastB+1] >= b) lastB++;

            long long sumP = sum(lastP, GB);
            long long sumB = sum(lastB, GP);

            if (k[i] - k[i-1] < p) {
                reset(GP);
            }
            if (k[i] - k[i-1] < b) {
                reset(GB);
            }

            add(i-1, sumP, GP);
            add(i-1, sumB, GB);
        }
    }

    long long res = sum(n-1, GP) + sum(n-1, GB);
    fastmod(res);

    printf("%lld\n", res);

    return 0;
}

Measured memory_bytes: 16864
import sys,math
if sys.version_info[0]>=3: raw_input=input
N=int(raw_input())
for i in range(N):
    x1,y1,x2,y2,x3,y3=[float(e) for e in raw_input().split()]
    a1=2*x2-2*x1
    b1=2*y2-2*y1
    c1=x1*x1-x2*x2+y1*y1-y2*y2
    a2=2*x3-2*x1
    b2=2*y3-2*y1
    c2=x1*x1-x3*x3+y1*y1-y3*y3
    x=(b1*c2-b2*c1)/(a1*b2-a2*b1)
    y=(c1*a2-c2*a1)/(a1*b2-a2*b1)
    print('%.3f %.3f %.3f'%(x,y,math.hypot(x1-x,y1-y)))


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

using namespace std;

int main() {
	int N,K;
	cin >> N >> K;
	multiset<int>P;
	for (int m = 0;m<N; ++m) {
		int n;
		cin >> n;
		P.insert(n);
	}
	int nAns = 0; 
	auto itr = P.begin();
	for (int i = 0;i<K;++i) {
		nAns += *itr;
		++itr;
	}
	cout << nAns <<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,a,b,c,cc,ans = 0;
    cin >> n >> a >> b;
    rep(i, n + 1){
        cc = 0;
        for (c = i; c > 0;) {
            cc += c % 10;
            c = c / 10;
        }
        if (cc >= a && cc <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MAX = 3e3 + 5;
ll dp[MAX][MAX] = {};
ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	return (x + y + 5 * MOD) % MOD;
}
ll mod_m(ll x, ll y) {
	return x * y%MOD;
}
ll mod_pow(ll x, ll t) {
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v%MOD;
		}
		else {
			return v * v%MOD*x%MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

ll a[MAX];
ll qx[MAX], qy[MAX];
ll row[MAX], ax[MAX];

int main() {
	ll n; ll q;
	cin >> n >> q;
	ll inv2 = mod_inv(2);
	REP(i, 1, n) {
		cin >> a[i];
	}
	REP(i, 1, q) {
		cin >> qx[i] >> qy[i];
	}
	REP(i, 1, n) {
		REP(j, 1, n) {
			if (a[i] > a[j]) {
				dp[i][j] = 1;
			}
		}
	}

	REP(k, 1, q) {
		ll x = qx[k]; ll y = qy[k];

		REP(j, 1, n) {
			if (j != x && j != y) {
				ax[j] = mod_p(mod_m(inv2, dp[x][j]), mod_m(inv2, dp[y][j]));
				row[j] = mod_p(mod_m(inv2, dp[j][x]), mod_m(inv2, dp[j][y]));
			}
		}
		REP(j, 1, n) {
			if (j != x && j != y) {
				dp[x][j] = dp[y][j] = ax[j];
				dp[j][x] = dp[j][y] = row[j];
			}
		}
		dp[x][y] = dp[y][x] = mod_m(inv2, mod_p(dp[x][y], dp[y][x]));
	}
	ll ans = 0;
	REP(i, 1, n) {
		REP(j, i + 1, n) {
			ans = mod_p(ans, dp[i][j]);
		}
	}
	REP(i, 1, q) {
		ans = mod_m(ans, 2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
#define INF 1e9

int main() {
	int N, Y;
	cin >> N >> Y;
	bool ans = false;
	int count10000 = -1, count5000 = -1, count1000 = -1;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j + i <= N; ++j) {
			int k = N - i - j;
			if (10000 * i + 5000 * j + 1000 * k == Y) {
				count10000 = i;
				count5000 = j;
				count1000 = k;
			}
		}
	}
	cout << count10000 << " " << count5000 << " "<< count1000;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val x1 = scanner.nextDouble()
    val y1 = scanner.nextDouble()
    val x2 = scanner.nextDouble()
    val y2 = scanner.nextDouble()
    println(Math.sqrt(Math.pow(x1 - x2, 2.toDouble()) + Math.pow(y1 - y2, 2.toDouble())))
}


Measured memory_bytes: 26944
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n;
	cin >> n;
	int isp[55556] = {};
	int i, j; isp[0] = 1; isp[1] = 1;
	for (i = 2; i < 55556; i++) {
		if (isp[i] == 0) {
			for (j = 2 * i; j < 55556; j += i) {
				isp[j] = 1;
			}
		}
	}
	vector<int>s;
	for (i = 0; i < 55556; i++) {
		if (isp[i] == 0 && i % 5 == 1)s.push_back(i);
	}
	for (i = 0; i < n; i++) {
		cout << s[i] << " ";
	}
	cout << endl;
	char nyaa;
	cin >> nyaa;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

// 最大公約数
ll gcd(ll a, ll b)
{
    if(a%b == 0){
        return(b);
    }
    else{
        return(gcd(b, a%b));
    }
}

// 最小公倍数
ll lcm(ll a, ll b)
{
    return a  / gcd(a, b) * b;
}

int main(void)
{
    ll N, M, g, l, i, j, k, judge=1;
    string S, T;

    cin >> N >> M >> S >> T;

    g = gcd(N,M);
    l = lcm(N,M);

    j = 0; k = 0;
    for(i=1; i<=g; i++){
        if(S[j] != T[k]){
            judge = 0;
            break;
        }

        j += (N/g);
        k += (M/g);
    }

    if(judge==1) cout << l << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 512
def main():
    n, a, b, c = map(int, input().split())
    s = [list(input()) for _ in range(n)]
    num = dict(A=a, B=b, C=c)
    t = a+b+c
    ans = []
    if t == 0:
        print("No")
        return
    if t == 1:
        for i in range(n):
            si = s[i]
            if num[si[0]] == 1:
                num[si[0]] -= 1
                num[si[1]] += 1
                ans.append(si[1])
            elif num[si[1]] == 1:
                num[si[0]] += 1
                num[si[1]] -= 1
                ans.append(si[0])
            else:
                print("No")
                return
        print("Yes")
        print("\n".join(ans))
        return
    for i in range(n-1):
        si = s[i]
        if num[si[0]] == 0 and num[si[1]] >= 1:
            num[si[0]] += 1
            num[si[1]] -= 1
            ans.append(si[0])
        elif num[si[1]] == 0 and num[si[0]] >= 1:
            num[si[0]] -= 1
            num[si[1]] += 1
            ans.append(si[1])
        elif num[si[0]] >= 1 and num[si[1]] >= 1:
            sin = s[i+1]
            if si[0] in sin:
                num[si[0]] += 1
                num[si[1]] -= 1
                ans.append(si[0])
            else:
                num[si[0]] -= 1
                num[si[1]] += 1
                ans.append(si[1])
        else:
            print("No")
            return
    if num[s[n-1][0]] >= 1:
        ans.append(s[n-1][1])
    elif num[s[n-1][1]] >= 1:
        ans.append(s[n-1][0])
    else:
        print("No")
        return
    print("Yes")
    print("\n".join(ans))
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 18876
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    if(A==5){
        if(B==5 && C==7) cout << "YES" << endl;
        else if(B==7 && C==5) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(A==7 && B==5 && C==5) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 256
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

int check(int x) {
  printf("%d\n", x);
  fflush(stdout);
  static char s[10];
  scanf("%s", s);
  if (!strcmp(s, "Vacant")) {
    exit(0);
  } else if (!strcmp(s, "Male")) {
    return 0;
  } else if (!strcmp(s, "Female")) {
    return 1;
  } else {
    assert(0);
  }
}

bool solve() {
  int n;
  if (scanf("%d", &n) != 1) { return false; }
  int L = 0, R = n - 1;
  int tL = check(L);
  int tR = check(R);
  while (L < R) {
    assert((tL + tR + (R - L)) % 2 == 1);
    int M = (L + R) / 2;
    int tM = check(M);
    if ((tL + tM + (M - L)) % 2 == 1) {
      R = M;
      tR = tM;
    } else {
      L = M;
      tL = tM;
    }
  }
  assert(0);
  return true;
}

int main() {
  while (solve());
  return 0;
}

Measured memory_bytes: 852
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[]a = new int [n];
		int sum = 0;
		for(int i= 0; i < n ; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		Arrays.parallelSort(a);
		sum -= a[n-1];
		
		if (sum > a[n-1])
			System.out.println("Yes");
		else
			System.out.println("No");

	}

}


Measured memory_bytes: 23636
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int K = Integer.parseInt(sc.next());
		String S = sc.next();
		if(K >= S.length()) {
			System.out.println(S);
		} else {
			System.out.println(S.substring(0,K)+"...");
		}
	}
}

Measured memory_bytes: 38436