akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

#define INF 10000000

using namespace std;

double calcDest (int xi, int xj, int yi, int yj)
{
    double dx, dy;
    dx = xi - xj;
    dy = yi - yj;
    return sqrt( dx * dx + dy * dy );
}

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

    double sum_dest = 0;

    int field[N][2];
    for ( int i = 0; i < N; ++i ) {
        cin >> field[i][0] >> field[i][1];
    }

    vector<int> Index(N);
    for ( int i = 0; i < N; ++i ) {
        Index[i] = i;
    }

    int count = 0;
    do { 
        for ( int i = 1; i < N; ++i ) {
            sum_dest += calcDest(field[Index[i]][0],field[Index[i-1]][0],field[Index[i]][1],field[Index[i-1]][1]);
        }
        count++;
    } while ( next_permutation(Index.begin(), Index.end()) );

    double ans = sum_dest / (double)count;

    //cout << ans << endl;
    printf("%.10lf\n", ans);

    return 0;
}

Measured memory_bytes: 256
s = input()
if s == "SUN":
    ans = 7
elif s == "MON":
    ans = 6
elif s == "TUE":
    ans = 5
elif s == "WED":
    ans = 4
elif s == "THU":
    ans = 3
elif s == "FRI":
    ans = 2
else:
    ans = 1
print(ans)


Measured memory_bytes: 38256
from itertools import*
from numpy import array
n,c=map(int,input().split())

l1=[]
l2=[]
for i in range(n):
    x,v=map(int,input().split())
    l1.append(x)
    l2.append(v)
#print(l1,l2)

ll=array([0]+l1)
lll=array([0]+list(accumulate(l2)))
lr=array([0]+[c-i for i in l1][::-1])
llr=array([0]+list(accumulate(l2[::-1])))
x=lll-ll
y=llr-lr
for i in range(1,n+1):
    x[i]=max(x[i-1],x[i])
    y[i]=max(y[i-1],y[i])
z=array([min(ll[::-1][i],lr[i])for i in range(n+1)])
print(max(x[::-1]+y-z))


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];

  int ans = 1, x = a[0];
  set<int> se;

  while (x != 2) {
    if (se.count(x) > 0) {
      ans = -1;
      break;
    }
    se.insert(x);
    x = a[x - 1];
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 5376
H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)

Measured memory_bytes: 61260
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        byte[] s = scan.next().getBytes();
        int m = s.length / 2;
        if (s.length % 2 == 0) {
            for (int i = 0; i < m; i++) {
                if (s[m - 1 - i] != s[m] || s[m + i] != s[m]) {
                    System.out.println(m + i);
                    return;
                }
            }
        }
        else {
            for (int i = 0; i < m + 1; i++) {
                if (s[m  - i] != s[m] || s[m + i] != s[m]) {
                    System.out.println(m + i);
                    return;
                }
            }
        }
        System.out.println(s.length);
    }
}


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

int main() {
  int ans = 0;
  string s;
  cin >> s;

  int g = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == 'S'){
      g = 0;
    }
    else{
      g++;
    }

    ans = max(ans, g);
  }

  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <vector>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");


