akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


typedef long double D;
const D PI = acos(-1.0);
const D EPS = 1e-10;
class P { public:
  D x, y;
  P(D x=0, D y=0) : x(x), y(y) {}

  P& operator+=(const P& o) { x += o.x; y += o.y; return *this; }
  P& operator-=(const P& o) { x -= o.x; y -= o.y; return *this; }
  P& operator*=(const P& o) { return *this = {x*o.x - y*o.y, x*o.y + y*o.x}; }
  P& operator*=(const D& r) { x *= r; y *= r; return *this; }
  P& operator/=(const D& r) { x /= r; y /= r; return *this; }
  P operator-() const { return {-x, -y}; }

  D norm() const { return x*x + y*y; }
  D abs() const { return sqrt(norm()); }
  D arg() const { return atan2(y, x); }
  bool isZero() const { return std::abs(x) < EPS && std::abs(y) < EPS; }
  /** 象限 */
  int orth() const { return y >= 0 ? (x >= 0 ? 1 : 2) : (x < 0 ? 3 : 4); }
  static P polar(const D& rho, const D& theta = 0) { return {rho * cos(theta), rho * sin(theta)}; }
};
std::ostream &operator<<(std::ostream &os, P const &p) { return os << "(" << p.x << ", " << p.y << ")"; }
P operator+(const P& p, const P& q) { return P(p) += q; }
P operator-(const P& p, const P& q) { return P(p) -= q; }
P operator*(const P& p, const P& q) { return P(p) *= q; }
P operator*(const P& p, const D& r) { return P(p) *= r; }
P operator/(const P& p, const D& r) { return P(p) /= r; }
P operator*(const D& r, const P& p) { return P(p) *= r; }
P operator/(const D& r, const P& p) { return P(p) /= r; }
D crs(const P& a, const P& b){ return a.x*b.y - a.y*b.x; }
D dot(const P& a, const P& b){ return a.x*b.x + a.y*b.y; }
int signum(D x) {return x > EPS ? +1 : x < -EPS ? -1 : 0;}
bool operator<(const P& a, const P& b) {
  // return a.arg() < b.arg();
  if (a.isZero() != b.isZero()) return a.isZero() > b.isZero();
  if (a.orth() != b.orth()) return a.orth() < b.orth();
  return crs(a, b) > 0;
}

int main2() {
  int N; cin >> N;
  vector<P> p(N);
  REP(i, N) {
    int x, y; cin >> x >> y;
    p[i] = P(x, y);
  }
  sort(ALL(p));

  double ans = 0;
  REP(i, N) {
    P s;
    REP(k, N) {
      s += p[(i + k) % N];
      chmax(ans, (double)s.abs());
    }
  }
  printf("%.12f\n", ans);

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int total;
	int sec;
	int i;
	
	total = 0;
	for (i = 0; i < 4; i++){
		scanf("%d", &sec);
		total += sec;
	}
	
	printf("%d\n", total / 60);
	printf("%d\n", total % 60);
	
	return (0);
}

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

