akhauriyash/Code-Regression huggingface dataset:
N=int(input())
costs = list(map(int, input().split()))

from collections import defaultdict
dp = defaultdict(int)
for i in range(len(costs)):
    dp[i]=0 

#初期設定
dp[0] = 0
dp[1] = abs(costs[1]-costs[0])
    
for i in range(2, len(costs)):
    step_cost= abs(costs[i]-costs[i-1])+dp[i-1]
    jump_cost= abs(costs[i]-costs[i-2])+dp[i-2]
    if step_cost > jump_cost:
        dp[i] = jump_cost
    else:
        dp[i] = step_cost

print(dp[N-1])

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

int main() {
  string N;
  cin >> N;
  if (N[1] == N[2]) {
    if (N[0] == N[1] || N[2] == N[3]) {
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    int diff = b-a;
    cout << diff*(diff-1)/2-a;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<fstream>

int main(){
	std::vector<int> x(5);
	int k;

	for(int i=0;i<5;i++){
		std::cin >> x[i];
	}
	std::cin >> k;

	if(x[4]-x[0] > k) std::cout << ":(" << std::endl;
	else std::cout << "Yay!" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(int i=0; i<3; ++i){
        int a[2] = {0};
        for(int j=0; j<2; ++j){
            for(int k=0; k<3; ++k){
                int tmp;
                cin >> tmp;
                a[j] *= 60;
                a[j] += tmp;
            }
        }
        int b = a[1] - a[0];
        cout << (b/3600) << ' ' << (b%3600/60) << ' ' << (b%60) << endl;
    }
}

Measured memory_bytes: 0
mod = 10**9+7
n,m=map(int,input().split())
dp=[1]*(n+1)
for i in range(m):
    dp[int(input())]=0
    
for i in range(2,n+1):
    if dp[i]!=0:
        dp[i]=dp[i-1]+dp[i-2]
        
print(dp[n]%mod)

Measured memory_bytes: 460020
q = int(input())
p = [False]*(10**5)
c = [0]*(10**5)
temp = [True]*(10**5)
temp[0] = False
temp[1] = False
for i in range(2, 10**5):
  c[i] = c[i-1]
  if temp[i]:
    temp[2*i::i] = [False]*(len(temp[i+i::i]))
    if temp[(i+1)//2] and i%2:
      c[i] += 1

for _ in range(q):
  l, r = map(int, input().split())
  print(c[r] - c[l-1])

Measured memory_bytes: 6240
k,a,b = map(int,input().split())

st = max(0, (k-(a-1))//2)

if b-a > 2:
	ans = st*(b-a)+a
	if (k-(a-1)) % 2 == 1:
		ans += 1
	print(ans)
else:
	print(k+1)

Measured memory_bytes: 3060
def binary_search(S, t):
    start = 0
    end = len(S)
    while True:
        mid = start + (end-start)//2
        if S[mid] == t:
            return True
        elif (end-start) < 2:
            return False
        elif S[mid] < t:
            start = mid
        else:
            end = mid

if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    ans = 0
    for i in T:
        if binary_search(S, i):
            ans += 1
    print(ans)

Measured memory_bytes: 18704
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ii = pair<ll, ll>;

const ll MOD { 1000000007 };
const double PI = acos(-1.0);

#define stdfor(i, a, b) for(int i = (a); i < (b); ++i)
#define invfor(i, n, b) for(int i = (n); i--; )
#define foreach(a, b) for(auto& a : b)
#define cforeach(a, b) for(const auto& a : b)
#define sz(a) ((int)(a.size()))
#define fill(a,v) memset(a, v, sizeof a)
#define all(a) a.begin(), a.end()
#define in(a,b) ((b).find(a) != (b).end())
#define entre(l, i, r) (l<i&&i<r)
#define pb push_back

bool IsZero(int i) {
    return i == 0;
}


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

    vector<int> vida(N,0);

    int menor = 2000000000;
    int pos_menor = 0;

    for(int i = 0; i < N; ++i) {
        cin >> vida[i];
        if(vida[i] < menor) {
            menor = vida[i];
            pos_menor = i;
        }
    }    

    while(count_if(vida.begin(), vida.end(), IsZero) != N-1) {
        int novo_menor = 2000000000;
        int novo_pos = 0;
        for(int i = 0; i < N; ++i) {
            if(vida[i] && i != pos_menor) {
                vida[i] = vida[i]%menor;
                if(vida[i] < menor && vida[i]) {
                    novo_menor = vida[i];
                    novo_pos = i;
                }
            }
        }

        if(novo_menor < menor) {
            menor = novo_menor;
            pos_menor = novo_pos;
        }
    }

    cout << menor << endl;
 
    return 0;
}

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

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

    vector<int> v(N), c(N);
    for (int i = 0; i < N; i++)
        cin >> v[i];
    for (int i = 0; i < N; i++)
        cin >> c[i];

    int res = 0;
    for (int i = 0; i < N; i++) {
        int t = v[i] - c[i];
        if (t > 0)
            res += t;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n);
  set <int> have;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    have.insert(a[i]);
  }
  sort(a.begin(), a.end());
  if ((int)have.size() > 3) {
    cout << "No\n";
    return 0;
  }
  for (int x : have) {
    for (int y : have) {
      vector <int> b = {x, y};
      for (int i = 2; i < n; ++i) {
        b.push_back(b.rbegin()[0] ^ b.rbegin()[1]);
      }
      sort(b.begin(), b.end());
      if (a == b) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
}



Measured memory_bytes: 4224
use std::io;
use std::str::FromStr;


fn main() {
    let xs: Vec<i64> = reads();
    let x = xs[0];
    let y = xs[1];

    let g = gcd(x, y);
    let ans = cntprime(g);

    println!("{}", ans + 1);
}

#[allow(dead_code)]
fn getline() -> String {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().to_string()
}

#[allow(dead_code)]
fn read<T>() -> T where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn reads<T>() -> Vec<T> where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn printv<T>(xs: &[T]) where T : std::fmt::Display {
    xs.iter().fold("", |s, x| {
        print!("{}{}", s, x);
        " "
    });
    println!();
}

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 { return x; }
    gcd(y, x % y)
}

fn cntprime(mut x: i64) -> i64 {
    let ub = x;
    let mut res = 0;
    for i in 2..x+1 {
        if i * i > ub { break; }
        if x % i == 0 {
            res += 1;
            while x % i == 0 {
                x /= i;
            }
        }
    }
    if x > 1 { res += 1; }

    res
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define set multiset
#define null NULL
#define ort (b+s)/2

using namespace std;

typedef long long Lint;
typedef long double db;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<db,db> dd;
typedef pair<int,string> is;

const int maxn = 600020;
const int K = 320;
const int MOd = 1e9 + 7;

int ar[maxn], a;

void solve() {
	scanf("%d %d %d",&ar[1],&ar[2],&ar[3]);
	sort( ar+1, ar+1+3 );
	if( ar[1] == ar[2] && ar[2] != ar[3] ) {
		printf("Yes\n");
		return;
	}
	if( ar[1] != ar[2] && ar[2] == ar[3] ) {
		printf("Yes\n");
		return;
	}
	printf("No\n");
}
void solve2() {
	bool ok = 1;
	int a;
	scanf("%d",&a);
	for(int i=1,j;i<=a;i++) {
		scanf("%d",&j);
		if( j%2 == 0 ) {
			if( j % 3 != 0 && j % 5 != 0 ) ok = 0;
		}
	}
	if( ok ) printf("APPROVED\n");
	else printf("DENIED\n");
}
int main(  ) {


    int n = 1;
    //scanf("%d",&n);
    while( n-- ) solve2();

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a));
#define MINUS(a) memset(a,-1,sizeof(a));
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


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

    LIN(n) LIN(a) LIN(b)
    if( n == 1 ){
      puta( "Hello World" );
      return 0;
    }else{
      puta( a + b );
      return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 4000
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int B[MAXN+5][2005], W[MAXN+5][2005], f[2005][2005], w[MAXN+5], b[MAXN+5], n; string S;
int main()
{
	n = read(); for(rint i = 1, a; i <= n<<1; cin >> S, (S[0]=='W'?W:B)[i][a=read()]++, (S[0]=='W'?w:b)[a] = i, i++);
	for(rint i = 1, j; i <= n<<1; i++)
	{
		for(j = n; j; B[i][j] += B[i][j+1], W[i][j] += W[i][j+1], j--);
		for(j = n; j; B[i][j] += B[i-1][j], W[i][j] += W[i-1][j], j--);
	}	memset(f,0x3f,sizeof f), f[0][0] = 0;
	for(rint i = 0, j; i <= n; i++) for(j = 0; j <= n; j++)
		i<n ? f[i+1][j] = min(f[i+1][j],f[i][j]+B[b[i+1]-1][i+1]+W[b[i+1]-1][j+1]) : 0,
		j<n ? f[i][j+1] = min(f[i][j+1],f[i][j]+B[w[j+1]-1][i+1]+W[w[j+1]-1][j+1]) : 0; printf("%d\n",f[n][n]); return 0;
}

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

int main() {
    ll H;
    cin >> H;
    ll cnt = 0;
    while (H > 0) {
        H /= 2;
        cnt += 1;
    }
    ll ans = pow(2, cnt) - 1;
    printf("%lld", ans);
    return 0;
}

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

int main() {
	long long int m,i,k,n,flag=0;
//	string s,t,temp;
	cin>>n>>m;
	double a[n],j,sum=0,max1=0,l=0,b[n];
	for(i=0;i<n;i++)
	{
	    cin>>j;
	    j=(j+1)/2;
	    a[i]=j;
	    b[i]=a[i]+l;
	    l=b[i];
	}
	for(i=m-1;i<n;i++)
	{
	    sum=b[i]-b[i-m+1]+a[i-m+1];
	    if(sum>max1)
        {
            max1=sum;
        }
	}
	cout<<fixed<<setprecision(12)<<max1;


	return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(), m = scanner.nextInt(), l = scanner.nextInt();
		long[][] a = new long[n][m], b = new long[m][l];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				a[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < l; ++j) {
				b[i][j] = scanner.nextInt();
			}
		}
		long[][] c = new long[n][l];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < l; ++j) {
				for (int k = 0; k < m; ++k) {
					c[i][j] += a[i][k] * b[k][j];
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < l; ++j) {
				if (j != 0) System.out.print(' ');
				System.out.print(c[i][j]);
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 55572
#include<cstdio>
#include<iostream>
using namespace std;
int n, e; long long int adj[105][105];
long long int INFTY = (1LL<<32);
void floyd()
{
  for(int k=0; k<n; k++)
    for(int i=0; i<n; i++)
    {
      if(adj[i][k] == INFTY) continue;
      for(int j=0; j<n; j++)
      {
        if(adj[k][j] == INFTY) continue;
        adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
      }
    }
}

int main()
{
  scanf("%d%d", &n, &e);
  int s, t, d;
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<n; j++)
      adj[i][j] = INFTY;
    adj[i][i] = 0;
  }
  for(int i=0; i<e; i++)
  {
    scanf("%d%d%d", &s, &t, &d);
    adj[s][t] = d;
  }
  floyd();
  for(int i=0; i<n; i++)
  {
    if(adj[i][i] != 0)
    {
      printf("NEGATIVE CYCLE\n"); return 0;
    }
  }
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<n; j++)
    {
      if(j) printf(" ");
      if(adj[i][j] == INFTY)
        printf("INF");
      else printf("%lld", adj[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 3284
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
 
N,A,B,C,D = map(int,input().split())
S = list(input())
SA = deepcopy(S)
SB = deepcopy(S)
SA[B-1] = "#"
SB[D-1]=  "#"
 
bool=False
for i in range(A,max(D,C)):
    if S[i]=="#" and S[i-1]=="#":
        print("No")
        exit()
for i in range(B-1,D):
    if i >= N-1:
        break
    if S[i] == "." and S[i-1]=="." and S[i+1]==".":
        bool = True
        break
if bool:
    print("Yes")
else:
    bool1,bool2,bool3 = True,True,True
    #Bを先にDに進める戦略
    for i in range(A,C):
        if SB[i-1]=="#" and SB[i]=="#":
            bool1 = False
            break
    #Aを先に進めるため最初進められるかどうかの判定
    for i in range(A,C):
        if SA[i-1]=="#" and SA[i]=="#":
            bool2 = False
            break
    SA[B-1]="."
    SA[C-1]="#"
    #Aを先にCに進める戦略
    for i in range(B,D):
        if SA[i-1]=="#" and SA[i]=="#":
            bool3 = False
            break
    if bool1 or(bool2 and bool3):
        print("Yes")
    else:
        print("No")


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

int main(){
    int x, a;
    cin >> x >> a;
    if (x < a){
        cout << 0 << endl;
    }
    else{
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
<?php
define('M', 1000000007);

$N = (int)fgets(STDIN);
$As = array_map('intval', explode(' ', trim(fgets(STDIN))));

$mark = [];

if ($N % 2 === 0) {
    $pattern = 1;
    foreach ($As as $a) {
        if ($a % 2 === 0) {
            echo "0\n"; exit;
        }
        $left = $N / 2 - ($a + 1) / 2;
        $right = $N / 2 + ($a - 1) / 2;
        if (!isset($mark[$left])) {
            $pattern = ($pattern * 2) % M;
            $mark[$left] = true;
        } else if (!isset($mark[$right])) {
            $mark[$right] = true;
        } else {
            echo "0\n"; exit;
        }
    }
    echo "$pattern\n";
} else {
    $pattern = 1;
    $center = false;
    foreach ($As as $a) {
        if ($a % 2 === 1) {
            echo "0\n"; exit;
        }
        $left = ($N - 1) / 2 - $a / 2;
        $right = ($N - 1) / 2 + $a / 2;
        if ($a === 0) {
            if ($center) {
                echo "0\n"; exit;
            }
            $center = true;
            $mark[$left] = true;
        }
        else if (!isset($mark[$left])) {
            $pattern = ($pattern * 2) % M;
            $mark[$left] = true;
        } else if (!isset($mark[$right])) {
            $mark[$right] = true;
        }
        else {
            echo "0\n"; exit;
        }
    }
    echo "$pattern\n";
}

Measured memory_bytes: 35308
a, b, c = map(int, input().split())
k = int(input())
 
for i in range(k):
  if a < b < c:
    break
  elif b <= a:
    b = b*2
  elif c <= b:
    c = c*2
 
if a < b < c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9208
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	int64_t ma;
	pair<int64_t, int64_t> p[1000];
	cin >> n;
	REP(i, n) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 1; i < n; i++) {
		ma = max(p[i - 1].first / p[i].first + (p[i - 1].first % p[i].first == 0 ? 0 : 1), p[i - 1].second / p[i].second+ (p[i - 1].second % p[i].second == 0 ? 0 : 1));
		p[i].first = p[i].first*ma;
		p[i].second = p[i].second*ma;
	}
	cout << p[n - 1].first + p[n - 1].second;
}


Measured memory_bytes: 256
let solve n m =
    if (n * 2) >= m
    then m / 2
    else n + (m - 2 * n) / 4;;

let () = 
    let (n, m) = Scanf.scanf "%d %d" (fun n m -> n, m) in
    print_int (solve n m);
    print_newline ();;


Measured memory_bytes: 384
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

struct block{
	LL w,s,v;
};

vector<block> vec;

const int N = 1e3, S = 1e4;
LL dp[N + 5][2 * S + 5];

bool cmp(block &A, block &B) {
	return A.s + A.w > B.s + B.w;
}

int n;

LL calc(int idx, int s) {
	if(n == idx) return 0;
	LL &res = dp[idx][s];
	if(res != -1) return res;
	res = calc(idx + 1,s);
	if(s - vec[idx].w >= 0) res = max(res, calc(idx + 1, min(vec[idx].s, s - vec[idx].w)) + vec[idx].v);
	return res;
}

void hora(int tc) {
	cin>>n;
	for(int i = 0;i < n;i++) {
		block A;
		cin>>A.w>>A.s>>A.v;
		vec.PB(A);
	}
	sort(vec.begin(),vec.end(), cmp);
	memset(dp,-1,sizeof dp);
	cout<<calc(0, 2 * S + 1)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 157440
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+10;
int n,data[MAXN];
int bin[MAXN][3];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>data[i];
	int bg=0,pos1,pos2,cnt1=0,cnt2=0;
	for(int i=1;i<=n;i+=2){
		cnt1++;
		bin[data[i]][1]++;
		if(bin[data[i]][1] > bg){
			bg=bin[data[i]][1];
			pos1=data[i];
		}
	}
	bg=0;
	for(int i=2;i<=n;i+=2){
		cnt2++;
		bin[data[i]][2]++;
		if(bin[data[i]][2]>bg){
			bg=bin[data[i]][2];
			pos2=data[i];
		}
	}
	int ans = cnt1 - bin[pos1][1] + cnt2;
	for(int i=1;i<=1e5;i++){
		if(i!=pos1){
			ans = min(ans,cnt1-bin[pos1][1]+cnt2-bin[i][2]);
		}
	}
	ans = min(ans,cnt2-bin[pos2][1]+cnt1);
	for(int i=1;i<=1e5;i++){
		if(i!=pos2){
			ans=min(ans,cnt2-bin[pos2][1]+cnt1-bin[i][1]);
		
		}
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 1792
import java.util.*;

public class Main {



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(Math.min(p + q, Math.min(q + r, r + p)));
        return;
    }


}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const ll llf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
int n;
typedef pair<ll,ll> pii;
pii a[1010];
ll d[45],k=31;
int cmp(ll a,ll b){
	return a>b;
}
void solve(ll x,ll y){
	char s[1010]={0};
	for(int i=0;i<k;i++){
		ll l=abs(x+d[i])+abs(y),r=abs(x-d[i])+abs(y);
		ll p=abs(x)+abs(y+d[i]),u=abs(x)+abs(y-d[i]);
		if(l<=r&&l<=p&&l<=u){
			x+=d[i];
			s[i]='L';
		}else if(r<=l&&r<=p&&r<=u){
			x-=d[i];
			s[i]='R';
		}else if(p<=l&&p<=r&&p<=u){
			y+=d[i];
			s[i]='D';
		}else if(u<=l&&u<=r&&u<=p){
			y-=d[i];
			s[i]='U';
		}
	}
	//cout<<x<<" "<<y<<endl;
	cout<<s<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>a[1].fi>>a[1].se;
	int o=abs((a[1].fi+a[1].se)%2);
	for(int i=2;i<=n;i++){
		cin>>a[i].fi>>a[i].se;
		if(abs((a[i].fi+a[i].se)%2)!=o){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=0;i<=30;i++){
		d[i]=(1ll<<i);
	}
	if(o==0){
		d[k++]=1;
	}
	sort(d,d+k,cmp);
	cout<<k<<endl;
	for(int i=0;i<k;i++){
		cout<<d[i]<<" "; 
	}
	cout<<endl;
	for(int i=1;i<=n;i++){
		solve(a[i].fi,a[i].se);
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

if 0 in a:
    set_a = list(set(a))
    set_a = sorted(set_a)
    if len(set_a) == 1:
        print("Yes")
    elif len(set_a) == 2:
        if 2*a.count(set_a[0]) == a.count(set_a[1]):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

else:
    if n%3 != 0:
        print("No")

    else:
        if len(set(a)) != 3 or a.count(list(set(a))[0]) != int(n/3) or a.count(list(set(a))[1]) != int(n/3) or a.count(list(set(a))[2]) != int(n/3):
            print("No")

        else:
            set_a = list(set(a))
            if set_a[0] == set_a[1]^set_a[2] and set_a[1] == set_a[2]^set_a[0] and set_a[2] == set_a[1]^set_a[0]:
                print("Yes")
            else:
                print("No")


Measured memory_bytes: 14592
#include <iostream>

using namespace std;

long long a, b, c, d, ans;

int main() {
  cin >> a >> b >> c >> d;
  ans = max(a * c, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define ENDL endl
using namespace std;
int main() {
  int i, N, n, d;
  while (cin >> N, N) {
    int x[200], y[200];
    x[0] = 0;
    y[0] = 0;
    int maxX = -10000, maxY = -10000, minX = 10000, minY = 10000;
    for (i = 1; i < N; i++) {
      cin >> n >> d;
      x[i] = x[n];
      y[i] = y[n];
      if (d == 0)
        x[i]--;
      if (d == 1)
        y[i]--;
      if (d == 2)
        x[i]++;
      if (d == 3)
        y[i]++;
    }
    for (i = 0; i < N; i++) {
      maxX = max(maxX, x[i]);
      minX = min(minX, x[i]);
      maxY = max(maxY, y[i]);
      minY = min(minY, y[i]);
    }
    cout << maxX - minX + 1 << ' ' << maxY - minY + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 2956
/*  
    Shiny, shiny, shiny boots of leather
    Whiplash girlchild in the dark
    Comes in bells, your servant, don't forsake him
    Strike, dear mistress, and cure his heart
    _________________________
    _________________________
    168 Hours of Solitude
    Quarantine_Day : 7
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long int       LL;
typedef vector<int>         VI;
typedef vector<LL>          VL;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<lint>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    string s;
    cin>>s;

    int n = s.size();

    vector<bool>dp(n + 1);
    dp[0] = true;

    REP(i, n)if(dp[i]){
        if(i + 5 <= n && s.substr(i, 5) == "dream") dp[i + 5] = true;
        if(i + 7 <= n && s.substr(i, 7) == "dreamer") dp[i + 7] = true;
        if(i + 5 <= n && s.substr(i, 5) == "erase") dp[i + 5] = true;
        if(i + 6 <= n && s.substr(i, 6) == "eraser") dp[i + 6] = true;
    }
    cout<<(dp[n]?"YES\n":"NO\n");

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;




int main(void) {
	int n, i, cnt = 0,tmp;
	vector<int> p;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", &tmp);
		p.push_back(tmp);
	}
	for(i = 1; i < n -1;i++){
		if (p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1)) {
			cnt++;
		}
		else if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1)) {
			cnt++;
		}
	}
	printf("%d", cnt);
	return 0;
}

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

int main()
{
    int a,b;
    int n=1;
   cin>>a>>b;
   while (n<b)
   {
       n*=2;
       a--;
       if(a==0) break;
   }
   n+=b*a;
   cout<<n<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define R register
int n, K;
long long Ans, tmp;
int main()
{
	scanf("%d %d", &n, &K);
	for(R int i = K + 1; i <= n; i++)
	{
		tmp = Ans;
		R int t = n / i;
		Ans += 1ll * t * (i - K);
		t = n % i;
		if(t >= K) Ans += t - K + 1;
	}
	if(K == 0) Ans -= n;
	printf("%lld\n", Ans);
	return 0;
}

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

using ll = long long;
using ld=long double;

ld d[8][8];
int main(){
    int a,b;
    cin>>a>>b;
    if(a>9 || b>9)
    cout<<"-1";
    else
    cout<<a*b;
    
    return 0;
}


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

using namespace std;

typedef long long ll;

int n,s[3000];

int sum = 0;

int main() {
//	freopen("input.txt", "r", stdin);
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> s[i];
		sum += s[i];
	}
	int mx = 0;
	if(sum%10)
		mx = max(mx,sum);
	for (int i = 0; i < n; ++i){
		if((sum-s[i])%10){
			mx = max(mx,sum-s[i]);
		}
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 256
#BinarySearchTree
class TreeNode():
    def __init__(self):
        self.key = None
        self.parent = None
        self.left = None
        self.right = None
    def inoder(self):
        r=[]
        if self.left:
            r += self.left.inoder()
        r += [self.key]
        if self.right:
            r += self.right.inoder()
        return r

    def preoder(self):
        r = [self.key]
        if self.left:
            r += self.left.preoder()
        if self.right:
            r += self.right.preoder()
        return r

class BinaryTree():
    def __init__(self):
        self.root = None

    def insert(self, z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def show(self):
        x = self.root
        print(" " + " ".join(map(str, self.root.inoder())))
        print(" " + " ".join(map(str, self.root.preoder())))
 
 
n = int(input())
Tree = BinaryTree()
for i in range(n):
    L = input().split()
    if L[0] == "insert":
        Node = TreeNode()
        Node.key = int(L[1])
        Tree.insert(Node)
    else:
        Tree.show()

Measured memory_bytes: 190472
def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)


def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)


x = int(input())
ans = LCM(x, 360) // x
print(ans)


Measured memory_bytes: 9008
process.stdin.on("data",function(c){
	(c+"").trim().split("\n").some(function(n,x){
		n=n.split(" ");
		var a=+n[0],b=+n[1],c=+n[2],d=+n[3],e=+n[4],f=+n[5],x;
		console.log((x=((c*e-b*f)/(a*e-b*d))).toFixed(3),((c-a*x)/b).toFixed(3));
	});
}).resume();

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

int n, x, y, a[2005];

int main()
{
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	if(n == 1) printf("%d\n", abs(a[1]-y));
	else printf("%d\n", max(abs(a[n]-y), abs(a[n-1]-a[n])));
}


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

int main(){
    int N;
    char S[11];
    int K;

    //input
    cin >> N;
    cin >> S;
    cin >> K;

    for(int i = 0; i < N; i++){
        if(S[i] != S[K-1]){
            S[i] = '*';
        }
    }

    //output
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

void solve() {
	ll n, W;
	cin >> n >> W;
	vl v(n), w(n);
	rep(i, n) cin >> w[i] >> v[i];
	
	vvl dp(n+1, vl(W+1,0));
	FOR(i, 1, n)
		FOR(j, 1, W) {
			if (j >= w[i-1])
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
			else dp[i][j] = dp[i-1][j];
		}

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

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


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

const int INF = 1001001001;

int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

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

    rep(i, n-1) {
        if(s[i] != s[i+1]) {
            ans++;
        }
    }
    
    cout << ans;
    
    cout << endl;
    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



int n, a[202020], cnt[202020];
int d[30];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		for(int j = 0; j < 30; j++){
			if(a[i] >> j & 1){
				d[j]++;
			}
		}
	}
	
	for(int i = 0; i < 30; i++){
		for(int j = 0; j < n; j++){
			if((d[i]&1) ^ (a[j]>>i&1)){
				cnt[j] += 1<<i;
			}
		}
	}
	for(int i = 0; i < n; i++){
		cout << cnt[i] << " ";
	}
	cout << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 5184
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
using System.IO;
using System.Text;

//============================================================================
namespace Sweet
{
    class Program
    {
        static StreamWriter writer = null;
        //============================================================================
        static void setstdio(string[] args)
        {
            if (0 < args.Length)
            {
                // Redirect standard input from the console to the input file.
                Console.SetIn(new StreamReader(args[0]));
                if (args.Length == 2)
                {
                    // Attempt to open output file.
                    writer = new StreamWriter(args[1]);
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);
                }
            }
        }
        //============================================================================
        static int Swing()
        {
            int a,i,cnt;
            string ring = Console.ReadLine();
            string words = Console.ReadLine();
            string str;

            ring=ring.ToUpper();
            //words = words.ToUpper();
            for (a=i = cnt = 0; ; i++)
            {
                if (a < 0)
                {
                    words = Console.ReadLine();
                    //words = words.ToUpper();
                }
                while (words.IndexOf(" ") == 0)
                    words = words.Substring(1);
                a = words.IndexOf(" ");
                if (0 <= a)
                {
                    str = words.Substring(0, a);
                    str = str.ToUpper();
                }
                else
                    str = words.ToUpper();
                if (words == "END_OF_TEXT")
                    break;
                if (ring == str)
                    cnt++;
                if (0 < a)
                    words = words.Substring(a + 1);
            }
            Console.WriteLine("{0}", cnt);
            return 0;
        }

        private static bool isalpha(char v)
        {
            if ('a' <= v && v <= 'z' || 'A' <= v && v <= 'Z')
                return true;
            return false;
        }

        //============================================================================
        static void Main(string[] args)
        {
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            setstdio(args);

            while(Swing()!=0);
            //sw.Stop();
            //Console.WriteLine("duration = {0}", sw.Elapsed);
            if (writer != null)
                writer.Close();
            //Console.ReadLine();
        }
        //============================================================================
    }
}

Measured memory_bytes: 9696
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define, typedef */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
typedef long long ll;


/* main関数 */
int main(void) {
	int n;
	cin >> n;
	vector<int> l;
	l.reserve(n);
	rpt(i, n) {
		int h;
		cin >> h;
		l.push_back(h);
	}

	sort(l.begin(), l.end());
	ll count = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l[i] + l[j] > l[k]) count++;
				else break;
			}
		}
	}

	cout << count;

	return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

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

  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  sort(a.begin(), a.end());

  cout << a[N-1] - a[0] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

#define PI 3.1415926535

typedef struct{
  double x;
  double y;
}grid_chart;

int main()
{
  grid_chart t;
  t.x = t.y = 0;
  double angle = 0;
  while(1){
    double n, a;
    scanf("%lf,%lf", &n, &a);
    if(n == 0 && a == 0)
      break;
    else{
      t.x += n * sin(PI * angle / 180);
      t.y += n * cos(PI * angle / 180);
    }
    angle += a;
  }
  printf("%d\n%d\n", int(t.x), int(t.y));
}

Measured memory_bytes: 1216
n = int(input())
li = list(map(int, input().split()))
li_k = list(map(lambda n: len(str(n))-1, li))

if 0 in li:
    print(0)
elif sum(li_k) > 18:
    print(-1)
else:
    ans = li[0]
    for i in li[1:]:
        ans *= i
        if ans > 1000000000000000000:
            break
    if ans > 1000000000000000000:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 87984
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

template<class T>
vector<int> convex(vector<T> x, vector<T> y)
{
    int n = (int)x.size();
    vector<pair<pair<T,T>, int>> Pt(n);
    for (int i=0; i<n; i++)
        Pt[i] = make_pair(make_pair(x[i], y[i]), i);
    sort(Pt.begin(), Pt.end());
    vector<int> P(n);
    for (int i=0; i<n; i++)
        P[i] = Pt[i].second;

    vector<int> ans;

    auto f = [&](int i)
    {
        while ((int)ans.size()>=2)
        {
            int t = (int)ans.size();
            T p = (x[P[i]]-x[ans[t-1]])*(y[ans[t-1]]-y[ans[t-2]])
                - (x[ans[t-1]]-x[ans[t-2]])*(y[P[i]]-y[ans[t-1]]);
            if (p < 0)
                ans.pop_back();
            else
                break;
        }
        ans.push_back(P[i]);
    };

    ans.push_back(P[0]);
    ans.push_back(P[1]);
    for (int i=2; i<n; i++)
        f(i);
    ans.push_back(P[n-2]);
    for (int i=n-3; i>=0; i--)
        f(i);
    ans.pop_back();
    return ans;
}

#include <iostream>
#include <cmath>

int main()
{
    int N;
    cin>>N;
    vector<double> x(N), y(N);
    for (int i=0; i<N; i++)
        cin>>x[i]>>y[i];

    vector<int> C = convex(x, y);
    //for (int c: C)
    //    cout<<c<<endl;
    int cn = (int)C.size();
    vector<double> ans(N);
    double pi = acos(-1.0);
    for (int i=0; i<cn; i++)
    {
        double x0 = x[C[(i+cn-1)%cn]] - x[C[i]];
        double y0 = y[C[(i+cn-1)%cn]] - y[C[i]];
        double x1 = x[C[(i+1)%cn]] - x[C[i]];
        double y1 = y[C[(i+1)%cn]] - y[C[i]];
        double s = acos((x0*x1+y0*y1)/hypot(x0,y0)/hypot(x1,y1));
        ans[C[i]] = (pi-s)/(2*pi);
    }
    for (double a: ans)
        printf("%.20f\n", a);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

char s[60][30], buf[2];
int d[60][30][60][30][2];
struct st {
	int lx, ly, rx, ry, c;
	bool b;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int C(char c) {
	if (isdigit(c))return c - '0';
	return 0;
}
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		rep(i, h)rep(j, w) {
			scanf("%s", buf); s[i][j] = buf[0];
		}
		rep(j, w) {
			int i = h - 1;
			if (s[i][j] == 'S') {
				for (int k = -2; k <= 2; k++) {
					int a = 3 - abs(k);
					for (int t = 1; t <= a; t++) {
						int nx = i + k, ny = j + t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							d[i][j][nx][ny][0] = C(s[nx][ny]);
							que.push({ i,j,nx,ny,C(s[nx][ny]),0 });
						}
						nx = i + k, ny = j - t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							d[nx][ny][i][j][1] = C(s[nx][ny]);
							que.push({ nx,ny,i,j,C(s[nx][ny]),1 });
						}
					}
				}
			}
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.lx][p.ly][p.rx][p.ry][p.b] != p.c)continue;
			for (int k = -2; k <= 2; k++) {
				int a = 3 - abs(k);
				for (int t = 1; t <= a; t++) {
					if (p.b) {
						int nx = p.lx + k, ny = p.ly + t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							int&u = d[p.lx][p.ly][nx][ny][!p.b];
							int c = p.c + C(s[nx][ny]);
							if (u > c) {
								u = c; que.push({ p.lx,p.ly,nx,ny,u,!p.b });
							}
						}
					}
					else {
						int nx = p.rx + k, ny = p.ry - t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							int&u = d[nx][ny][p.rx][p.ry][!p.b];
							int c = p.c + C(s[nx][ny]);
							if (u > c) {
								u = c; que.push({ nx,ny,p.rx,p.ry,u,!p.b });
							}
						}
					}
				}
			}
		}
		int Min = INF;
		rep(i, h)rep(j, w)rep(k, h)rep(t, w)rep(y, 2) {
			if (s[i][j] == 'T' || s[k][t] == 'T')Min = min(Min, d[i][j][k][t][y]);
		}
		if (Min == INF)puts("-1");
		else printf("%d\n", Min);
	}
}

Measured memory_bytes: 28620
package main

import (
	"fmt"
)

func main() {
	var X int64
	fmt.Scan(&X)
	var y int64 = 100
	ctr := 0
	for {
		if y >= X {
			fmt.Println(ctr)
			return
		}
		y += y / 100
		ctr++
	}
}


Measured memory_bytes: 1756
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int a , b;
int vis[N];
int tim[N][2];
vector < int > adj[N];

void bfs(int s , int id){
    queue < int > q;
    q.push(s);
    tim[s][id] = 1;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(auto v : adj[u]){
            if(tim[v][id] == 0){
                tim[v][id] = tim[u][id] + 1;
                if(id == 0 && tim[v][1] <= tim[v][0]){
                    a = v;
                    b = u;
                    return;
                }
                q.push(v);
            }
        }
    }
}

int dfs(int u , int p){
    int ret = 0;
    for(auto v : adj[u]){
        if(v == p || (a == u && b == v) || (a == v && b == u))
            continue;
        ret += dfs(v , u);
    }
    return ret + 1;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i < n; i++){
        int u , v;
        scanf("%d%d" , &u , &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    bfs(1 , 1);
    bfs(n , 0);
    int A = dfs(1 , -1);
    int B = dfs(n , -1);
    cerr << a << " " << b << " " << A << " " << B <<  endl;
    puts( (A <= B) ? "Snuke" : "Fennec");
}




Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}



int main() {
   fast();
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++){
    cin>>a[i];
   }
   int tri=0;
   for(int i=0;i<n;i++){
    tri=__gcd(a[i],tri);
   }
   for(int i=0;i<n;i++){
      a[i]=a[i]/tri;
   }
   if(n==1){
    cout<<mod-7<<"\n";
    return 0;
   }
   if(n==2){
    cout<<max(a[0]*tri,a[1]*tri);
    return 0;
   }
   
   vector<int> v;
   for(int i=1;i<=sqrt(a[0]);i++){
    if(a[0]%i==0){
      v.pb(i);
      v.pb(a[0]/i);
    }
   }
   for(int i=1;i<=sqrt(a[1]);i++){
    if(a[1]%i==0){
      v.pb(i);
      v.pb(a[1]/i);
    }
   }
   sort(v.begin(),v.end());
   for(int i=v.size()-1;i>=0;i--){
    int count=0;
      for(int j=0;j<n;j++){
          if(a[j]%v[i]==0){
            count++;
          }
      }
      if(count==n-1){
        cout<<tri*v[i]<<"\n";
        return 0;
      }
   }
   cout<<tri<<"\n";
   return 0;


}


Measured memory_bytes: 3980
#include <iostream>

int main(){
    std::string s;
    std::cin >> s;

    long long k;
    std::cin >> k;

    int sz = s.size();
    char ans = '1';
    int i = 0;
    while(i < sz){
        if('1' != s.at(i)){
            ans = s.at(i);
            break;
        }
        ++i;
    }

    if(k <= i){
        ans = '1';
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256