akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int[] wa = new int[n];
        int[] va = new int[n];
        for(int i=0; i<n; i++){
            wa[i] = Integer.parseInt(sc.next());
            va[i] = Integer.parseInt(sc.next());
        }
        
        long[] dp = new long[w+1];
        for(int i=0; i<n; i++){
            for(int j=w; j>=0; j--){
                if(wa[i]+j<=w && dp[j+wa[i]] < dp[j]+va[i]){
                    dp[j+wa[i]] = dp[j]+va[i];
                }
            }
        }
        
        long ans = 0;
        for(int i=0; i<dp.length; i++){
            ans = Math.max(ans, dp[i]);
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int r;
	cin >> r;
	cout << 3 * r * r;

	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V,int NV> class SegTree_1 {
public:
	vector<V> val;
	static V const def=0;
	// static V const def=1LL<<60; min
	V comp(V l,V r){ return max(l,r);};
	
	SegTree_1(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=comp(v,val[entry]);
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_1<ll,1<<20> st;

int N;
int H[201010];
ll A[201010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>H[i];
	ll ma=0;
	FOR(i,N) {
		cin>>A[i];
		A[i]+=st.getval(0,H[i]);
		ma=max(ma,A[i]);
		st.update(H[i],A[i]);
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 18944
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

const int MAX_N = 100005;

class Edge {
public:
  int nxt, to;
} e[MAX_N];

int fa[MAX_N], head[MAX_N], cnt, id[MAX_N];

void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
}

int N, dep[MAX_N], vis[MAX_N], K;

void dfs(int u, int v) {
  dep[u] = dep[v] + 1;
  for (int i = head[u]; i; i = e[i].nxt)
    dfs(e[i].to, u);
}

bool cmp(int x, int y) {
  return dep[x] > dep[y];
}

void dfs1(int u) {
  vis[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt)
    if (!vis[e[i].to])
      dfs1(e[i].to);
}

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &fa[i]);
    if (i != 1) addedge(fa[i], i);
    id[i] = i;
  }

  int res = fa[1] != 1;

  dfs(1, 0);

  sort(id + 1, id + N + 1, cmp);

  for (int i = 1; i <= N; ++i)
    if (!vis[id[i]] && dep[id[i]] > K + 1) {
      int u = id[i], temp = K - 1;
      while (temp) u = fa[u], temp--;
      dfs1(u), res++;
    }

  printf("%d\n", res);
  return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

int main(){
	ll n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	if(a[n - 1] == 0 && k % 2){
		cout << 0 << '\n';
		return 0;
	}
	int sol = 1;
	if(a[n - 1] <= 0 && k % 2){
		for(int i = n - 1;  i >= n - k; i--){
			sol = (sol * 1LL * a[i] + MOD) % MOD;
		}
		cout << sol << '\n';
		return 0;
	}

	ll i = 0, j = n - 1;
	if(k % 2){
		sol = (sol * 1LL *  a[j]) % MOD;
		j--;
		k--;
	}
	k /= 2;
	for(int p = 0; p < k; p++){
		ll neg = (a[i] * 1LL * a[i + 1]);
		ll pos = (a[j] * 1LL * a[j - 1]);
		if(neg >= pos){
			sol = (sol * 1LL * (neg % MOD)) % MOD;
			i += 2;
		}else{
			sol = (sol * 1LL * (pos % MOD)) % MOD;
			j -= 2;
		}
	}
	cout << (sol + MOD) % MOD << '\n';
}


Measured memory_bytes: 4464
require 'mathn'

$<.each_line do |line|
	*l, v1, v2 = line.split(',').map(&:to_i)

	meet = l.inject(&:+) / (v1 + v2) * v1
	sum = 0
	l.each.with_index(1) do |len, i|
		if meet <= sum += len
			p i
			break
		end
	end
end

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

int N;
int cases[10][10]; // cases[head][tail]: 先頭がhead、末尾がtailの場合の数

int main(){

	cin >> N;

	for (int i=1; i<=N; i++) {
		int tail = i % 10;

		int head = i;
		while(head >= 10) {
			head /= 10;
		}

		cases[head][tail]++;
	}

	ll ans = 0;
	for (int i=0; i<=9; i++) {
		for (int j=0; j<=9; j++) {
			ans += cases[i][j] * cases[j][i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	int A, B, K; cin >> A >> B >> K;
	int cnt = 0;
	for (int i = max(A, B); i >= 1; i--) {
		if (A%i == 0 && B %i == 0)cnt++;
		if(cnt == K){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

inline int count(ll mask, int n) {
    int ret = 0;
    for(int i = 0; i < n; ++i)
        if(mask & 1<<i)
            ret++;
    return ret;
}

ll dp[1<<21] = {1};
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cin >> a[i][j];
    ll ALL = (1<<n)-1;
    for(ll mask = 0; mask <= ALL; mask++) {
        int cnt = count(mask, n);
        for(int i = 0; i < n; i++) {
            if((mask & 1<<i) && a[cnt-1][i])
                dp[mask] = (dp[mask] + dp[mask ^ 1<<i]) % mod;
        }
    }
    cout << (dp[ALL]+mod)%mod;
    return 0;
}


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

using namespace std;

int main() {

	vector<int> a(3,0);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());

	cout << a[0] << " " << a[1] << " " << a[2] << endl;
}


Measured memory_bytes: 3148
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;
    
    int getFst(int x, int dig) {
        int dv = 10 ^^ (dig - 1);
        x /= dv;
        
        return x % 10;
    }
    
    int getLst(int x) {
        return x % 10;
    }
    
    immutable int len = n.to!string.length.to!int;
    immutable int nfst = getFst(n, len);
    
    int getNr(int fst, int lst, int dig) {
        if (dig == 1) {
            return fst == lst && fst <= n ? 1 : 0;
        }
        
        if (dig > len
            || (dig == len && fst > nfst)) {
            return 0;
        }
        
        if (dig < len || fst < nfst) {
            return 10 ^^ (dig-2);
        }
        
        int pw1 = 10 ^^ (dig-1);
        int pw2 = 10 ^^ (dig-2);
        int tot = 0;
        foreach (ins; 0 .. pw2) {
            tot += fst * pw1 + ins * 10 + lst <= n ? 1 : 0;
        }
        
        return tot;
    }
    
    
    long ans = 0;
    foreach (x; 1 .. 10) {
        foreach (y; 1 .. 10) {
            foreach (d1; 1 .. len + 1) {
                foreach (d2; 1 .. len + 1) {
                    ans += getNr(x, y, d1).to!long * getNr(y, x, d2);
                    
                    debug { writeln(x, ' ', y, ' ', d1, ' ', d2, ' ', getNr(x, y, d1), ' ', getNr(y, x, d2)); }
                }
            }
        }
    }
    
    ans.writeln;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  int ans = b / a;
  cout << min(c, ans) << endl;
  return 0;
}



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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
    int N;
    cin>>N;
    cout<<fixed<<setprecision(10);
    cout<<(lb)((N+1)/2)/N<<endl;
}

Measured memory_bytes: 3776
#include <iostream>

using namespace std;

void resolve()
{
    int N, R;
    cin >> N >> R;
    int ans = (N >= 10) ? R : (R + 100 * (10 - N));
    cout << ans << endl;
}

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
if N == 1:
  count += min(A[0]+A[1], B[0])
  print(count)
  exit(0)
mid_idx = N // 2
for idx in range(0, mid_idx):
  n_kill = min(A[idx], B[idx])
  count += n_kill
  A[idx] -= n_kill
  B[idx] -= n_kill
  n_kill = min(A[idx+1], B[idx])
  count += n_kill
  A[idx+1] -= n_kill
  B[idx] -= n_kill
  idx = -(idx+1)
  n_kill = min(A[idx], B[idx])
  count += n_kill
  A[idx] -= n_kill
  B[idx] -= n_kill
  n_kill = min(A[idx-1], B[idx])
  count += n_kill
  A[idx-1] -= n_kill
  B[idx] -= n_kill
if N % 2 != 0:
  count += min(A[mid_idx]+A[mid_idx+1], B[mid_idx])
print(count)

Measured memory_bytes: 19284
#include <stdio.h>

int main(void)
{
    int A, B, max;
    int C[3];
    scanf("%d %d", &A, &B);
    C[0] = A + B;
    C[1] = A - B;
    C[2] = A * B;
    max = C[0];
    for (int i = 0; i < 3; i++)
    {
        if (max < C[i])
            max = C[i];
    }
    printf("%d", max);
    return 0;
}

Measured memory_bytes: 128
def bfs(k):
    p=k
    frontier=[1]
    visited={1:1}
    while frontier:
        next=[]
        for u in frontier:
            if u==1:
                l=k-1
            else:
                l=k-2
            i=0
            if u in adj:
                for v in adj[u]:
                    if v not in visited:
                        visited[v]=1
                        p=(p*(l-i))%(10**9+7)
                        i+=1
                        next.append(v)
        frontier=next
    return p
  
n,k=map(int,input().split())
adj={}
for w in range(n-1):
    a,b=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
print(bfs(k))

Measured memory_bytes: 39432
#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);
  ll n;
  cin >> n;
  unordered_set<ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    s.insert(a);
  }
  if (s.size() == n)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
int main(){
  int  n,d,k,m=0;
  cin>>n>>d;
  float a[n][d],x=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      for(int k=0;k<d;k++){
        x+=pow(abs(a[i][k]-a[j][k]),2);
      }
 //     cout<<"x="<<x<<endl;
      k=x;
    x=pow(x,0.5);
//    cout<<"x="<<x<<endl;
    
    k=pow(k,0.5);
//    cout<<"k="<<k<<endl;
    if(x-k==0.00000000){
    	m++;
	}
	x=0;
}
}
cout<<m;}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  int A,B,dameflag=0;
  string S;
  cin>>A>>B>>S;

  if(S[A]!='-'){
    dameflag=1;
  }

  FORQ(i,0,A-1){
    if(S[i]>'9'||S[i]<'0'){
      dameflag=1;
    }
  }

  FORQ(i,A+1,A+B){
    if(S[i]>'9'||S[i]<'0'){
      dameflag=1;
    }
  }

  if(dameflag==1){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const long long mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    ll n,x; cin >> n >> x;
    ll ans = 1;
    ll tmp = 0;
    for(int i = 0; i < n; i++){
        ll l; cin >> l;
        tmp += l;
        if(tmp <= x){
            ans++;
        }
        

    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    string s, t;cin >> s >> t;
    int ss[s.size()+1];
    int tt[t.size()+1];
    ss[0] = 0;
    tt[0] = 0;
    if(s[0]=='A'){
        ss[1] = 1;
    }else{
        ss[1] = 2;
    }
    if(t[0]=='A'){
        tt[1] = 1;
    }else{
        tt[1] = 2;
    }
    FOR(i,1,s.size()){
        if(s[i]=='A'){
            ss[i+1] = ss[i] + 1;
        }else{
            ss[i+1] = ss[i] + 2;
        }
    }
    FOR(i,1,t.size()){
        if(t[i]=='A'){
            tt[i+1] = tt[i] + 1;
        }else{
            tt[i+1] = tt[i] + 2;
        }
    }
    int q; cin >>q;
    REP(i,q){
        int a,b,c,d; cin >> a >> b >> c >> d; a--;c--;
        if((ss[b]-ss[a]-tt[d]+tt[c])%3==0){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }


}

Measured memory_bytes: 1664
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 100005
#define mod 998244353
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld:\n",i)
#define pf(a) printf("%lld ",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp,mp1;
vector<pair<ll,pair<ll,pair<ll,ll> > > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,ll>mpp;
map<ll,bool>mb;
ll n,x,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
ll arr[MAX][4];
ll dp[MAX][4];
ll calc(ll pos,ll w)
{
    if(pos>n) return 0;
    else if(dp[pos][w]!=-1) return dp[pos][w];
    ll ret=0;
    if(pos==1)
    {
        ret=max(ret+arr[pos][0]+calc(pos+1,0),max(ret+arr[pos][1]+calc(pos+1,1),ret+arr[pos][2]+calc(pos+1,2)));
    }
    else if(w==0)
    {
        ret=max(ret,max(ret+arr[pos][1]+calc(pos+1,1),ret+arr[pos][2]+calc(pos+1,2)));
    }
    else if(w==1)
    {
        ret=max(ret,max(ret+arr[pos][2]+calc(pos+1,2),ret+arr[pos][0]+calc(pos+1,0)));
    }
    else if(w==2)
    {
        ret=max(ret,max(ret+arr[pos][1]+calc(pos+1,1),ret+arr[pos][0]+calc(pos+1,0)));
    }
    return dp[pos][w]=ret;
}
int main()
{
    cin>>n;
    v.clear();
    memset(arr,0,sizeof arr);
    FOR1(i,n)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    memset(dp,-1,sizeof dp);
    ll ans=calc(1,0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
function Main(input) {
	input = input.split('\n')
  	length = Number(input[0])
  	let count = 0
  	
  	for(let i=1;i<=length;i++){
    	let temp = input[i].split(' ').map(e=>Number(e))
        if(temp[0] === temp[1]){
        	++count
        }else{
         	count = 0 
        }
      
      	if(count === 3){
        	console.log('Yes')
          	break
        }
    }
  	if(count !== 3){console.log('No')}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 29700
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
int n, a[100000], g[100000][2];

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


int main() {
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    g[0][0] = 0;
    g[n - 1][1] = 0;
    for(int i = 1; i < n; ++i)
        g[i][0] = gcd(g[i - 1][0], a[i - 1]);
    for(int i = n - 2; i >= 0; --i)
        g[i][1] = gcd(g[i + 1][1], a[i + 1]);//, cout << g[i + 1][1] << " " << a[i + 1] << endl;
    int mx = max(g[0][1], g[n - 1][0]);
    for(int i = 1; i < n - 1; ++i) {
        mx = max(mx, gcd(g[i][0], g[i][1]));
    }
    //cout << endl;
    //for(int i = 0; i < n; ++i)
    //    cout << g[i][0] << " " << g[i][1] << endl;
    cout << mx << endl;
    return 0;
}

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

using namespace std;

vector<int> m(1000001, 1000000);

int main() {
  int N;
  cin >> N;
  vector<int> v;
  v.push_back(1);
  for (int i = 6; i <= N; i *= 6) v.push_back(i);
  for (int i = 9; i <= N; i *= 9) v.push_back(i);
  sort(begin(v), end(v));

  m[0] = 0;
  for (int i = 1; i <= N; ++i) {
    for (auto a : v) {
      if (i < a) break;
      m[i] = min(m[i], m[i - a] + 1);
    }
  }

  cout << m[N] << endl;
}


Measured memory_bytes: 7004
def prime(n):
    n *= 2
    flag = [True] * (n - 1)
    for i in range(n - 1):
        if flag[i] == True:
            if i + 2 >= n // 2:
                return i + 2
            num = i
            while num <= n - 2:
                flag[num] = False
                num += i + 2
n = int(input())
print(prime(n))

Measured memory_bytes: 66380
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(){
	int n, m;
	while(cin >> n){
		if(!n) break;
		map<char, char> map;
		char str;

		for(int i=0; i<n; ++i){
			char a, b;
			cin >> a >> b;
			map.insert(pair<char, char>(a, b));
		}

		cin >> m;
		for(int i=0; i<m; ++i){
			cin >> str;
			if(map.count(str) == 1){
				cout << map[str];
			} else {
				cout << str;
			}
		}

		cout << endl;
	}

    return 0;
}

Measured memory_bytes: 1188
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for k in range(1, n + 1):
    c[int(str(k)[0])][int(str(k)[-1])] += 1

cnt = 0
for i in range(10):
    for j in range(10):
        cnt += c[i][j] * c[j][i]
print(cnt)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>

using namespace std;

const int inf = 99999;

int prim(int a[101][101], int n)
{
	int r=0;
	bool vis[101];
	int cost[101];
	
	fill(vis, vis+101, false);
	fill(cost, cost+101, inf);
	cost[0] = 0;
	
	while(1){
		int v = -1;
		
		for(int i = 0; i < n; i++){
			if(!vis[i] && (v == -1 || cost[i] < cost[v])){
				v = i;
			}
		}
		
		if(v == -1){
			break;
		}
		
		vis[v] = true;
		r += cost[v];
		
		for(int i = 0; i < n; i++){
			cost[i] = min(cost[i], a[v][i]);
		}
	}
	
	return r;
}

int main()
{
	int a[101][101], n, m, s, t, u;
	
	while(1)
	{
		cin >> n;
		if(n == 0){
			break;
		}
		fill(&a[0][0], &a[n][n], inf);
		for(int i = 0; i < n; i++){
			a[i][i] = 0;
		}
		
		cin >> m;
		while(m--){
			scanf("%d,%d,%d",&s,&t,&u);
			a[s][t] = a[t][s] = u/100;
		}
		
		cout << (prim(a, n)-(n-1)) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

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

  scanf("%d %d", &w, &n);

  int s[w], a, b, A, B;

  for(i = 0;i < w;i++){
    s[i] = i + 1;
  }

  for(i = 0;i < n;i++){ 
    scanf("%d,%d", &a, &b);
    A = s[a - 1];
    B = s[b - 1];
    s[a - 1] = B;
    s[b - 1] = A;
  }

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

  return 0;
}

Measured memory_bytes: 596
use proconio::input;

fn main() {
    input! {
        n: u64,
    }
    let modulo = 1_000_000_007;
    let all = mod_pow(10, n, modulo);
    let no_zero_nine = mod_pow(8, n, modulo);
    let zero_or_nine = mod_pow(9, n, modulo);
    println!(
        "{}",
        (all + no_zero_nine + 2 * modulo - 2 * zero_or_nine) % modulo
    );
}

fn mod_pow(a: u64, b: u64, modulo: u64) -> u64 {
    if b == 0 {
        1
    } else if b % 2 == 0 {
        let half = mod_pow(a, b / 2, modulo);
        half * half % modulo
    } else if b % 2 == 1 {
        let half = mod_pow(a, b / 2, modulo);
        half * half % modulo * a % modulo
    } else {
        unreachable!()
    }
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N,M; cin >>N >>M;
  string s; cin >>s;
  stack<int> sta;
  int pos = N;
  bool ng = false;
  while (pos > 0){
    for (int i=min(pos, M); i>=0; i--){
      if (i == 0){ ng = true; break;}
      if (s[pos-i] == '1') continue;
      sta.push(i);
      pos -= i;
      break;
    }
    if (ng) break;
  }
  if (ng){
    cout <<-1 <<endl;
  }else{
    while (!sta.empty()){
      cout <<sta.top() <<" ";
      sta.pop();
    }
    cout <<endl;
  }
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

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

	ll ans = 1;
	vector<ll> prime(n + 2, 1);
	for (ll i = 2; i <= n; i++)
	{
		for (ll j = i; j <= n; j += i)
		{
			prime[j]++;
		}
		ans += i * prime[i];
	}

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

Measured memory_bytes: 81412
while True:
    count=0
    n, s = tuple([int(x) for x in raw_input().split(" ")])

    if n==0 and s==0:
        break
    
    for i in range(1, n+1):
        for j in range(1, n+1):
            if j==i:
                continue
            for k in range(1, n+1):
               if k==i or k==j:
                   continue
               if i+j+k==s:
                   count+=1
    
    print count / 6

Measured memory_bytes: 4216
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

n = int(input())
A = list(map(int, input().split()))
i = partition(A, 0, n-1)
A[i] = "["+str(A[i])+"]"
print(*A)

Measured memory_bytes: 18292
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
  int N,K;
  cin >> N >> K;
  if(K==1){
    cout<<0<<endl;
 return 0;
  }
  N-=K;
  cout<<N<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int ans = 0;
  cin >> N;
  float ave = 0;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    ave += a.at(i);
  }
  ave = round(ave / N);
  
  for(int i = 0; i < N; i++)
    ans += (a.at(i) - ave) * (a.at(i) - ave);
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include<stdio.h>

int main(void)
{

        int a, b, k, s, i;

        scanf("%d%d%d", &a, &b, &k);

        for(i=100; i>=1; i--){
                if((a%i==0) && (b%i==0))
                        s++;
                if(s==k) break;
        }
        printf("%d\n", i);
        return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 r, D, x;

int main() {
  cin >> r >> D >> x;
  REP(i, 10) {
    x = r * x - D;
    cout << x << endl;
  }

  return 0;
}

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

int remainder(string str,int n)
{
	int rem =0;
	for(int i=0;i<str.size();i++)
	{
		rem = rem*10 + str[i]-'0';
		rem = rem%n;
	}
	return rem;
}

int main()
{
	string str;
	cin >> str;
	if(remainder(str,9)==0)
		cout << "Yes\n";
	else
		cout <<"No\n";
	return 0;
}

Measured memory_bytes: 3824
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    ll a,b;
    cin >> a >> b;
    if(a * b % 2){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;
    }



    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int k; string s; cin>>k>>s;
	if(s.size()>k){
		s=s.substr(0,k)+"..."s;
	}
	cout<<s<<"\n"s;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;

    if (y == NIL) {
        root = z;
    }
    else {
        if (z->key < y->key) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(void) {
    int n, i, k;
    string com;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &k);
            insert(k);
        }
        else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 24688
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push(a);
  }

  rep(i, m) {
    int x = q.top(); q.pop();
    x /= 2;
    q.push(x);
  }

  ll ans = 0;
  while (!q.empty()) {
    ans += q.top(); q.pop();
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  string s,t;
  cin>>s;
  map<char,char> mp;
  mp['b']='d';
  mp['d']='b';
  mp['p']='q';
  mp['q']='p';
  rrep(i,s.size()-1){
    t+=mp[s[i]];
  }

  Yes(s==t);


}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		double v = in.nextDouble();
		double t = v/9.8;
		double y = 4.9*t*t;

		for (int i=1; ; i++) {
			if (y <= 5*i-5) {
				out.println(i);
				return;
			}
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(in.hasNext())solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 27596
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <numeric>
#include <random>
#include <memory>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <cstring>
#include <cassert>
#include <bitset>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif
//#define int ll
//#pragma GCC optimize("Ofast")


using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define sz(x) int((x).size())

#ifndef LOCAL
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#else
	mt19937 rng(228);
#endif

const int N = 1e3 + 7;
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 3;
const int MOD = 998244353;
const ld eps = 1e-6;
const string cars[] = {"🚗", "🚕", "🚙"};

int a[N][N], pos[N][N], dp[N][N], c[N][N], n;

void calc(int x, int y) {
	if (dp[x][y] || x == 0 || y == 0) {
		return;
	}
	if (c[x][y] == 1) {
		cout << "-1\n";
		exit(0);
	}
	c[x][y] = 1;

	int i = a[x][pos[x][y] - 1];
	int j = a[y][pos[y][x] - 1];

	calc(x, i);
	calc(y, j);

	dp[x][y] = max(dp[x][i], dp[y][j]) + 1;
	c[x][y] = 2;
}

signed main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(9);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n; j++) {
			cin >> a[i][j];
			pos[i][a[i][j]] = j;
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			calc(i, j);
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 16128
import fractions
a,b,c,d = map(int,input().split())
nums = b-a+1

def lcm (x,y):
    return (x * y) // fractions.gcd(x, y)

c_num = b//c - (a-1)//c
d_num = b//d - (a-1)//d
cd_num = b//lcm(c,d) - (a-1)//lcm(c,d)

print(nums-(c_num+d_num-cd_num))

Measured memory_bytes: 5048
M,D = map(int,input().split())
ans = 0
s = []
for i in range(4,M+1):
    for j in range(22,D+1):
         k = str(j)
         if  int(k[0])*int(k[1]) == i:
             ans += 1
             s.append(i)
             s.append(j)
ans_2 = ans
for i in range(len(s)//2):
    if s[i*2-1]%10 == 1 or s[1*2-1]//10 == 1:
        ans_2 -= 1
print(ans_2)

Measured memory_bytes: 3064
package main

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

func isEvenString(s string) bool {
	if len(s)&1 == 1 {
		return false
	}
	if s[0:len(s)/2] == s[len(s)/2:len(s)] {
		return true
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	for ans := len(s) - 1; ans >= 1; ans-- {
		if isEvenString(s[0:ans]) {
			puts(ans)
			break
		}
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int count = 0;
  
  for (int i = 0; i < S.size()/2; i++) {
    if (S.at(i) != S.at(S.size()-1-i)){
      count++;
    }
  }
  cout << count << endl;
}
  

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

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
    int n;
    cin>>n;
    map<string, int>mp{
        {"AC", 0},
        {"WA", 0},
        {"TLE", 0},
        {"RE",0}
    };
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout << "AC x "<<mp["AC"]<<endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}


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

using namespace std;

using i64 = long;

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


template<typename T>
struct Compression{
    vector<T> compvec;
    Compression(vector<T>& inp){//圧縮する
        compvec = inp;
        sort(compvec.begin(), compvec.end());
        compvec.erase(unique(compvec.begin(), compvec.end()), compvec.end());
    }
    int Index(T val){//圧縮を元に対応するインデックスを返す
        auto it = lower_bound(compvec.begin(), compvec.end(), val);
        return distance(compvec.begin(), it);
    }
    vector<T>& operator*(){
        return compvec;
    }
};


signed main(){
    int n, t;
    cin >> n >> t;
    vector<i64> a(n + 1);
    for(int i = 0; i < n; ++i)
        cin >> a[i + 1];
    ++n;

    vector<vector<vector<i64>>> dp(n + 1, vector<vector<i64>>(t + 1, vector<i64>(n + 1, INF)));
    Compression<i64> c(a);
    dp[1][0][c.Index(a[0])] = a[0];
    if(t)
        for(int k = 0; k < n; ++k)
            dp[1][1][k] = (*c)[k];

    for(int i = 1; i < n; ++i){
        for(int j = 0; j <= t; ++j){
            for(int k = 0; k < n; ++k){
                i64 diff = max(0L, a[i] - (*c)[k]);
                int idx = c.Index(a[i]);
                dp[i + 1][j][idx] = min(dp[i + 1][j][idx], dp[i][j][k] + diff);
                if(j != t){
                    dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k]);
                    if(i != n - 1){
                        int idx3 = c.Index(a[i + 1]);
                        i64 diff = max(0L, a[i + 1] - (*c)[k]);
                        dp[i + 1][j + 1][idx3] = min(dp[i + 1][j + 1][idx3], dp[i][j][k] + diff);
                    }
                }
            }
        }
    }
    i64 ans = INF;
    for(int j = 0; j <= t; ++j)
        for(int k = 0; k < n; ++k){
            ans = min(ans, dp.back()[j][k]);
        }
    cout << ans << endl;
}


Measured memory_bytes: 219008
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
  int n,m,l,r,rmin=100001,lmax=0;

  cin>>n>>m;

  for(int i=0;i<m;i++){
    cin>>l>>r;
    if(lmax<l){
      lmax=l;
    }
    if(rmin>r){
      rmin=r;
    }
  }

  int ans=rmin-lmax+1;
  if(ans>0){
    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, k = (int(i) for i in input().split())
#print(a,b)

ans=0    
for i in range(1,n+1):
    cnt=0
    while i < k:
        cnt+=1
        i=i*2
#    print(cnt)
    ans+=(1/n)*((1/2)**cnt)
    
print(ans)

Measured memory_bytes: 39024
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <tuple>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> s(n);
    for(int i = 0; i < n; ++i){
        long long si;
        cin >> si;
        s.at(i) = si;
    }

    long long ans = 0;
    for(int c = 1; c < n - 1; ++c){
        long long tmp = 0;
        for(int k = 1; (k + 1) * c < n - 1; ++k){
            const long long a = n - 1 - k * c;
            if(a % c == 0 && (a / c <= k)){
                break;
            }
            tmp += s.at(k * c) + s.at(n - 1 - k * c);
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N];
int main (){
  scanf ("%d", &n);
  int sum = 0;
  forn (i, 1, n) scanf ("%d", a + i), sum += a[i];
  sort (a + 1, a + n + 1);
  if (sum % 10 != 0) return printf ("%d\n", sum), 0;
  forn (i, 1, n){
    if (a[i] % 10 != 0) return printf ("%d\n", sum - a[i]), 0;
  }
  sum = 0;
  printf ("%d\n", sum);
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();

        for(int i = 1; i<= 50000; i++){
            if(i * 108 / 100 == n){
                System.out.println(i);
                return;
            }
        }

        System.out.println(":(");
    }



    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

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

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

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

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

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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

}



Measured memory_bytes: 22612
use std::io;

fn main() {
    let mut inp = String::new();
    io::stdin().read_line(&mut inp).unwrap();
    inp = inp.trim().to_string();
    if inp == "RRR" {
        println!("3");
    }
    else if inp.find("RR") != None {
        println!("2");
    }
    else if inp.find("R") != None {
        println!("1");
    }
    else {
        println!("0");
    }
}

Measured memory_bytes: 2100
n = int(input())
li = []
for i in range(n):
    li.append(int(input()))

max_val = max(li)
sec_val = sorted(li)[-2]
ans = []

for j in li:
    if j == max_val:
        ans.append(sec_val)
    else:
        ans.append(max_val)

for k in ans:
    print(k)

Measured memory_bytes: 14096