void main()
{
    auto S = readln.chomp;

    auto head = S[0..7];
    auto tail = S[$-7..$];
    foreach (i; 0..8) {
        if (head[0..i] ~ tail[i..7] == "keyence") {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(max(a)):
    HP = 0
    for j in range(n):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


int pre[100005];

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  


    int n;
    cin>>n;
    int a[n+1];
    int b[n+1];
    
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    int bada=1;
    int x=0;
    for(int i=n;i>=1;i--)
    {
        int z=a[i];
        z+=x;
        z%=b[i];
        x+=(b[i]-z)%b[i];
        int g=__gcd(bada,b[i]);
        bada=(bada*b[i])/g;
    }
    cout<<x;
} 
    
 

Measured memory_bytes: 5144
def solve():
    timer = 0
    count = 0
    ans = 0
    while (count < n):
        diff = timer - ti[count]
        timer = ti[count] + t
        if 0 < (diff) < t:
            ans += t - diff
        else:
            ans += t
        count += 1
    print(ans)

if __name__ == '__main__':
    n, t = map(int, input().split())
    ti = list(map(int, input().split()))
    solve()

Measured memory_bytes: 25200
// AOJ 3027: OOllOll
// 2018.3.28 bal4u

#include <stdio.h>

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


Measured memory_bytes: 2104
import Data.List

main = do
  n <- readLn
  putStrLn $ show n ++ ": " ++ unwords (fmap show $ primeFactor n)

factors :: Int -> [Int]
factors n = [d | d <- [1..n], n `mod` d == 0]

isPrime :: Int->Bool
isPrime x =
  null [y | y<-[2..floor $ sqrt $ fromIntegral x], x `mod` y == 0]

primeFactor :: Int -> [Int]
primeFactor n
  | isPrime n = [n]
  | otherwise = go n
  where
    go 1 = []
    go n = d : go (n `div` d)
      where d = factors n !! 1

primeFactorTailRec :: [Int] -> Int -> [Int]
primeFactorTailRec res 1 = res
primeFactorTailRec res n = primeFactorTailRec (d : res) (n `div` d)
    where d = factors n !! 1

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

int N,a,b,total=0;

void Input(){
	cin>>N;
	for(int i=0; i<N; i++){
		cin>>a>>b;
		if(a==b){
			total++;
		}else{
			total=0;
		}
		if(total==3){
			cout<<"Yes"<<'\n';
			return;
		}
	}
	cout<<"No"<<'\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Input();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{	
	int N;
	cin >> N;
	vector<int> v(N);
	REP(i, N) cin >> v[i];
	sort(ALL(v));
	v[N - 1] /= 2;
	cout << accumulate(ALL(v), 0) << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X, Y = MAP()

ans = 0
if X == 1:
    ans += 300000
elif X == 2:
    ans += 200000
elif X == 3:
    ans += 100000
if Y == 1:
    ans += 300000
elif Y == 2:
    ans += 200000
elif Y == 3:
    ans += 100000
if X == Y == 1:
    ans += 400000
print(ans)


Measured memory_bytes: 3064
import sys
import math

X = int(sys.stdin.readline().strip())

# i秒までに進める最大の距離
max_t = int(math.sqrt(2*X)) + 1
# print(max_t)
for i in range(max_t + 1):
    if i * (i+1) >= 2 * X:
        break

print(i)

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

int main(void)
{
	int N, K; cin >> N >> K;
	int R, S, P; cin >> R >> S >> P;
	string T; cin >> T;
	vector<char> rec;
	int ans = 0;

	for (int i = 0; i < K; i++) {
		if (T[i] == 's') {
			ans += R;
			rec.push_back('r');
		}
		else if (T[i] == 'p') {
			ans += S;
			rec.push_back('s');
		}
		else {
			ans += P;
			rec.push_back('p');
		}
	}

	for (int i = K; i < N; i++) {
		if (T[i] == 's') {
			if (rec[i - K] != 'r') {
				ans += R;
				rec.push_back('r');
			}
			else if (i < N - K) {
				if(T[i+K]=='p')rec.push_back('p');
				else rec.push_back('s');
			}
			
		}
		else if (T[i] == 'p') {
			if (rec[i - K] != 's') {
				ans += S;
				rec.push_back('s');
			}else if (i < N - K) {
				if (T[i + K] == 'r')rec.push_back('r');
				else rec.push_back('p');
			}
		}
		else {
			if (rec[i - K] != 'p') {
				ans += P;
				rec.push_back('p');
			}
			else if (i < N - K) {
				if (T[i + K] == 's')rec.push_back('s');
				else rec.push_back('r');
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	string s;cin>>s;
	s+='R';
	int cnt=0,in=-1,cntl=0;
	bool flagl=0;
	int arr[sz(s)-1]={};
	loop(sz(s),i,0){
		if(flagl&&s[i]=='R'){
			if(cntl%2){
				arr[in-1]=cnt/2;
				arr[in]=(cnt+1)/2;
			}
			else{
				arr[in-1]=(cnt+1)/2;
				arr[in]=cnt/2;
			}
			cnt=flagl=cntl=0;
		}
		else if(s[i]=='L'&&!flagl){
			in=i;
			flagl=1;
		}
		cntl+=(s[i]=='L');
		cnt++;
	}
	for(auto x:arr)cout<<x<<' ';
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;

long long gcd(long long a,long long b){
	if(b==0) return a;
	else gcd(b,a%b);
}

int main(){
    long long A,B;
	while(cin>>A>>B){
		printf("%lld %lld\n",gcd(A,B),A*B/gcd(A,B));
	}
    return 0;
}

Measured memory_bytes: 1148
n=int(input())
c=0
l=[0,3,5,7]
for i1 in l:
 for i2 in l:
  for i3 in l:
   for i4 in l:
    for i5 in l:
     for i6 in l:
      for i7 in l:
       for i8 in l:
        for i9 in l:
         x=str(i1+10*i2+100*i3+1000*i4+10000*i5+100000*i6+1000000*i7+10000000*i8+100000000*i9)
         if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1
print(c)

Measured memory_bytes: 3064
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, M, X, C[21], A[21][21], ans;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> M >> X;
	for (ll b = 0; b < N; b++) {
		cin >> C[b];
		for (ll j = 0; j < M; j++) cin >> A[b][j];
	}
	
	ans = INF;
	for (ll i = 0; i < (1ll << N); i++) {
		ll cost = 0;
		ll comp[21];
		memset(comp, 0, sizeof comp);
		bool good = true;
		for (ll b = 0; b < N; b++) {
			if (i & (1ll << b)) {
				cost += C[b];
				for (ll j = 0; j < M; j++) comp[j] += A[b][j];
			}
		}
		for (ll j = 0; j < M; j++) {
			if (comp[j] < X) good = false;
		}
		if (good) ans = min(ans, cost);
	}
	
	if (ans == INF) cout << -1;
	else cout << ans;
	
	
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e7+1;
ll fact[N],p[N];
void sieve(int n){
    for(int i=4;i<=n;i+=2)
        p[i]=2;
    for(int i=3;i*i<=n;i+=2)
    if(!p[i])for(int j=i*i;j<=n;j+=i)p[j]=i;
    return;
}
ll fac(int n){
    fact[1]=1;
    for(int i=2;i<=n;i++){
        if(!p[i])fact[i]=2;
        else{
            int temp=i,cnt=0;
            while(temp%p[i]==0){temp/=p[i];cnt++;}
            fact[i]=fact[temp]*(cnt+1);
        }
    }
    ll ans=0;  
    for(int i=1;i<=n;i++){
        ans+=i*fact[i];
    }
    return ans;
}


int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    sieve(n);
    cout<<fac(n);
    return 0;
}

Measured memory_bytes: 159872
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = 0;
		int[] cnt = new int[n];
		Arrays.fill(cnt, Integer.MAX_VALUE);
		int now = 0;
		int loop = 0;
		int start = 0;
		for(int i = 0; i <= n; i++){
		    if(cnt[a[now]] == Integer.MAX_VALUE){
		        cnt[a[now]] = i+1;
		        now = a[now];
		    }else{
		        loop = a[now];
		        start = i+1;
		        break;
		    }
		}
		//System.out.println(loop);
		//System.out.println(start);
		
		int[] cntL = new int[n];
		Arrays.fill(cntL, Integer.MAX_VALUE);
		cntL[loop] = 0;
		int nowL = loop;
		int cycle = 0;
		for(int i = 0; i < n; i++){
		    if(cntL[a[nowL]] == Integer.MAX_VALUE){
		        cntL[a[nowL]] = i+1;
		        nowL = a[nowL];
		    }else{
		        cycle = i+1;
		        break;
		    }
		}
		
		//System.out.println(Arrays.toString(cnt));
		//System.out.println(Arrays.toString(cntL));
		
		if(k < start){
		    for(int i = 0; i < n; i++){
		        if(cnt[i] == k) result = i+1;
		    }
		}else{
		    for(int i = 0; i < n; i++){
		        if(cntL[i] == (k-start)%cycle) result = i+1;
		    }
		}
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 49068
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=200005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n;
    cin >> n;
    ll a[n+1];
    rep(i,1,n+1) cin >> a[i];

    map<ll,ll> r;
    ll ans=0;
    rep(i,1,n+1) {
    	ans+=r[i-a[i]];
    	r[a[i]+i]++;
    }
    ret(ans);

}

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

using namespace std;

int main()
{
    int n, t;
    int curT, curC;
    int res;
    while(cin >> n >> t)
    {
        res = INT_MAX;
        while(n--)
        {
            cin >> curC >> curT;
            if(curT <= t)
            {
                res = min(res, curC);
            }
        }
        if(res == INT_MAX)
            cout << "TLE" << endl;
        else
            cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define all(x) x.begin(), x.end()
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

Int dp[100001][4];

int main() {
    string s;
    cin >> s;
    dp[0][0] = 1;
    for (Int i = 0; i < (Int)s.size(); i++) {
        for (Int j = 0; j < 4; j++) {
            if (s[i] == '?') {
                dp[i + 1][j] += dp[i][j] * 3;
                dp[i + 1][j] %= mod;
            }
            else {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= mod;
            }
        }   
        if (s[i] == '?') {
            for (Int j = 0; j < 3; j++) {
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j + 1] %= mod;
            }
        }
        else {
            dp[i + 1][s[i] - 'A' + 1] += dp[i][s[i] - 'A'];
            dp[i + 1][s[i] - 'A' + 1] %= mod;
        }
    }
    // for (Int i = 0; i < (Int)s.size() + 1; i++) {
    //     for (Int j = 0; j < 4; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    dump(dp[s.size()][3]);
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;
typedef pair<int,int> ii_t;

int a[300][300] = {0};
int prom[300*300 + 10] = {0};
int diff[300*300 + 10] = {0};

int main() {
    int h, w, d, q, left, right;
    cin >> h >> w >> d;
    map<int,ii_t> pos;
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++) {
            cin >> a[i][j];

            pos[a[i][j]] = ii_t(i,j);
        }
    int hw = h*w;
    for (int k=1;k<=hw;k++) {
        if (k-d <= 0) {
            prom[k] = 0;
        } else {
            ii_t fr = pos[k-d];
            ii_t to = pos[k];

            prom[k] = abs(to.first-fr.first) + abs(to.second-fr.second);
        }
        if (k-d <= 0) {
            diff[k] = 0;
        } else {
            diff[k] += diff[k-d] + prom[k];
        }
        // cerr << "diff: " << k << " " << diff[k] << endl;
    }

    for (cin >> q ; q -- ; ) {
        cin >> left >> right;
        cout << (diff[right] - diff[left]) << endl;
    }
    return 0;
}


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

long long n;
int ans;
int a[4] = {0, 3, 5, 7};

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=1050000; ++i){
		long long t = 0;
		int j = i;
		long long tmp = 1;
		while(j > 0){
			t += tmp * a[j % 4];
			tmp *= 10;
			j /= 4;
		}
//		cout << t << "\n";
		j = i;
		bool f[4] = {};
		while(j > 0){
			f[j%4] = true;
			j /= 4;
		}
		if(!f[0] && f[1] && f[2] && f[3] && t <= n){
			++ans;
//			cout << t << "\n";
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

typedef vector<vector<pair<ll,int>>> wgraph;
typedef pair<ll,int> pli;

vector<ll> bfs(wgraph v,int x){
  priority_queue<pli,vector<pli>,greater<pli>> q;
  vector<ll> dist(v.size(),longinf);
  dist[x]=0;
  q.push({0LL,x});

  while(q.size()){
    pli p=q.top(); q.pop();
    ll d=p.F, now=p.S;
    if(dist[now]<d){ continue; }
    for(auto to:v[now]){
      if(dist[to.S]>d+to.F){
        dist[to.S] = d+to.F;
        q.push({dist[to.S], to.S});
      }
    }
  }
  return dist;
}

int main(){
  int n,m;
  cin >> n >> m;
  wgraph v(mx*3);
  rep(i,m){
    int x,y,z=1;
    cin >> x >> y; x--; y--;
    v[x].emplace_back(z,y+mx);
    v[x+mx].emplace_back(z,y+mx+mx);
    v[x+mx+mx].emplace_back(z,y);
  }
  int s,t;
  cin >> s >> t; s--; t--;
  vector<ll> dist=bfs(v,s);
  ll ans = dist[t];
  if(ans==longinf){
    ans = -1;
  } else {
    ans/=3;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35456
n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e|e.to_i}

def combo(d, i)
	c = 0
	s = d[i]
	while d[i]==s 
		c += 1
		i += 1
	end
	return c
end


ap = []
am = []

1.upto(n) do |i|
	ap << i - a[i-1]
	am << i + a[i-1]
end

ap.sort!.reverse!
am.sort!.reverse!

sum = 0
i = 0
j = 0
c = combo(ap, 0)
while ap[i]>1 && j<n
	if ap[i] < am[j] then
		j += 1
	elsif ap[i] > am[j]
		i += c
		c = combo(ap, i)
	else
		sum += c
		j += 1
	end
	#p sum
end

#p ap 
#p am

print(sum)

Measured memory_bytes: 35148
/*
問題の名称：Heian-kyo Walking
問題のURL：http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2186&lang=jp
所要時間：50分
学んだこと：動的計画法 2次元配列の初期化は割とめんどくさい
着席位置：中央　中央
*/

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {   

        //上からその座標に行けるかをHoriz[][],左からその座標に行けるかをVert[][]で管理
        bool Horiz[16][16],Vert[16][16];
        for(int j = 0; j < 16; j++)
        {
            for(int k = 0; k < 16; k++)
            {
                if(j == 0)
                {
                    //x座標が0なら左からは来れないのでfalseに
                    Horiz[j][k] = false;
                }
                else
                {
                    Horiz[j][k] = true;
                }
            }
        }

        for(int j = 0; j < 16; j++)
        {
            for(int k = 0; k < 16; k++)
            {
                if(k == 0)
                {
                    //y座標は0なら上からは来れないのでfalseに
                    Vert[j][k] = false;
                }
                else
                {
                    Vert[j][k] = true;
                }
            }
        }

        int gx,gy;
        cin >> gx >> gy;
        int m;
        cin >> m;
        int x1,x2,y1,y2;
        for(int j = 0; j < m; j++)
        {
            cin >> x1 >> y1 >> x2 >> y2;
            //マタタビの位置を確認してfalseに
            if(x1 == x2)
            {
                Vert[x1][max(y1,y2)] = false;
            }
            else
            {
                Horiz[max(x1,x2)][y1] = false;
            }

        }

        int ans[16][16];
        for(int j = 0; j <= gx; j++)
        {
            for(int k = 0; k <= gy; k++)
            {
                if((j == 0)&&(k == 0))
                {
                    ans[j][k] = 1;
                }
                else if((Horiz[j][k] == false)&&(Vert[j][k] == false))
                {
                    ans[j][k] = 0;
                }
                else if((Horiz[j][k] == true)&&(Vert[j][k] == false))
                {
                    ans[j][k] = ans[j-1][k];
                }
                else if((Horiz[j][k] == false)&&(Vert[j][k] == true))
                {
                    ans[j][k] = ans[j][k-1];
                }
                else
                {
                    ans[j][k] = ans[j-1][k] + ans[j][k-1];
                }
            }
        }

        if(ans[gx][gy] == 0)
        {
            cout << "Miserable Hokusai!" << endl;
        }
        else
        {
            cout << ans[gx][gy] << endl;;
        }
    }
}


Measured memory_bytes: 3072
S = input()
pre = int(S[0:2])
af = int(S[2:4])
if 1 <= pre <= 12:
    preM = 1
else:
    preM = 0
if 1 <= af <= 12:
    afM = 1
else:
    afM = 0
if preM == 1:
    if afM == 1:
        ans = "AMBIGUOUS"
    else:
        ans = "MMYY"
else:
    if afM == 1:
        ans = "YYMM"
    else:
        ans = "NA"
print(ans)

Measured memory_bytes: 3064
dice = STDIN.gets.chomp().split(" ")
line = STDIN.gets.chomp()
roll = Array.new(line.length) { |i|  i = line[i, 1]}

for i in 0..roll.length - 1 do
  case roll[i]
  when "S" then
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  when "N" then
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  when "E" then
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  when "W" then
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  end
end

puts dice[0]

Measured memory_bytes: 6116
// :)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) {
		cout << "Zero";
		return 0;
	}
	if (a > 0) {
		cout << "Positive";
		return 0;
	}
	b = min(b, (ll)-1);
	if ((b - a + 1) % 2 == 0)
		cout << "Positive";
	else
		cout << "Negative";
}


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

#define ll long long
#define mod 1000000007

int main() {
    ll n,ans=0;
    cin>>n;
    ll p[n];
    map<ll,ll>mp;
    for(ll i=0;i<n;i++){
        cin>>p[i];
        mp[p[i]]=1;

        if(mp.begin()->first>=p[i])ans++;

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


Measured memory_bytes: 14336
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int N;
    cin >> N;
    ll edges = 0;
    rep(k,N-1) {
        ll i, j;
        cin >> i >> j;
        if (j < i) swap(i,j);
        edges += ll(i) * (N - j + 1);
    }
    ll vertices = 0;
    for (int k = 1; k <= N; ++k) {
        vertices += ll(N - k + 1) * (N-k+2);
    }
    vertices /= ll(2);
    cout << vertices - edges << endl;
    return 0;
}

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

void solve() {
    string S, T;
    cin >> S >> T;

    int ns = S.size();
    int nt = T.size();
    for (int i = ns - nt; i >= 0; --i) {
        string first_part = S.substr(0, i);
        string s = S.substr(i, nt);
        string last = S.substr(i + nt);

        bool ok = true;
        for (int j = 0; j < nt; ++j) {
            if (!(s[j] == T[j] || s[j] == '?')) {
                ok = false;
                break;
            }
        }
        if (ok) {
            for (char c : first_part) {
                cout << (c == '?' ? 'a' : c);
            }
            cout << T;
            for (char c : last) {
                cout << (c == '?' ? 'a' : c);
            }
            cout << endl;
            return;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

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


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

using namespace std;

const int N = 3005;

int n, mod;
int f[N][N];
int c[N][N];

void add(int &x, int y) { x = (x + y) >= mod ? x + y - mod : x + y; }

int main() {
	cin >> n >> mod;
	f[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= i; ++j) {
			add(f[i + 1][j], f[i][j]);
			add(f[i + 1][j], 1LL * f[i][j] * j % mod);
			add(f[i + 1][j + 1], f[i][j]);
		}
	}
	for (int i = 0; i <= n; ++i) c[i][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= i; ++j) {
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
		}
	}
	int res = 0;
	for (int i = 0; i <= n; ++i) {
		int m = n - i;
		int v0 = 1, v1 = 2;
		for (int j = 0; j < m; ++j) v0 = 2LL * v0 % mod; // 2 ^ m
		for (int j = 0; j < m; ++j) v1 = 1LL * v1 * v1 % mod; // 2 ^ (2 ^ m)
		int sum = 0, cur = 1;
		for (int j = 0; j <= i; ++j) {
			add(sum, 1LL * cur * f[i][j] % mod * v1 % mod), cur = 1LL * cur * v0 % mod;
		}
		sum = 1LL * sum * c[n][i] % mod;
		// cout << sum << '\n';
		if (i & 1) res -= sum; else res += sum;
		if (res >= mod) res -= mod; if (res < 0) res += mod;
	}
	cout << res;
}

Measured memory_bytes: 69504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), x = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= d; j++) {
				if ((j - 1) % a[i - 1] == 0)
					count++;
			}
		}
		System.out.println(count + x);
	}

}


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

typedef long long ll;

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

    ll x;
    cin >> x;
    if(x<100){
        cout << 0 << endl;
        return 0;
    }
    ll uku = x % 100;
    for(ll a=0;a<=99;a++){
        for(ll b=0;b<=50;b++){
            for(ll c=0;c<=33;c++){
                for(ll d=0;d<=25;d++){
                    for(ll e=0;e<=20;e++){
                        if(a+2*b+3*c+4*d+5*e==uku && (a+b+c+d+e)<=(x-uku)/100){
                            cout << 1 << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll modi = 1e9+7;
const ll mxn = 5e5+5;	
ll fact[mxn],inv[mxn],ifact[mxn];

void solve(){
	ll n,m;
	cin >> n >> m;
	fact[0] = fact[1] = inv[0] = inv[1] = ifact[0]=ifact[1] = 1LL;
	for(ll i =2;i<mxn;i++){
		fact[i] = fact[i-1]*i%modi;
		inv[i] = (modi - (modi/i)*inv[modi%i]%modi)%modi;
		ifact[i] = ifact[i-1]*inv[i]%modi;
	}

	auto ncr =[&](ll n, ll r){
		if(r>n)
			 return 0ll;

		return (fact[n]*ifact[n-r]%modi)*ifact[r]%modi;
	};

	ll ans = 0;
	ll cur = 1;
	for(ll i =0;i<=n;i++){
		ans = (ans + modi + cur*(ncr(n,i)*ncr(m-i,n-i)%modi)*fact[n-i]%modi)%modi;
		cur  = -cur;
	}
	cout << (ans*ncr(m,n)%modi)*fact[n]%modi << endl;

	
}	

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	solve();
	return 0; 
}

Measured memory_bytes: 15348
#include<iostream>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
int a,b,p;
cin>>a>>b;
p=a*b;
if(p%2==0)
cout<<"Even";
else
cout<<"Odd";
return 0;  
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 998244353;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	string s; cin >> s;

	vl cnt(8);
	cnt[0] = n;

	ll res = 1;
	for (char c: s) {
		ll bit = 0;
		if (c == 'R') bit = 1;
		if (c == 'G') bit = 2;
		if (c == 'B') bit = 4;
		assert(bit != 0);
		
		ll mask = 8;
		FOR(cmask,0,8) if (cnt[cmask] && !(cmask & bit)) mask = cmask;
		assert(mask != 8);
		
		res = res * cnt[mask] % MOD;
		cnt[mask]--;
		cnt[mask|bit]++;
	}
	assert(cnt[7] == n);
	cout << res << endl;
}



Measured memory_bytes: 720
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long K, S;
    long long count = 0;
 
    cin >> K >> S;
    for(int i = 0; i <= K; i++){
        for(int j = i; j <= K; j++){
            for(int k = j; k <= K; k++){
                if(i + j + k == S){
                    if(i == j && j == k)
                        count++;
                    else if(i == j || j == k || i == k)
                        count += 3;
                    else
                        count += 6;
                }
            }
        }
    }   
    
    cout << count;
}
    


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	var m [][]string
	cf := make([]bool, W)
	for i := 0; i < H; i++ {
		r := make([]string, W)
		x := ""
		fmt.Scan(&x)
		w := false
		for j, v := range x {
			r[j] = string(v)
			if r[j] == "#" {
				w = true
				cf[j] = true
			}
		}
		if w {
			m = append(m, r)
		}
	}
	for _, v := range m {
		for i, x := range v {
			if cf[i] {
				fmt.Printf("%s", x)
			}
		}
		fmt.Println("")
	}

}

Measured memory_bytes: 1024
N,K=map(int,input().split())
X = list(map(int, input().split()))

print(min([min(abs(X[i]) + abs(X[i+K-1]-X[i]), abs(X[i+K-1]) + abs(X[i]-X[i+K-1])) for i in range(N-K+1)]))

Measured memory_bytes: 62576
import numpy as np
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
a = A % 10
b = B % 10
c = C % 10
d = D % 10
e = E % 10
 
aa = A // 10
bb = B // 10
cc = C // 10
dd = D // 10
ee = E // 10
 
r = np.array([a, b, c, d, e])
k = (r > 0).sum()
if k > 0:
  l = r[r != 0].min()
  print((aa + bb + cc + dd + ee) * 10 + 10*(k-1) + l)
else:
  print(A + B + C + D + E)

Measured memory_bytes: 14296
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define Would;
#define you;

int main() {
  int n;
  Would you cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long  x, y;
  x = 0;
  y = 0;
  for (int i = n-1; i > 0 && y == 0; --i) {
    if (a[i] == a[i-1]) {
      if (x == 0) x = a[i];
      else y = a[i];
      i--;
    }
  }
  Would you cout<<x*y<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

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

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    rep(i, h) cin >> s[i];
    int ans = 1000000000;
    if (h == 1){
        int sm = 0;
        int num = 0;
        rep(i, w){
            if (s[0][i] == '1'){
                num++;
            }
            if(num > k){
                sm++;
                num = 1;
            }
        }
    }
    


    for (int i = 0; i < (1 << (h - 1)); i++){
        // 実現可能かどうかのフラグ
        bool Flag = true;
        int sm = 0;
        vector<int> a;
        int num = 1;
        rep(j, h - 1){
            if(((i >> j) & 1) == 1) {
                sm++;
                a.push_back(num);
                num = 0;
            }
            num++;
        }
        a.push_back(num);
        int num1[a.size()];
        fill(num1, num1 + a.size(), 0);
        rep(j, w){
            // 線を足すかどうかのフラグ
            bool flag = false;
            int num2[a.size()];
            fill(num2, num2 + a.size(), 0);
            int idx = 0;
            rep(l, a.size()){
                rep(m, a[l]){
                    if (s[idx][j] == '1') num2[l]++;
                    idx++;
                }
            }
            rep(l, a.size()){
                if (num1[l] + num2[l] > k){
                    flag = true;
                }
            }
            if (flag){
                sm++;
                rep(l, a.size()) if(num2[l] > k) Flag = false;
                rep(l, a.size()) num1[l] = num2[l];
            }else{
                rep(l, a.size()) num1[l] += num2[l];
            }
            // rep(l, a.size()) cout << num1[l] << " ";
            // cout << endl;
            // cout << sm << endl;
        }
        if (Flag){
            ans = min(ans, sm);
        }
        // rep(i, a.size()){
        //     cout << a[i] << " ";
        // }cout << endl;
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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 add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> vs(N);
    REP(i,N) cin >> vs[i];
    string ans;
    auto dfs = [&](auto && self, int cur, int a, int b, int c) -> bool{
        if(cur == N) return true;

        if(vs[cur] == "AB"){
            if(a == 0 && b == 0) return false;
            if(0 < a && self(self, cur+1, a-1, b+1, c)){
                ans.push_back('B');
                return true;
            }
            if(0 < b && self(self, cur+1, a+1, b-1, c)){
                ans.push_back('A');
                return true;
            }
            return false;
        }

        if(vs[cur] == "AC"){
            if(a == 0 && c == 0) return false;
            if(0 < a && self(self, cur+1, a-1, b, c+1)){
                ans.push_back('C');
                return true;
            }
            if(0 < c && self(self, cur+1, a+1, b, c-1)){
                ans.push_back('A');
                return true;
            }
            return false;
        }

        if(vs[cur] == "BC"){
            if(b == 0 && c == 0) return false;
            if(0 < b && self(self, cur+1, a, b-1, c+1)){
                ans.push_back('C');
                return true;
            }
            if(0 < c && self(self, cur+1, a, b+1, c-1)){
                ans.push_back('B');
                return true;
            }
            return false;
        }
        return false;
    };

    dfs(dfs, 0, A, B, C);
    reverse(ans.begin(), ans.end());
    if(ans.size() < N) cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        for(auto x : ans) cout << x << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 14508
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  ll N;
  cin >> N;
  double pitwo = 6.28318530717958623200;
  cout << setprecision(10) << N * pitwo << endl;

  return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int mx=200010;
long long tree[4*mx];
long long arr[mx],vv[mx],n;
void update(int node,int l,int r,int p,long long val){
	if(l==p && p==r){
		tree[node]=val;
		return ;
	}
	if(l>p || r<p)return;
	int mid=(l+r)>>1;
	update(node*2,l,mid,p,val);
	update(node*2+1,mid+1,r,p,val);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}

long long query(int node,int l,int r,int p,int q){
	if(l>q || r<p)return -1;
	if(p<=l && r<=q)return tree[node];
	int mid=(l+r)>>1;
	return max(query(node*2,l,mid,p,q),query(node*2+1,mid+1,r,p,q));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	long long ma=0;
	for(int i=1;i<=n;i++)cin>>arr[i];
	for(int i=1;i<=n;i++)cin>>vv[i];
	for(int i=1;i<=n;i++){
		long long kk=query(1,1,n,0,arr[i])+vv[i];
		update(1,1,n,arr[i],kk);
		ma=max(ma,kk);
	}
	cout<<ma<<endl;

	return 0;
}

Measured memory_bytes: 8448
#import 
#=input()
n=int(input())
#=map(int,input().split())
l=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

cnt = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            q = [l[i],l[j],l[k]]
            q.sort()
            if (len(q) == len(set(q))) and (q[0] + q[1] > q[2]):
                cnt += 1
print(cnt)


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

typedef long long ll;

int main() {
    ll k;
    cin >> k;
    ll ad = 1;
    ll sum = 0;
    while (k > 0) {
        sum += ad;
        k /= 2;
        ad *= 2;
    }
    cout << sum << 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;

bool is_prime[100000];
double prime[10000];

int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i < 100000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = i * 2; j < 100000; j += i)is_prime[j] = false;
		}
	}
	int m; double a, b;
	while (scanf("%d%lf%lf", &m, &a, &b), m) {
		int Max = 0, P, Q;
		for (int i = 0; prime[i] * 2 <= m; i++) {
			int j = upper_bound(prime, prime + p, prime[i] / a*b) - prime - 1;
			int k = upper_bound(prime, prime + p, m / prime[i]) - prime - 1;
			j = min(j, k);
			if (j < 0)continue;
			if (Max < prime[i] * prime[j] && prime[j] / (double)prime[i] >= a / b) {
				Max = prime[i] * prime[j]; P = prime[i]; Q = prime[j];
			}
		}
		printf("%d %d\n", P, Q);
	}
}

Measured memory_bytes: 3360
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void rread(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int mod=1e9+7;
int main(){
	int n;rread(n);
	int now=1;
	rep(i,1,n)now=1ll*now*i%mod;
	printf("%d\n",now);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll res=0;
  for(ll i=1;i<=N;i++){
    ll d=N/i;
    res+=i*d*(d+1)/2;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n)for(int i=0;i<n;i++)
int X,Y,Z,N;
int V[4],E[51],A[51];
double dp[51][5000];
int main() {
	while(scanf("%d %d %d",&X,&Y,&Z),(X|Y|Z)) {
		rep(i,X)
			scanf("%d",&V[i]);
		rep(i,51)
			E[i]=A[i]=0;
		rep(i,Z)
			scanf("%d",&N),scanf("%d %d",&E[N],&A[N]);
		rep(i,51) rep(j,5000)
			dp[i][j]=0;
		dp[0][0]=1;
		rep(i,Y) rep(j,5000) {
			if(!dp[i][j]) continue;
			rep(k,X) {
				int tx=min(Y,i+V[k]),value=j;
				if(E[tx]==2) value+=A[tx];
				if(E[tx]==3) value=max(value-A[tx],0);
				if(E[tx]==1) tx=min(Y,tx+A[tx]);
				dp[tx][value]+=dp[i][j]/X;
			}
		}
		double sum=0;
		rep(i,5000)
			sum+=i*dp[Y][i];
		printf("%d\n",(int)sum);
	}
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N;
    cin >> N;
    int a[N];
    map<int,int> m;
    rep(i,N) {
        cin >> a[i];
        int x=a[i]-1;
        m[x]++;
        x++;
        m[x]++;
        x++;
        m[x]++;
    }
    int ans=0;
    for(auto P:m){
        ans=max(ans,P.second);
    }
    cout << ans << endl;
    



}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

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

    return 0;
}

Measured memory_bytes: 3620