int main(){
    ll a, b;
    cin >> a >> b;
    if(a*b % 2 == 1 || a*b*3 % 2 == 1){
      print("Yes");
    }else{
      print("No");
    }
   
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int n;
    cin >> n;
    vector<int> l(2*n,0);
    rep(i,2*n)cin >> l[i];
    sort(l.begin(),l.end());
    ll res = 0;
    for(int i = 0;i<2*n;i += 2)res += l[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
def euclid(a, b):
  if b == 0:
    return a
  else:
    return euclid(b, a%b)
A,B,C,D=map(int,input().split())
if A%C==0:
  k=A//C
else:
  k=(A//C)+1
if B%C==0:
  t=B//C
else:
  t=(B//C)
n=t-k+1
if A%D==0:
  a=A//D
else:
  a=(A//D)+1
b=B//D
m=b-a+1
mi=(C*D)//euclid(C, D)
if A%(C*D)==0:
  c=A//mi
else:
  c=(A//mi)+1
d=(B//mi)
r=d-c+1
s=n+m-r
print(B-A+1-s)

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

int main() {
  int h,n;
  cin>>h>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int sum=0;
  for(int i=0;i<n;i++){
    sum=sum+a.at(i);
  }
  if(sum>=h){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("lepus.in", "r", stdin); freopen("lepus.out", "w", stdout);
#define __lcm(a, b) a * b / __gcd(a, b)
#define up_b upper_bound
#define low_b lower_bound
#define pcnt(i) __builtin_popcount(i)

using namespace std;

const long long MXN = 1e6 + 1;
const long long MAXN = 1e3 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

inline void JUDGE(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,-1,0,0}; int dy[]= {0,0,1,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, a[MXN], b[MXN];

int main() {

    JUDGE();

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = i;
    }
    ll mn = b[a[1]];
    ll ans = 1;
    for(int i = 2; i <= n; i++) {
        if(mn > a[i]) {
            ans ++;
        }
        mn = min(mn, b[a[i]]);
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 5888
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vl a(3);
  rep(i, 3) cin >> a[i];
  ll ans = INT_MAX;
  rep(i, 3) {
    rep(j, 3) {
      rep(k, 3) {
        if (i == j || j == k || i == k) continue;
        ans = min(ans, abs(a[i] - a[j]) + abs(a[j] - a[k]));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

public class GFG
{
    static public void Main()
    {
        try
        {
            var n = Console.ReadLine();
            //var input1 = Console.ReadLine().Split(' ');
            //var n = int.Parse(input1[0]);
            //var L = int.Parse(input1[1]);

            //var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

            SubString(n);
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }

    static void SubString(string s)
    {
        for (int i = 0; i < s.Length-1; i++)
        {
            if (s[i] == s[i + 1])
            {
                Console.Write((i + 1) + " " + (i + 2));
                return;
            }
            if (i + 2 < s.Length && s[i] == s[i + 2])
            {
                Console.Write((i + 1) + " " + (i + 3));
                return;
            }
        }

        Console.Write("-1 -1");

    }

    static bool UnBal(string s)
    {
        if (s.Length <= 1)
            return false;

        var ss = s.ToCharArray();
        int n = ss.Length;
        var group = ss.GroupBy(x => x).Select(g => new { l = g.Key, count = g.Count() });

        foreach (var cc in group)
        {
            if (cc.count > (n / 2))
                return true;
        }
        return false;

    }

}

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

int main()
{
	int n;
	while (cin >> n, n) {
		vector<int> key(n);
		for (int i = 0; i < n; i++) {
			cin >> key[i];
		}
		string str;
		cin >> str;
		for (int i = 0; i < str.length(); i++) {
			if (str[i] >= 'a' && str[i] <= 'z') {
				if (str[i] - key[i % n] >= 'a')
					str[i] -= key[i % n];
				else {
					str[i] += 'A' - 'a' + 26 - key[i % n];
					if (str[i] < 'A')
						str[i] += 'a' - 'A' + 26;
				}
			}
			else {
				if (str[i] - key[i % n] >= 'A')
					str[i] -= key[i % n];
				else {
					str[i] += 'a' - 'A' + 26 - key[i % n];
					if (str[i] < 'a')
						str[i] += 'A' - 'a' + 26;
				}
			}
		}
		cout << str << endl;
	}
	return 0;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  vi a(n);
  ll sum = 0;
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }

  if(sum < k){
    cout << n << endl;
    return 0;
  }

  sort(all(a));

  ll s = 0, ans = n;
  for(int i = n-1; i >= 0; i--){
    if(s + a[i] < k){
      s += a[i];
    }else{
      ans = min(ans, (ll)i);
    }
  }

  cout << ans << 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 P = pair<int, int>;
using ll = long long;

int main(){
	int s, w;
  	cin >> s >> w;
  	
  	cout << ((s > w) ? "safe" : "unsafe") << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  String S = sc.nextLine();
	  
	  if (S.contains("A") && S.contains("B")) {
          System.out.println("Yes");
      }
	  else {
		  System.out.println("No");
	  }
	  
	  sc.close();
	  
  }
}

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

int main() {
  int n, cnt = 0;
  vector<int> d1(100);
  vector<int> d2(100);
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    cin >> d1.at(i) >> d2.at(i);
  }
  
  for (int i = 0; i < n - 2; i++) {
    if (d1.at(i) == d2.at(i) && d1.at(i + 1) == d2.at(i + 1) && d1.at(i + 2) == d2.at(i + 2)) {
    	cnt = 1;
     	break;
    }
   }
  
    if (cnt){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}

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

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

Measured memory_bytes: 6272
n = 0
x = 0
cnt = 0

while True:
    
    I = input().split()
    n = int(I[0])
    x = int(I[1])
    if n == 0 and x == 0:
        break
    
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if (i + j + k) == x:
                    cnt += 1
                    continue
    print(cnt)
    cnt = 0

Measured memory_bytes: 7712
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template<typename T>
void dump(T a, int n) { for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' '); }

template<typename T>
void dump(T a) { dump<T>(a, a.size()); }

constexpr int INF = INT_MAX;

int main(void) {
	for (int N, M; cin >> N >> M, N;) {
		VI C(M), X(N);
		for (auto &c : C) { cin >> c; }
		for (auto &x : X) { cin >> x; }

		// 
		VVI dp(N + 1, VI(256, INF));
		dp[0][128] = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 256; j++) if(dp[i][j] != INF) {
				for (auto c : C) {
					int y = max(0, min(255, j + c));
					int sq = (X[i] - y) * (X[i] - y);
					dp[i + 1][y] = min(dp[i + 1][y], dp[i][j] + sq);
				}
			}
		}

		cout << *min_element(dp[N].begin(), dp[N].end()) << endl;
		
	}

	return 0;
}

Measured memory_bytes: 21996
# coding: utf-8
def get_ln_inputs():
    return input().split()


def map_list(fn, xs):
    return list(map(fn, xs))


def get_ln_int_inputs():
    return map_list(int, get_ln_inputs())


def main():
    R = get_ln_int_inputs()[0]
    G = get_ln_int_inputs()[0]
    print(R + 2* (G - R))
    return


main()

Measured memory_bytes: 3316
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Enumerable.Repeat(0, n)
                                .Select(x => int.Parse(Console.ReadLine()) - 1)
                                .ToArray();
            bool[] isTouched = new bool[n];
            int idx = 0, cnt = 0;
            bool canTwo = false;
            while (true)
            {
                cnt++;
                isTouched[idx] = true;
                int newIdx = a[idx];
                Console.Error.WriteLine("{0} -> {1}", idx, newIdx);
                if (newIdx == 1)
                {
                    canTwo = true;
                    break;
                }
                else if (idx == newIdx || isTouched[newIdx])
                {
                    canTwo = false;
                    break;
                }
                idx = newIdx;
            }
            Console.WriteLine(canTwo ? cnt : -1);
        }
    }
}


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

int main(void){
    int n,k; cin >> n >> k;
    int h[n+1];
    ll dp[n+1];
    for(int i=1; i<=n; i++) cin >> h[i];

    dp[1]=0;
    for(int i=2; i<=n; i++){
        ll v=1000000000;
        for(int l=1; l<=min(k,i-1); l++){
            v=min(v,dp[i-l]+abs(h[i]-h[i-l]));
        }
        dp[i]=v;
    }

    cout << dp[n] << endl;
}

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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int N;
    string S;
    cin >> N >> S;
    int cnt = 0;
    REP(i, N-2){
        // if (S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') cnt++;
        if (S.substr(i, 3) == "ABC") cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

void rotate(string& a,string& b,string& c,string& d)
{
	string temp=a;
	a=b;
	b=c;
	c=d;
	d=temp;
}
void turnx(vector<string>& d)
{
	rotate(d[0],d[2],d[5],d[3]);
}
void turny(vector<string>& d)
{
	rotate(d[0],d[4],d[5],d[1]);
}
void turnz(vector<string>& d)
{
	rotate(d[1],d[3],d[4],d[2]);
}
void turnmin(vector<string>& d)
{
	vector<string> res=d;
	for(int i=0;i<6;i++){
		for(int j=0;j<4;j++){
			res=min(res,d);
			turnz(d);
		}
		(i&1?turnx:turny)(d);
	}
	d=res;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<vector<string> > ds(n,vector<string>(6));
		for(int i=0;i<n;i++)
			for(int j=0;j<6;j++)
				cin>>ds[i][j];
		
		for(int i=0;i<n;i++)
			turnmin(ds[i]);
		
		sort(ds.begin(),ds.end());
		ds.erase(unique(ds.begin(),ds.end()),ds.end());
		
		cout<<n-ds.size()<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.io.*;

/**
 * Created by Ayushi on 22 Mar 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();
        float n = Integer.parseInt(temp);
        br.close();

        float a = n/3;
        float ans = a * a * a;
        System.out.println(ans);
    }
}


Measured memory_bytes: 20180
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
}



Measured memory_bytes: 35736
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const ll MOD = 1e9 + 7;
int n;
vector<vector<int>> adj;
vector<bool> vis;
pair<ll, ll> dfs(int s)
{
    vis[s] = true;
    vector<pair<ll, ll>> tmp;
    pair<ll, ll> ans;
    for(auto &i : adj[s])
    {
        if(!vis[i])
        {
            tmp.pb(dfs(i));
        }
    }
    ll tot = 1, tb = 1;
    for(auto i : tmp)
    {
        tot *= (i.f + i.s);
        tot %= MOD;
        tb *= i.f;
        tb %= MOD;
    }
    ans = {tot, tb};
    return ans;
}
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    adj.assign(n, vector<int>());
    F0R(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].pb(b); adj[b].pb(a);
    }
    // for(auto i : adj)
    // {
    //     for(auto j : i)
    //     {
    //         cout << j << " ";
    //     }
    //     cout << "\n";
    // }
    vis.assign(n, false);
    pair<ll, ll> res = dfs(0);
    cout << (res.f + res.s)%MOD;
    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int> h(n); for (auto& item : h)cin >> item;

	vector<int> dp(n); dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; ++i) {
		int case_1 = dp[i - 1] + abs(h[i - 1] - h[i]);
		int case_2 = dp[i - 2] + abs(h[i - 2] - h[i]);
		dp[i] = case_1 < case_2 ? case_1 : case_2;
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc143/tasks/abc143_a
#include <iostream>

template <typename T>
T max(T a, T b)
{
	return a > b ? a : b;
}

int main()
{
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);

	int window_width, curtain_width;
	const int curtain_count = 2;

	std::cin >> window_width >> curtain_width;

	int required_width = window_width - curtain_count * curtain_width;

	std::cout << max(0, required_width);
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0

for i in range((len(a) + 1 )// 2) :
    alice += max(a)
    a.remove(max(a))
    if len(a) != 0 :
        bob += max(a)
        a.remove(max(a))
print(alice - bob)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a[3005];
int main(void){
    int n,ans=0;cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int main()
{
    int A, B, C;
    int K;
    int mul;

    cin >> A >> B >> C;
    cin >> K;
    mul = 1 << K;

    cout << max( { A * mul + B + C, A + B * mul + C, A + B + C * mul } ) << endl;

    return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin>>A>>B>>C;
  int count=0;
  bool end=true;
  if(A==B && B==C && A%2==0){
    cout<<-1<<endl;
  } //無限の場合
  else if(A==B && B==C && A%2==1){
    cout<<0<<endl;
  }
  else{
    while(end){
      if(A%2+B%2+C%2==0){
        int a = A/2;
        int b = B/2;
        int c = C/2;
        A=b+c;
        B=c+a;
        C=a+b;
        count++;
      }
      if(A%2+B%2+C%2>=1){
        end=false;
    }
    } //while終わり
    cout<<count<<endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string input;
        while ((input = Console.ReadLine()) != null)
        {
            string[] s = input.Split(' ');
            int[] a = new int[4];
            int[] b = new int[4];
            for (int i = 0; i < 4; i++)
            {
                a[i] = int.Parse(s[i]);
            }
            input = Console.ReadLine();
            s = input.Split(' ');
            for (int i = 0; i < 4; i++)
            {
                b[i] = int.Parse(s[i]);
            }
            int hit = 0;
            int blow = 0;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (i == j) continue;
                    if (a[i] == b[j])
                    {
                        blow++;
                        
                    }
                }
                 if (a[i] == b[i])
                {
                    hit++;
                }
            }
            Console.WriteLine(hit + " " + blow);
        }
    }
}

Measured memory_bytes: 5572
N = int(input())

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if i > N/i:
                break
            if num % i == 0:
                divisor_list.append(i)

        return divisor_list

A = make_divisor_list(N)

B = []
ans = float("inf")

for a in A:
    b = int(N/a)
    c = max(a,b)
    ans = min(ans,len(str(c)))

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define MAX 1000000000000000000
int main() {
  long long  a;
  double tmp;
  cin >> a >> tmp;
  long long b = tmp*100.0+0.5;
  long long ans = a*b;
  cout << ans/100 << endl;
}

Measured memory_bytes: 3156
package main

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

func mpow(x int, n int) int {
	result := 1
	for n != 0 {
		if n&1 == 1 {
			result *= x
			result %= 1000000007
		}
		x *= x
		x %= 1000000007
		n >>= 1
	}
	return result
}

func main() {
	maxA := 1000000

	N := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	sieve := make([]int, maxA+1)
	sieve[0] = -1
	sieve[1] = -1
	for i := 2; i <= maxA; i++ {
		if sieve[i] != 0 {
			continue
		}
		sieve[i] = i
		for j := i * i; j <= maxA; j += i {
			if sieve[j] == 0 {
				sieve[j] = i
			}
		}
	}

	lcmFactors := map[int]int{}
	for i := 0; i < N; i++ {
		t := map[int]int{}
		a := A[i]
		for a != 1 {
			t[sieve[a]]++
			a /= sieve[a]
		}
		for k, v := range t {
			if lcmFactors[k] < v {
				lcmFactors[k] = v
			}
		}
	}

	lcm := 1
	for k, v := range lcmFactors {
		for i := 0; i < v; i++ {
			lcm *= k
			lcm %= 1000000007
		}
	}

	result := 0
	for i := 0; i < N; i++ {
		result += lcm * mpow(A[i], 1000000007-2)
		result %= 1000000007
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 11136
#include "iostream"

using namespace std;

int main() {
  int n;
  cin >> n;
  int pre;
  cin >> pre;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    ans += pre < a;
    pre = a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
long long int solve(int W,int w[],long long int v[],int n,long long int **dp)
{
    if(dp[W][n]!=-1)
        return dp[W][n];

    if(W<=0)
        return 0;
    if(n<=0)
        return 0;
    if(w[n]>W)
        return dp[W][n]=solve(W,w,v,n-1,dp);
    else
         return dp[W][n]=max(solve(W-w[n],w,v,n-1,dp)+v[n],solve(W,w,v,n-1,dp));



}
int main()
{
    int n,W;
    cin>>n>>W;
    int w[n+1];
    long long int v[n+1];
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    long long int **dp=new long long int *[W+1];
    for(int i=0;i<=W;i++)
        dp[i]=new long long int[n+1];
    for(int i=0;i<=W;i++)
        for(int j=0;j<=n;j++)
            dp[i][j]=-1;
    cout<<solve(W,w,v,n,dp)<<endl;
    return 0;

}


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

#define ll long long
#define N 110
int n; ll x; 
ll len[N], tot[N]; 
ll res;

void DFS(ll l, ll r, int cur)
{
	//printf("%lld %lld %d\n", l, r, cur);
	if (cur < 0 || l > x) return;  
	if (r <= x) 
	{
		res += tot[cur]; 
		return;
	}
	ll mid = (l + r) >> 1;
	if (mid <= x) ++res;
	DFS(l + 1, mid - 1, cur - 1);
	DFS(mid + 1, r - 1, cur - 1);
}

int main()
{
	len[0] = 1;
	for (int i = 1; i <= 50; ++i)
		len[i] = 2 * len[i - 1] + 3;
	tot[0] = 1;
	for (int i = 1; i <= 50; ++i)
		tot[i] = 2 * tot[i - 1] + 1;
	while (scanf("%d%lld", &n, &x) != EOF)
	{
		res = 0;
		DFS(1, len[n], n); 
		printf("%lld\n", res); 
	}
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  string s="No";
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n){
        s="Yes";
        i=10;
        break;
      }
    }
  }
  cout << s << endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int H,W;
  cin>>H>>W;
  vector<vector<char>>S(H,vector<char>(W));
  int sum=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>S[i][j];
      if(S[i][j]=='#')sum++;
    }
  }
  int dx[4]={0,1,-1,0};
  int dy[4]={1,0,0,-1};
  bool ok=false;
  queue<pii>q;
  q.push({0,0});
  vector<vector<bool>>used(H,vector<bool>(W,false));
  vector<vector<int>>d(H,vector<int>(W,0));
  while(q.size()){
    int x=q.front().first;
    int y=q.front().second;
    q.pop();
    if(x==W-1&&y==H-1){
      ok=true;
      break;
    }
    if(used[y][x])continue;
    used[y][x]=true;
    for(int i=0;i<4;i++){
      int X=x+dx[i];
      int Y=y+dy[i];
      if(0<=X&&X<W&&0<=Y&&Y<H&&S[Y][X]!='#'){
        d[Y][X]=d[y][x]+1;
        q.push({X,Y});
      }
    }
  }
  if(ok)cout<<H*W-d[H-1][W-1]-1-sum<<endl;
  else cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import           Data.Array
import           Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe
import qualified Data.Vector           as V
import qualified Data.Vector.Mutable   as M

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

main=do
    getLine
    a <- getIntList
    let cnt = runST $ do
            vec <- V.thaw $ V.replicate m 0
            forM_ a $ \ai ->
                forM_ (primeFactor ai) $ \j ->
                    M.modify vec (+1) j
            V.freeze vec
    putStrLn$
        if V.and $V.map (<=1) cnt
        then "pairwise coprime"
        else if foldl1 gcd a == 1
            then  "setwise coprime"
            else  "not coprime"
m = 10^6+1

table :: V.Vector Int
table = runST $ do
    vec <- V.thaw $ V.fromList [0..m]
    forM_ (takeWhile (\i -> i*i < m) [2..]) $ \i -> do
        arri <- M.read vec i
        when (arri >= i)$
            forM_ (takeWhile (\j -> i*j < m) [i..]) $ \j -> do
                v <- M.read vec (i*j)
                when (v == i*j) $ M.write vec (i*j) i
    V.freeze vec



primeFactor :: Int -> [Int]
primeFactor 1 = []
primeFactor n = if null prev || head prev /= p
    then p:prev
    else prev
    where p = table V.! n
          prev = primeFactor (n `div` p)


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

using namespace std;

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

int n,s[55];

signed main()
{
    n=read();
    for (int i=1;i<=n;i++) s[i]=read();
    int sum=0;
    for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) sum+=s[i]*s[j];
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200005
#define LOG         20
#define mod         1000000007
using namespace std;
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,o,z,ans=0,sum=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<=60;i++){
        z=0;
        o=0;
        for(j=0;j<n;j++){
            if(a[j]%2==0){
                z++;
            }
            else{
                o++;
            }
            a[j]=a[j]/2;
        }
        ans=pow(2,i);
        ans=ans%mod;
        ans=ans*o;
        ans=ans%mod;
        ans=ans*z;
        ans=ans%mod;
        sum+=ans;
        sum=sum%mod;
    }
    cout<<sum;
}

Measured memory_bytes: 2560
import numpy as np
N = int(input())
lst = [int(x) for x in input().split()]

lst2 = np.zeros((max(lst), N))
for idx, n in enumerate(lst):
    lst2[:n,idx] = 1

ret = 0
for x in lst2:
    flg = True
    for y in x:
        if flg and y == 1:
            ret += 1
            flg = False
        elif y == 0:
            flg = True
print(ret)

Measured memory_bytes: 21540
// AOJ 0643 Trunk Road
// 2018.3.28 bal4u

#include <stdio.h>

#define ABS(a)  ((a)>=0?(a):-(a))

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

int a[26][26];

int main()
{
	int h, w, r, c, m, n, x, s, ans;

	h = in(), w = in();
	for (r = 0; r < h; r++) for (c = 0; c < w; c++) a[r][c] = in();

	ans = 0x50505050;
	for (m = 0; m < h; m++) for (n = 0; n < w; n++) {
		s = 0;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) {
			x = ABS(m-r); if (ABS(n-c) < x) x = ABS(n-c);
			s += x*a[r][c];
		}
		if (s < ans) ans = s;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N, M;
	cin >> N >> M;
	int sum = 100*(N-M) + 1900*M;
	int ans = sum * pow(2, M);
	cout << ans << endl;
}


Measured memory_bytes: 256
def get_second(a):
	if len(a) == 1:
		return 0
	else:
		return a[1][0]

n = int(input())
a = [int(v) for v in input().split()]
nums = [{}, {}]
for i, v in enumerate(a):
	if v in nums[i % 2]:
		nums[i % 2][v] += 1
	else:
		nums[i % 2][v] = 1
evens = sorted([(v, k) for k, v in nums[0].items()], reverse=True)
odds = sorted([(v, k) for k, v in nums[1].items()], reverse=True)
if evens[0][1] != odds[0][1]:
	print(n - evens[0][0] - odds[0][0])
else:
	print(n - max(evens[0][0] + get_second(odds), get_second(evens) + odds[0][0]))

Measured memory_bytes: 20764
while True:
	m, f, r = map(int, input().split())

	if (m == -1 and f == -1 and r == -1):
		break

	if (m == - 1 or f == -1):
		print('F')
	elif (m + f >= 80):
		print('A')
	elif (65 <= m + f < 80):
		print('B')
	elif (50 <= m + f < 65):
		print('C')
	elif (30 <= m + f < 50):
		if (r >= 50):
			print('C')
		else:
			print('D')
	else:
		print('F')

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

int main(){
  string S;
  cin >> S;
  int K=S.size();
  char pre=S[0];
  
  for(int i=1;i<S.size();i++){
    if(S[i]==pre){
      K--;
      i++;
      pre = '0';
    }
    else pre = S[i];
  }
  
  cout << K << endl;
  return 0;
}


Measured memory_bytes: 640
import sys

def main():
    N = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))

    rest = 0
    count = 0
    for a,b in zip(A,B):
        if rest > 0:
            count += min(a,rest)
            a -= rest
            if a <= 0:
                rest = b
                continue
        if a < b:
            rest = b-a
            count += a
        else:
            count += b
            rest = 0
    count += min(A[-1],rest)
    print(count)

if __name__=='__main__':
    main()

Measured memory_bytes: 19376
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define inf 1000000000000001
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j;
    cin>>n;
    vector<ll> v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    vector<ll> pre(n,0),ans(n,0);
    pre[0]=v[0];
    for(i=1;i<n;i++)
    {
        pre[i]=pre[i-1]^v[i];
    }
    for(i=0;i<n;i++)
    {
        ans[i]=pre[n-1]^v[i];
        cout<<ans[i]<<" ";
    }
    
    return 0;
     
}

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    i64 n, k;
    cin >> n >> k;
    vector<i64> a(n);
    for(auto& x : a){
        cin >> x;
        --x;
        x %= k;
    }
    vector<i64> r(n + 1, 0);
    for(i64 i = 0; i < n; ++i)
        r[i + 1] = (r[i] + a[i]) % k;

    map<i64,vector<i64>> v;
    for(i64 i = 0; i < n + 1; ++i)
        v[r[i]].emplace_back(i);

    i64 ans = 0;
    for(i64 i = 0; i < n; ++i){
        i64 mo = r[i] % k;
        auto it_1 = lower_bound(v[mo].begin(), v[mo].end(), i);
        auto it_2 = lower_bound(v[mo].begin(), v[mo].end(), i + k);
        ans += distance(it_1, it_2) - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s;
	for(int i=0;i<4;i++){
		string t="";
		if(i%2==0)t+='S';
		else t+='W';
		if(i%3==0)t+='S';
		else t+='W';
		for(int i=1;i<n-1;i++){
			if(t[i]=='S'){
				if(s[i]=='o')t+=t[i-1];
				else{
					if(t[i-1]=='S'){
						t+='W';
					}
					else{
						t+='S';
					}
				}
			}
			else{
				if(s[i]=='x')t+=t[i-1];
				else{
					if(t[i-1]=='S'){
						t+='W';
					}
					else{
						t+='S';
					}
				}
			}
		}
		if(t[0]=='S'){
			if(s[0]=='x'&&t[1]==t[n-1])continue;
			if(s[0]=='o'&&t[1]!=t[n-1])continue;
		}
		else{
			if(s[0]=='x'&&t[1]!=t[n-1])continue;
			if(s[0]=='o'&&t[1]==t[n-1])continue;
		}
		if(t[n-1]=='S'){
			if(s[n-1]=='x'&&t[0]==t[n-2])continue;
			if(s[n-1]=='o'&&t[0]!=t[n-2])continue;
		}
		else{
			if(s[n-1]=='x'&&t[0]!=t[n-2])continue;
			if(s[n-1]=='o'&&t[0]==t[n-2])continue;
		}
		cout << t << endl;
		return 0;
	}
	cout << -1 << endl;
}


Measured memory_bytes: 748
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}else if(a>b){
		cout<<"a > b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
return 0;
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        for (int i = 2; i < S.length(); i= i + 2) {
            String sub = S.substring(0,S.length() - i);
            if(isSS( sub )){
                System.out.println(sub.length());
                break;
            }
        }

    }
    private static boolean isSS(String str){

        String pre = str.substring(0, str.length() / 2);
        String post = str.substring(str.length() / 2 , str.length());

        boolean result = true;
        for (int i = 0; i < pre.length(); i++) {
            if (pre.charAt(i) != post.charAt(i)) {
                result = false;
                break;
            }
        }
        return result;
    }
}


Measured memory_bytes: 22996
N = int(input())
A = list(map(int,input().split()))

mod = 10**9 + 7

from collections import defaultdict

B = [defaultdict(int) for i in range(N)]
C = defaultdict(int)

for x in range(N):
    a = A[x]
    for i in range(2,int(a**0.5)+1):
        while a%i==0 and a>0:
            B[x][i]+=1
            a//=i
            #print(a)
            C[i]=max(C[i],B[x][i])
    #print(a)
    if a>1:
        B[x][a]+=1
        C[a] = max(C[a],B[x][a])
#print(B,C)
l = 1
for key in C:
    l*=pow(key,C[key],mod)
    l%=mod

ans = 0
for i in range(N):
    b = l
    for key in B[i]:
        c = pow(key,B[i][key],mod)
        b *= pow(c,mod-2,mod)
    ans+=b
    ans%=mod

print(ans)

Measured memory_bytes: 54876
#include<stdio.h>

int p[100],m[100][100];
void M(int n){
  int i,l,j,k,b;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l - 1;
      m[i][j] = 100000;
      for(k=i;k<j;k++){
        b = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
        if(m[i][j]>b) m[i][j]=b;
      }
    }
  }
}

int main(){
  int n,i,j;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  M(n);
  printf("%d\n",m[1][n]);

  return 0;
}



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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            int result = 0;
            /*
            for (int i = 0; i < 30; i++)
            {
                if(n < Math.Pow(k, i))
                {
                    result = i;
                    break;
                }
            }
           */

           //解説のやり方
            while(n > 0)
            {
                n = n / k;
                result++;
            }
            Console.WriteLine(result);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

const int MX = 5000 * 200000;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int xy = max(x, y);
    int ans = MX;
    rep(i, xy+1) {
        int c0 = 2 * i, a0 = max(0, x - i), b0 = max(0, y - i);
        chmin(ans, a * a0 + b * b0 + c * c0);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<map>

int const N = 2e5 + 5;

int a[N];
int n;

typedef std::pair<int, int> pii;

void out_pii(pii x) {
	std::cerr << x.first << ' ' << x.second << '\n';
}

void remax(pii x, pii& mx, pii& cmx) {
	if(x.second <= cmx.second) 
		return ;
	if(x.second > mx.second) 
		cmx = mx, mx = x;
	else 
		cmx = x;
}

std::map<int, int> M1;
std::map<int, int> M2;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin >> n;
	for(int i = 1; i <= n; ++i)
		std::cin >> a[i];

	M1.clear();
	M2.clear();

	for(int i = 1; i <= n; i += 2) 
		if(M1.count(a[i]) == 0)
			M1[a[i]] = 1;
		else 
			M1[a[i]]++;
	
	for(int i = 2; i <= n; i += 2) 
		if(M2.count(a[i]) == 0)
			M2[a[i]] = 1;
		else 
			M2[a[i]]++;

	std::pair<int, int> mx1, cmx1;
	for(auto& k : M1) 
		remax(std::make_pair(k.first, k.second), mx1, cmx1);

	std::pair<int, int> mx2, cmx2;
	for(auto& k : M2) 
		remax(std::make_pair(k.first, k.second), mx2, cmx2);

	int ans = 0;
	if(mx1.first != mx2.first) 
		ans = n - mx1.second - mx2.second;
	else {
		ans = std::max(cmx1.second + mx2.second, cmx2.second + mx1.second);
		ans = n - ans;
	}
	std::cout << ans << '\n';
}


Measured memory_bytes: 5376