akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    static int N;
    static int[] bit = new int[100000010];

    public static void add(int a, int w) {
        for (int i=a;i<=N;i+=i&(-i)) {
            bit[i]+=w;
        }
    }

    public static int sum(int a) {
        int ret = 0;
        for (int i=a;i>0;i-=i&(-i)) {
            ret+=bit[i];
        }
        return ret;
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = in.nextInt();
        N = n;
        long ans = 0L;
        int[] a = new int[n];
        ArrayList<int[]> list = new ArrayList<int[]>();
        for (int i=0;i<n;i++) {
            int b = in.nextInt();
            int[] c = {b, i+1};
            list.add(c);
        }
        Comparator<int[]> comparator = new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[0], o2[0]);
            }
        };
        Collections.sort(list, comparator);
        for (int i=0;i<n;i++) {
            a[i] = list.get(i)[1];
        }

        for (int i=0;i<n;i++) {
            add(a[i], 1);
            ans += i+1-sum(a[i]);
        }
        // out.println(Arrays.toString(bit));
        out.println(ans);

        out.close();
    }

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

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

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

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

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

    }
}



Measured memory_bytes: 464484
#include<bits/stdc++.h>
using namespace std;
 string s;long long int i,siz;long long int n=0;int ans=0;
int rec(int now_keta,int p3,int p5,int p7,int num){
  if(now_keta==siz){
    if(p3&&p5&&p7){
      if(num<=n){
        ans++;return ans;
      }else{
      return ans;
      }
    }else{
     return ans; 
    }
  }
  if(p3&&p5&&p7){
      if(num<=n){
        ans++;
      }
   }
  rec(now_keta+1,p3+1,p5,p7,num*10+3);
  rec(now_keta+1,p3,p5+1,p7,num*10+5);
  rec(now_keta+1,p3,p5,p7+1,num*10+7);
 return ans;
}
int main(){
 cin>>s;
  siz=s.size();for(i=0;i<siz;i++){
    n=n*10;
    if(s[i] =='1'){n+=1;}else if(s[i] =='2'){n+=2;}else if(s[i] =='3'){n+=3;}else if(s[i] =='4'){n+=4;}else if(s[i] =='5'){n+=5;}else if(s[i] =='6'){n+=6;}else if(s[i] =='7'){n+=7;}else if(s[i] =='8'){n+=8;}else if(s[i] =='9'){n+=9;}
  }
  cout<<rec(0,0,0,0,0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, h, a[MAX_N], b[MAX_N];

signed main(){
	cin >> n >> h;
	ll max_a = 0, ret = 0;
	REP(i, n){
		cin >> a[i] >> b[i];
		max_a = max(max_a, a[i]);
	}
	// cout << max_a << endl;
	sort(b, b+n, greater<ll>());
	REP(i, n){
		if(b[i] > max_a){
			h -= b[i];
			// cout << b[i] << endl;
			ret++;
		}
		if(h <= 0) break;
	}
	if(h > 0) ret += (h % max_a == 0) ? h / max_a : h / max_a + 1;
	cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b,l[1<<21],p[1<<21];
int n,cnt;
int A[22],AA;
int solve(int n,int a,int b){
	int x=a^b;
//	for(int i=0;i<n;i++)if((1<<i)!=x)p[++cnt]=1<<i;
	l[1]=1;
	for(int i=1;i<=n-1;i++){
		for(int j=1;j<=(1<<i)-1;j++)l[j+(1<<i)]=l[j];
		l[1<<i]=i+1;
	}
	for(int i=1;i<=(1<<n)-1;i++)printf("%d ",a),a^=p[l[i]];
	printf("%d ",b);
	return 0;
}
int solve(int n,int a,int b,int AA){
//	printf("%d %d %d %d\n",n,a,b,AA);
	if(AA==1)return solve(n,a,b);
	int O=1<<A[AA];
//	solve(n-1,a,)
	solve(n-1,a,a^O,AA-1);
	solve(n-1,b^O,b,AA-1);
}
int f[1<<21];
int solve(int n){
	if(n==1){
		f[0]=0;
		f[1]=1;
		return 0;
	}
	solve(n-2);
	for(int i=0;i<1<<n-2;i++)f[i+(1<<n-2)]=(1<<(n-2))+f[(1<<n-2)-i-1];
	int A=3,B=2;
	for(int i=0;i<1<<n-2;i++){
		f[(1<<n-1)+i*2]=A*(1<<(n-2))+f[i];
		f[(1<<n-1)+i*2+1]=B*(1<<(n-2))+f[i];
		swap(A,B);
	}
}
int main(){
//	freopen("1.out","w",stdout);
	scanf("%d%d%d",&n,&a,&b);
	int flag=0;
	int x=a^b;
	int tot=0;
	for(int i=0;i<n;i++)if(x&(1<<i))A[++AA]=i,tot++;
	else p[++cnt]=1<<i,flag=i;
	if(tot%2==0){
		printf("NO\n");
		return 0;
	} 
	printf("YES\n");
	if(tot==1){
		p[++cnt]=1<<A[1];
		solve(n,a,b);
		return 0;
	}
	solve(tot);
	if(tot==n){
		if(a==0)for(int i=0;i<1<<n;i++)printf("%d ",f[i]);
		else for(int i=(1<<n)-1;i>=0;i--)printf("%d ",f[i]);
			return 0;
	}
	int X=0,Y=1<<flag;
	for(int i=0;i<1<<tot;i++){
		int x=0;
		if(flag)
		for(int j=1;j<=AA;j++)if((f[i]&(1<<j-1)))x|=1<<A[j];
		solve(n-tot,a^x^X,a^x^Y);
	//	printf("\n%d\n",x);
		swap(X,Y);
	}
}

Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif
    string s;
    while (cin >> s) {
        for (int i = 0; i < (int)s.size(); ++i) {
            if (s[i] == '?') {
                s[i] = 'D';
            }
        }
        cout << s << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 3976
/*
Author : shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    if(n==22)
        cout<<"Christmas Eve Eve Eve"<<endl;
    else if(n==23)
        cout<<"Christmas Eve Eve"<<endl;
    else if(n==24)
        cout<<"Christmas Eve"<<endl;
    else
        cout<<"Christmas"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> SP;
  
  for(int i=0;i<N;i++){
    string Si;
    int Pi;
    
    cin >> Si >> Pi;
    SP.push_back(make_tuple(Si, Pi, i+1));
  }
  
  sort(SP.begin(), SP.end());
  
  vector<tuple<string, int, int, int>> OUT(N);
  
  for(int i=0;i<N;i++){
    get<0>(OUT.at(i)) = get<0>(SP.at(i));
    get<1>(OUT.at(i)) = N-1-i; 
    get<2>(OUT.at(i)) = get<1>(SP.at(i));
    get<3>(OUT.at(i)) = get<2>(SP.at(i));
  }
  
  sort(OUT.begin(), OUT.end());
  
  
  for(int i=0;i<N;i++){
    string x;
    int y,z,w;
    tie(x,y,z,w)=OUT.at(i);
    cout <<w<<endl;  
  }

}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int N;
  cin >> N;
  int ans = 0;
  int ba = 0;
  int a = 0;
  int b = 0;
  rep(i, N){
    string s;
    cin >> s;
    rep(i, s.size() - 1){
      if(s[i] == 'A' && s[i + 1] == 'B') ans++;
    }
    if(s[0] == 'B'){
      if(s[s.size() - 1] == 'A') ba++;
      else b++;
    }else if(s[s.size() - 1] == 'A') a++;
  }
  if(ba){
    if(a && b){
      a--;
      b--;
      ans += ba + 1;
      ans += min(a, b);
    }else if(a){
      ans += ba;
    }else if(b){
      ans += ba;
    }else{
      ans += ba - 1;
    }
  }else{
    ans += min(a, b);
  }
  cout << ans << endl;
  return 0;
}


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

int adj[100][100];
int vertex;
int ans;

int max(int a, int b)
{
    return (a > b ? a : b);
}

void dfs(int v, int num, int *vis)
{
    int i;
    int flag;
    
    flag = 0;
    for (i = 0; i < vertex; i++){
        if (adj[v][i] && vis[i] == 0){
            adj[v][i] =  0;
            vis[i] = 1;
            dfs(i, num + 1, vis);
            adj[v][i] = 1;
            vis[i] = 0;
          }
    }
    if (flag == 0){
        ans = ans > num ? ans : num;
    }
    return;
}

int main(void)
{
    int vis[100];
    int n;
    int i, j;
    int from, to;
    int count[100], mc;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(count, 0, sizeof(count));
        memset(adj, 0, sizeof(adj));
        vertex = 0;
        
        for (i = 0; i < n; i++){
            scanf("%d%d", &from, &to);
            vertex = vertex < from ? from : vertex;
            vertex = vertex < to ? to : vertex;
            from--;
            to--;
            count[from]++;
            count[to]++;
            adj[from][to] = adj[to][from] = 1;
        }
        
        mc = 10000;
        
        for (i = 0; i < vertex; i++){
            if (count[i] != 0){
                mc = mc > count[i] ? count[i] : mc;
            }
        }
        
        ans = 0;
        for (i = 0; i < vertex; i++){
            if (mc >= count[i] - 1){
                memset(vis, 0, sizeof(vis));
                vis[i] = 1;
                if (n == 100 && ans == 9){
                    break;
                }
                dfs(i, 1, vis);
            }
        }
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 444
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

s = s()
w = i()
cnt = 1
t = ""
for i in range(len(s)):
    if (cnt - 1) % w == 0:
        t += s[i]
    cnt += 1

print(t)

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

int main()
{
	string A, B, C;

	cin >> A >> B >> C;

	int a = A.size(), b = B.size();

	if (A[a - 1] == B[0] && B[b - 1] == C[0]) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import scala.io.Source

object Main extends App {
  val inputStrings = Source.stdin.getLines().toList
  val Array(a, b, c, d) = inputStrings.head.split(' ').take(4).map(_.toInt)
  val x = (a + d - 1) / d
  val y = (c + b - 1) / b
  val result = if (x >= y) "Yes" else "No"
  print(result)
}


Measured memory_bytes: 55056
#include <iostream>
#include <vector>
#include <map>
using namespace std;
map<long long, long long> divide(long long n){//素因数分解
    map<long long, long long> res;
    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
int main(){
    int N;
    cin >> N;
    map<long long, long long> m;
    for(int i = 2; i <= N; i++){
        map<long long, long long> t = divide(i);
        for(auto v: t){
            m[v.first] += v.second;
        }
    }
    vector<int> cnt(10000);
    for(auto v: m){
        if(v.second >= 74) cnt[75]++;
        if(v.second >= 24) cnt[25]++;
        if(v.second >= 14) cnt[15]++;
        if(v.second >= 4) cnt[5]++;
        if(v.second >= 2) cnt[3]++;
    }
    int ans = 0;
    ans += cnt[25] * (cnt[3] - 1) + cnt[15] * (cnt[5] - 1) + cnt[5] * (cnt[5] - 1) * (cnt[3] - 2) / 2 + cnt[75];
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;


int main(){
  int n;
  cin >> n;

  int x = n;
  int f = 0;
  while(x>0){
    f += x%10;
    x /= 10;
  }

  cout << (n%f==0 ? "Yes":"No") << endl;
  
}


Measured memory_bytes: 3564
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val ps = new Array[Int](n)
    for (i <- ps.indices) {
      ps(i) = sc.nextInt()
    }

    var ans = 0
    for (i <- 1 until n - 1) {
      val arr = Array(ps(i - 1), ps(i), ps(i + 1))
      if (ps(i) != arr.min && ps(i) != arr.max) ans += 1
    }

    println(ans)
  }
}

Measured memory_bytes: 25788
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		char[] t = br.readLine().toCharArray();
		br.close();

		char[] ss = new char[s.length * 2];
		System.arraycopy(s, 0, ss, 0, s.length);
		System.arraycopy(s, 0, ss, s.length, s.length);

		for (int i = 0; i < t.length; i++) {
			boolean flg = true;
			for (int j = 0; j < t.length; j++) {
				if (ss[i + j] != t[j]) {
					flg = false;
					break;
				}
			}
			if (flg) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 21460
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % 13;
        x = (x * x) % 13;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    string s;

    static ll dp[100010][13];

    cin >> s;

    dp[0][0] = 1;

    for (int i = 0; i <= s.size(); i++)
    {
        int c;

        if (s[i] == '?')
        {
            c = -1;
        }
        else
        {
            c = s[i] - '0';
        }

        for (int j = 0; j < 10; j++)
        {
            if (c != -1 && c != 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;
        }
    }

    cout << dp[s.size()][5] << endl;
}

Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {

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

		double Hrad = 30 * (H + M / 60.0);
		double Mrad = 360 * (H + M / 60.0);

		double C = A * A + B * B - 2 * A * B * Math.cos(Math.toRadians(Hrad - Mrad));

		C = Math.sqrt(C);
		System.out.println(C);
	}

}


Measured memory_bytes: 35716
loop do
  n = gets.to_i
  break if n == 0
  max = -100_000
  max_n = -100_000
  r = 0
  n.times do
    m = gets.to_i
    max_n = [max_n, m].max
    r = [r + m, 0].max
    max = [max, r].max
  end
  puts max_n > 0 ? max : max_n
end

Measured memory_bytes: 8768
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;cin>>S>>T;
  if(S.size()>T.size()){
    cout<<"GREATER"<<endl;
  }
  else if(T.size()>S.size()){
    cout<<"LESS"<<endl;
  }
  else{
    bool flag=true;
    for(int i=0;i<S.size();i++){
      if(S.at(i)>T.at(i)){
        cout<<"GREATER"<<endl;
        flag=false;
        break;
      }
      if(S.at(i)<T.at(i)){
        cout<<"LESS"<<endl;
        flag=false;
        break;
      }
    }
    if(flag){
      cout<<"EQUAL"<<endl;
    }
  }
}
      


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

		for(int i=0; i<N; i++){
			for(int j=0; j<D; j++){
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		}


		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#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(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (d <= t * s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int main()
{
    int N, Y;
    cin >> N >> Y;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; i + j <= N; j++)
        {
            int x = Y - i * 10000 - j * 5000;
            if (Y == i * 10000 + j * 5000 + (N - i - j) * 1000)
            {
                cout << i << ' ' << j << ' ' << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 888
program average_length
  implicit none
  integer :: n, i, j
  real(8) :: x(8) = 0.d0, y(8) = 0.d0, m = 0.d0
  read(*,*) n
  do i = 1, n
    read(*,*) x(i), y(i)
  end do
  do i = 1, n-1
    do j = i+1, n
      m = m+d2(x(i),y(i),x(j),y(j))
    end do
  end do
  m = 2.d0*m/real(n,8)
  write(*,*) m
contains
  real(8) function d(x,y)
    real(8) :: x, y
    d = sqrt(x*x+y*y)
  end
  real(8) function d2(x1,y1,x2,y2)
    real(8) :: x1, y1, x2, y2
    d2 = d(x2-x1,y2-y1)
  end
end program average_length

Measured memory_bytes: 256
import heapq
def dijkstra(V, edges, s):
    inf=float('inf')

    dist=[inf]*V
    dist[s]=0
    
    que=[[0,s]]
    heapq.heapify(que) #最小値を管理 [dist[i],i]となる要素

    while  que:
        p=heapq.heappop(que) #距離が最小のものを取り出す
        dis=p[0]
        v=p[1]
        if dist[v] <dis:
            continue
        for edge in edges[v]:
            to_v=edge[0]
            cost=edge[1]
        
            if dist[to_v] > dist[v] + cost:
                dist[to_v]=dist[v]+cost
                heapq.heappush(que,[dist[to_v], to_v])
    
    return dist

def main():
    n=int(input())
    edges=[[] for _ in range(n)]
    for i in range(n-1):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        edges[a].append([b,c])
        edges[b].append([a,c])
    q,k=map(int,input().split())
    k-=1
   
    dist=dijkstra(n,edges,k)
    for i in range(q):
        x,y=map(int,input().split())
        x-=1
        y-=1
        print(dist[x]+dist[y])
if __name__=='__main__':
    main()

Measured memory_bytes: 55480
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto np = readln.split.to!(long[]);
    auto N = np[0];
    auto P = np[1];
    if (N == 1) {
        writeln(P);
        return;
    }
    long r = 1;
    auto p = P;
    for (long x = 2; x^^2 <= P; ++x) {
        long y;
        while (p%x == 0) {
            ++y;
            p /= x;
        }
        r *= x^^(y/N);
    }
    writeln(r);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<ll> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }

    ll ans=0;
    ll sum=0;
    int k=0;
    for(i=0; i<n; i++) {
        if(i>0) sum-=a[i-1];
        if(k<i) k=i;
        while(k<n) {
            if((sum+a[k])==(sum^a[k])) {
                sum=(sum^a[k]);
                k++;
            }
            else {
                break;
            }
        }
        ans += (k-i);
    }
    printf("%lld\n", ans);

    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 k;
  cin >> k;
  queue<int64> que;
  REP(i,9)que.push(i+1);
  REP(i,k-1){
    int64 x = que.front();
    que.pop();
    if(x % 10 > 0)
      que.push(x * 10 + x % 10 - 1);
    que.push(x * 10 + x % 10);
    if(x % 10 < 9)
      que.push(x * 10 + x % 10 + 1);
  }
  ANS(que.front());
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//*************** Constraints are always Imaginary,I'm real **************
using namespace std;
#define int long long 
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define fi first
#define se second
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
int32_t main()
{
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);
          // #ifndef ONLINE_JUDGE
          // freopen("input.txt","r",stdin);
          // freopen("output.txt","w",stdout);
          // #endif
          int h,w,n;
          cin>>h>>w>>n;
          int x=max(h,w);
          cout<<((n-1)/x)+1;
          return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
	#define int long long
	#define pi pair<int,int>
	#define ff first
	#define ss second
	#include "string"

	const int M = 1e9 + 7;
	int mod( int m ) {
	   m %= M;
	   return (m + M) % M;
	}

	void brute(int *a,int n,int k){
		int ans = -1e9;
		for(int i=0;i<(1<<n);i++){
			if(__builtin_popcount(i) != k)
				continue;
			int tt = 1;
			for(int j=0;j<n;j++){
				if(i&(1<<j))
					tt *= a[j];
			}
			ans = max(ans,tt);
		}
		cout<<ans<<endl;
	}

	int32_t main(){
		boost;
		int n,k;
		cin>>n>>k;
		int a[n];
		vector<int>pos,neg;
		int zero = 0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(a[i] == 0)
				zero++;
			if(a[i] < 0)
				neg.push_back(a[i]);
			else
				pos.push_back(a[i]);
		}
		//brute(a,n,k);
		sort(pos.rbegin(),pos.rend());
		sort(neg.rbegin(),neg.rend());
		int ans = 1;
			
		if(neg.empty()){
			for(int i=0;i<k;i++)
				ans = mod(ans*pos[i]);
			cout<<ans<<endl;
			return 0;
		}
		else if(pos.empty()){
			if(k%2 == 0)
				sort(neg.begin(),neg.end());
			for(int i=0;i<k;i++)
				ans = mod(ans*neg[i]);
			if(k%2 && zero > 0)
				ans = 0;
			cout<<ans<<endl;
			return 0;
		}
		else if(k == n){
			for(int i=0;i<n;i++)
				ans = mod(ans*a[i]);
			cout<<ans<<endl;
			return 0;
		}

		multiset<int>s,t;
		for(int &i :pos)
			s.insert(i);
		for(int &i:neg)
			t.insert(i);

		if(k%2 == 1){
			k--;
			int tt = *s.rbegin();
			ans = mod(ans*tt);
			s.erase(s.find(tt));
		}

		while(k>0){
			int tn = -1;
			int tp = -1;
			int fp ,fn;
			if(t.size() > 1){
				fn = *t.begin();
				t.erase(t.find(fn));
				int tt = *t.begin();
				tn = fn*tt;
			}

			if(s.size() > 1){
				fp = *s.rbegin();
				s.erase(s.find(fp));
				int tt = *s.rbegin();
				tp = fp*tt;
			}
			//cout<<tn<<" "<<tp<<endl;
			if(tn == -1 && tp == -1){
				ans = mod(ans * mod(fp*fn));
			}
			else if(tn > tp){
				ans = mod(ans * mod(tn));
				t.erase(t.find(*t.begin()));
				if(tp != -1)
					s.insert(fp);
			}
			else{
				ans = mod(ans * mod(tp));
				s.erase(s.find(*s.rbegin()));
				if(tn != -1)
					t.insert(fn);
			}
			k -= 2;
		}
		cout<<ans<<endl;
	}



Measured memory_bytes: 15848
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    double[] arr = new double[N];
    double A = 0;
    double B = 1;
    for (int i=0;i<N;i++){
      double n = scan.nextDouble();
      arr[i] = n;
      A+=n;
      B*=n;
    }
    double a = 0;
    for (int i=0;i<N;i++){
      a += B/arr[i];
    }
    System.out.println(B/a);
  }
}

Measured memory_bytes: 24020
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String n = sc.next();
      	String newn ="";
      	for(int i = 0; i < 3; i++){
	      	if(n.charAt(i) == '1'){
            	newn += "9";
            }else if(n.charAt(i) == '9'){
            	newn += "1";
            }else{
            	newn += String.valueOf(n.charAt(i));
            }
        }
      	System.out.println(newn);
    }
}

Measured memory_bytes: 38532
N,A,B,C=map(int,input().split())
L=[int(input()) for _ in range(N)]
from itertools import product

ans=10**18

for pattern in product(range(4),repeat=N):
    MP=0
    take=[0]*3
    for index,length in zip(pattern,L):
        if index==3:
            continue
        if take[index]!=0:
            MP+=10
        take[index]+=length
    if take[0]!=0 and take[1]!=0 and take[2]!=0:
        MP+=abs(A-take[0])
        MP+=abs(B-take[1])
        MP+=abs(C-take[2])
        ans=min(MP,ans)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const char letters[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int diff[62];char pw[129],query[129];
int ask(){int x;printf("? %s\n",query);fflush(stdout);return !scanf("%d", &x)?-1:x;}
int main()
{
  int total=0,len=0;
  rep(i,62){rep(j,128){query[j]=letters[i];}query[128]=0;diff[i]=128-ask();total+=diff[i];}
  rep(i,62)
  {
    if(len==0){len=diff[i];rep(j,diff[i])pw[j]=letters[i];}
    else
    {
      for(int k=diff[i],l=0;k>=1;--k)
      {
        int r=len;
        while(l<r)
        {
          int mid=(l+r+1)/2;
          rep(j,mid)query[j]=pw[j];
          rep(j,k)query[mid+j]=letters[i];
          query[mid+k]=0;
          if(ask()==total-mid-k)l=mid;else r=mid-1;
        }
        ++len;
        for(int j=len;j>l;--j){pw[j]=pw[j-1];}
        pw[l]=letters[i];
      }
    }
  }
  pw[len]=0;
  return printf("! %s\n", pw),0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w,a,b;
    cin >> w >> a >> b;
    if(a<b) {
        if (b - (w + a) <= 0) {
            cout << 0 << endl;
        } else cout << b - (w + a) << endl;
    }
    else if(b<a){
            if (a- (w + b) <= 0) {
                cout << 0 << endl;
            } else cout << a - (w + b) << endl;
    }
    else if(a==b){
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll sum=0;
    rep(i,n){
        sum=(sum+modpow(i+1,mod-2))%mod;
    }
    ll ans=0;
    rep(i,n){
        ans=(ans+sum*a[i])%mod;
        sum=(sum+modpow(i+2,mod-2))%mod;
        sum=(sum-modpow(n-i,mod-2))%mod;
    }
    ans=(ans+mod)%mod;
    rep(i,n){
        ans=(ans*(i+1))%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    string s;
    int n, k;

    cin >> n >> s >> k;

    for (int i=0; i<s.size(); i++) {
        if (s[k-1]!=s[i]) cout << "*";
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

int main() {
    int n,x[100],d = 100000000;
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> x[i];
    }
    for(int i = 1;i <= 100;i++ ) {
        int c = 0;
        for(int j = 0;j < n;j++) {
            c += (x[j]-i) * (x[j]-i);
        }
        d = min(d,c);
    }
    cout << d << endl;
}

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

int main() {
  int n, sum;
  cin >> n;
  vector<int> d(n);
  for(int i=0; i<n; i++) cin >> d[i];
  for(int l=0; l<n; l++) for (int r=l+1; r<n; r++) sum += d[l] * d[r];
  cout << sum << endl;
}

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

//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

ll pow(ll x, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

using namespace std;
int main(void){

    ll n;
    cin >> n;
    ll ans = 0;
    REP(i,n){
      ll num = i+1;
      ll div = n/num;
      // 初項num、公比num、項数divの和
      ans += div * (div + 1) * num / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
N,K=map(int,input().split())
table=[[0]*K for i in range(K)]#W=1
C=0
for i in range(N):
    x,y,z=input().split()
    x = int(x)
    y=int(y)
    if z=='B':
        y +=K
    x %=(2*K)
    y %=(2*K)
    t = (x//K +y//K)%2
    x%= K
    y%=K
    if t:
        table[y][x]-=1
    else:
        table[y][x]+=1
        C+=1
B=N-C
#print(table)
pr=[[0]*(K+1) for i in range(K)]
for i in range(K):
    for j in range(K):
        pr[j][i+1]=pr[j][i]+table[j][i]
#print(pr)
pr2=[[0]*(K+1) for i in range(K+1)]
for j in range(K):
    for i in range(K):
        pr2[j+1][i+1]=pr2[j][i+1]+pr[j][i+1]
#print(pr2)
ans = 0
for i in range(K+1):
    for j in range(K+1):
        #s=pr2[K][K]-pr2[i-1][K] -pr2[K][j-1]+2*pr2[i-1][j-1]
        s =pr2[i][K] +pr2[K][j]-2*pr2[i][j]
        #白で塗った時に差し引き難点もらえるか
        #t=pr2[K][K]-s#黒で塗る
        #print(s,t,s-t,C-s)
        ans = max(ans,C-s,B+s)
print(ans)

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n) cin>>a[i];
    int s=0;
    rep(i,n)s^=a[i];
    rep(i,n) a[i]^=s;
    rep(i,n)cout<<a[i]<<endl;
    return 0;
}

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

typedef long long int ll;
const	int maxn = 2e5+100;
struct SECTION {
	ll l,r;
	SECTION() {}
	SECTION(ll l,ll r):l(l),r(r) {}
	bool operator<(const SECTION& oth) const {
		if(l==oth.l) return r < oth.r;
		return l < oth.l;
	}
	bool operator==(const SECTION& oth) const { return l==oth.l&&r==oth.r; }
};
map<ll,int> idx;
vector<SECTION> sec[maxn];
ll N,X,D;

int main() {
	std::ios::sync_with_stdio(false);
	ll kl=0,kr=0,key,cnt = 0,ans = 0;
	cin >> N >> X >> D;
	if(D==0) {
		if(!X) cout << 1 << endl;
		else cout << N+1 << endl;
		return 0;
	} else if(D<0) {
		X*=-1;
		D*=-1;
	}
	ll l,r;
	for(int i=0; i<=N; i++) {
		key = i*X;
		ll bb = key%abs(D);
		l = r = key/abs(D);
		l+=kl; r+=kr;
		if(l>r) swap(l,r);
		if(idx[bb]==0ll) idx[bb] = ++cnt;
		sec[idx[bb]].push_back({--l,r});
		kl+=i,kr+=N-i-1;
	}
	for(int i=1; i<=cnt; i++) {
		SECTION tp;
		sort(sec[i].begin(),sec[i].end());
		tp = sec[i][0];
		for(SECTION now: sec[i]) {
			if(now.l <= tp.r) tp.r = max(tp.r,now.r);
			else {
				ans += tp.r-tp.l;
				tp = now;
			}

			if(now == sec[i].back()) {
				ans += tp.r-tp.l;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n,q;
    string s;
    cin>>n>>q>>s;
    vector<int> dat(n+10),ans(q);//0-indexed [l,r]
    for(int i=1;i<n;i++){
        if(s[i-1]=='A'&&s[i]=='C'){
            dat[i]++;
        }
        dat[i]+=dat[i-1];
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        l--;r--;
        ans[i]=dat[r]-dat[l];
    }
    rep(i,q){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4300
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<int> b(N + 1);
    vector<int> w(N + 1);
    REP(i, N) {
        if (S[i] == '#') {
            b[i + 1] = b[i] + 1;
        }
        else {
            b[i + 1] = b[i];
        }
    }

    REV(i, N, 1) {
        w[i-1] = w[i];
        if (S[i] == '.') w[i-1]++;
    }

    int res = INF;
    REP(i, N + 1) {
        res = min(res, w[i] + b[i]);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4340
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

int main() {
	cin >> A >> B;
	cout << max(A + B, max(A * B, A - B));
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int p[] =new int[n];

		int cnt=0;
		for(int i=0; i<n; i++) {
			p[i]=sc.nextInt();

		}
		for(int i=0; i<n; i++) {
			if(p[i] != i+1) cnt++;
		}

		if(cnt<=2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		sc.close();
	}
}


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

int main() {
    double n;
    cin >> n;
    double ans;

    if (int(n) % 2 == 0) {
        ans = 0.5;
    } else ans = (n+1)/(2*n);

    printf("%.10f",ans);
    return 0;
}

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

using ll = long long;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);

  sort(p.begin(),p.end());

  int ans = 0;
  for (int i = 0; i < K; i++)
  {
    ans += p[i];
  }

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


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef pair<int,int> P;
int n,m,s,t,A[N],used[N],depth[N];
vector<int> G[N];
vector<P> ans;

void dfs(int x,int d,int prev){
  depth[x]=d;
  for(int i=0;i<G[x].size();i++){
    int nx=G[x][i];
    if(nx==prev)continue;
    if(!used[nx]){
      used[nx]=true;
      dfs(nx,d+1,x);
      if(!A[nx])
	ans.push_back(P(min(x,nx),max(x,nx)));
      A[x]+=A[nx];
    }
    else if(d>depth[nx])A[nx]--,A[x]++;
  }
}

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  used[0]=1;
  dfs(0,0,0);
  sort(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++)
    cout<<ans[i].first<<' '<<ans[i].second<<endl;
  return 0;
}

Measured memory_bytes: 7288
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int C(int x, int y) {
	return (x + y - 1) / y;
}
int main() {
	int d, g;
	cin >> d >> g;
	g /= 100;
	V p(d), c(d);
	rep(i, d) {
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}
	int ans = upper;
	rep(bit, 1 << d) {
		vector<bool> zenkan(d, false);
		rep(i, d) {
			if (1 & (bit >> i)) zenkan[i] = true;
		}
		int score = 0;
		int pro = 0;
		rep(i, d) {
			if (zenkan[i]) {
				int I = i + 1;
				score += p[i] * I;
				score += c[i];
				pro += p[i];
			}
		}
		for (int i = d - 1; i >= 0; i--) {
			if (zenkan[i]) continue;
			int I = i + 1;
			int husoku = g - score;
			if (husoku <= 0) break;
			int tokitai = C(husoku, I);
			int toku = min(tokitai, p[i]);
			score += toku * I;
			if (toku == p[i]) score += c[i];
			pro += toku;
		}
		chmin(ans, pro);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_J

#include <bits/stdc++.h>

using namespace std;

long long MOD = 1e9 + 7;

long long f[1010][1010];

int main() {
    long long n;//ボール
    long long k;//箱
    cin >> n >> k;

    f[0][0] = 1;
    for (int i = 0; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            f[i][j] = f[i][j - 1];
            if (i >= j) {
                f[i][j] = (f[i][j] + f[i - j][j] + MOD) % MOD;
            }
        }
    }
    
    cout << f[n][k] << endl;
    return 0;
}

/*。
 * 区別できないn個のボールを区別できないi個以下
 * の箱に入れる方法をf[n][i]とする。
 * n個のボールをちょうどk個の箱に入れる方法は
 * g[n][k]=f[n][k]-f[n][k-1]
 * で与えられる。
 * g[n][k]の状況を作るにはまずk個の箱に1個ずつ
 * ボールを入れ，次に残ったn-k個のボールをk個
 * 以下の箱に入れればよい。n-k>=0ならば
 * g[n][k]=f[n-k][k]
 * =f[n][k]-f[n][k-1]
 * 移項して
 * f[n][k]=f[n][k-1]+f[n-k][k]
 * n-k<0のときはg[n][k]=0となり，
 * f[n][k]=f[n][k-1]
 *
 */


Measured memory_bytes: 10988
#include <iostream>
#include <cstdio>

using namespace std;
string str;

char leftKey[] = {'q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', 'v', 'b'};

bool inLeft(char c) {
  for (int i = 0; i < sizeof(leftKey); i++) {
    if (c == leftKey[i]) {
      return true;
    }
  }
  return false;
}

void solve() {
  int isLeft = inLeft(str[0]);
  int cnt = 0;
  
  for (int i = 1; i < str.size(); i++) {
    if (isLeft != inLeft(str[i])) {
      isLeft = inLeft(str[i]);
      cnt++;
    }
  }
  printf("%d\n", cnt);
}

int main() {
  while (true) {
    getline(cin, str);
    if (str == "#") {
      return 0;
    }
    solve();
  }
}

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

using namespace std;

vector<int> FindCount(const string &str)
{
    vector<int> count(26, 0);
    for (const auto &ch : str) {
        count[ch - 'a'] += 1;
    }
    return count;
}

void Merge(const vector<int> &source, vector<int> &dest)
{
    for (size_t i = 0; i < dest.size(); i += 1) {
        dest[i] = min(dest[i], source[i]);
    }
}

string GetString(const vector<int> &count)
{
    string str = "";
    for (size_t i = 0; i < count.size(); i += 1) {
        str.append(count[i], 'a' + i);
    }
    return str;
}

int main()
{
    int n;
    cin >> n;
    cin.get();

    vector<int> count(26, (1 << 30));
    for (auto i = 0; i < n; i += 1) {
        string headline;
        getline(cin, headline);
        Merge(FindCount(headline), count);
    }

    cout << GetString(count) << "\n";
    return 0;
}


Measured memory_bytes: 256
import numpy as np
from operator import itemgetter

N, M = input().split()
N, M = int(N), int(M)
C = [input().split() for i in range(M)]

for i, c in enumerate(C):
  C[i] = [int(c[0]), int(c[1])]
  C[i].append(i)

C_sorted = sorted(C, key = lambda x: (x[0], x[1]))

counter = 1
current = 1

for c in C_sorted:
  if current < c[0]:
    counter = 1
  pref = str(c[0])
  num = str(counter)
  number = ''
  for i in range(6 - len(pref)):
    number += '0'
  number += pref
  for i in range(6 - len(num)):
    number += '0'
  number += num

  c.append(number)
  counter += 1
  current = c[0]

C_reversed = sorted(C_sorted, key = lambda x: x[2])

for c in C_reversed:
  print(c[3])

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

int main(){
    int X,T,N;
    cin >> N >> X >> T ;
    int c=1;
    if(N<=X){
        cout << T << endl;
    }else{
        while(1){
            N-=X;
            c++;
            if(N<=X) break;
    }
    cout << c*T << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <math.h>

using namespace std;

int main(){
	int N, M;
	long int *a = NULL;
	long int *b = NULL;
	long int *c = NULL;
	long int *d = NULL;

	long int dist;
	long int min_dist = pow(10,8) + pow(10,8) + 1;
	int min_num;

	cin >> N >> M;

	a = new long int[N];
	b = new long int[N];
	c = new long int[M];
	d = new long int[M];

	for(int i = 0; i < N; i++){
		cin >> a[i] >> b[i];
	}
	for(int j = 0; j < M; j++){
		cin >> c[j] >> d[j];
	}

	for(int i = 0; i < N; i++){
		min_dist = pow(10,8) + pow(10,8) + 1;
		for(int j = 0; j < M; j++){
			dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
			if(dist < min_dist){
				min_dist = dist;
				min_num = j;
			}
		}
		cout << min_num+1 << endl;
	}

	delete[] a;
	delete[] b;
	delete[] c;
	delete[] d;

	return 0;
}

Measured memory_bytes: 256