akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[50],b[50];
int A[51],B[51];
int dp[51][51][51][51][2][2];
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==-1)a[i]=0;
    A[i+1]=A[i]+a[i];
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
    if(b[i]==-1)b[i]=0;
    B[i+1]=B[i]+b[i];
  }
  memset( dp, -1, sizeof(dp));
  for(int x=n;x>=0;x--)
    for(int y=m;y>=0;y--)
      for(int s=x;s>=0;s--)
        for(int t=y;t>=0;t--)
          for(int f=1;f>=0;f--)
            for(int p=1;p>=0;p--){
              int &res=dp[x][y][s][t][f][p];
              if(p==0){
                res=-1e9;
                if(f==1&&x==s&&y==t)res=max(res,0);
                else res=max(res,dp[x][y][x][y][x==s&&y==t][1]+A[x]-A[s]-B[y]+B[t]);
                if(x<n&&a[x]==0)res=max(res,dp[x+1][y][s][y][0][1]);
                if(x<n&&a[x]>0)res=max(res,dp[x+1][y][s][t][0][1]);
              }else{
                res=1e9;
                if(f==1&&x==s&&y==t)res=min(res,0);
                else res=min(res,dp[x][y][x][y][x==s&&y==t][0]+A[x]-A[s]-B[y]+B[t]);
                if(y<m && b[y]==0)res=min(res,dp[x][y+1][x][t][0][0]);
                if(y<m && b[y]>0)res=min(res,dp[x][y+1][s][t][0][0]);
              }
            }
  cout<<dp[0][0][0][0][0][0]<<endl;
  return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = (ull)1e9 + 7;

int main(void)
{
	ll n, m, qs;
	cin >> n >> m >> qs;
	vector<map<ll,ll>> r(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		r[a][b]++;
	}
	vector<P> qv(qs);
	rep(i, qs) {
		cin >> qv[i].first >> qv[i].second;
		qv[i].first--; qv[i].second--;
	}

	vector<vector<ll>> sums(n, vector<ll>(n + 1, 0));
	rep(i, n) {
		rep(j, n) {
			sums[i][j + 1] = sums[i][j] + r[i][j];
		}
	}
	vector<vector<ll>> allSums(n, vector<ll>(n, 0));
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n;j++) {
			for (int k = i; k <= j; k++) {
				allSums[i][j] += sums[k][j+1];
			}
		}
	}

	rep(i, qs) {
		cout << allSums[qv[i].first][qv[i].second] << endl;
	}
	return 0;
}


Measured memory_bytes: 22144
use proconio::{input};
use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Clone, Eq, PartialEq)]
struct Node {
    cost: i64,
    x: i64,
    y: i64
}

impl Ord for Node {
    fn cmp(&self, other: &Node) -> Ordering {
        self.cost.cmp(&other.cost).reverse()
    }
}
impl PartialOrd for Node {
    fn partial_cmp(&self, other: &Node) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

// #[fastout]
#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    input! {
        H: i64,
        W: i64,
        CH: i64,
        CW: i64,
        DH: i64,
        DW: i64,
        S: [String; H],
    }

    let mut Q = BinaryHeap::new();
    Q.push(Node { cost: 0, x: CW - 1, y: CH - 1 });

    let inf = W * H;
    let mut C = vec![vec![inf; W as usize]; H as usize];

    let push = |qq: &mut BinaryHeap<Node>, cc: &mut Vec<Vec<i64>>, x, y, cost| {
        if x < 0 || W <= x { return; }
        if y < 0 || H <= y { return; }

        let xx = x as usize;
        let yy = y as usize;

        if S[yy].as_bytes()[xx] == "#".as_bytes()[0] { return; }

        if cc[yy][xx] <= cost { return; }
        cc[yy][xx] = cost;

        qq.push(Node { cost: cost, x: x, y: y });
    };

    let mut ans = -1;

    while let Some(Node {cost, x, y }) = Q.pop() {
        if x == DW - 1 && y == DH - 1 { ans = cost; break; }

        push(&mut Q, &mut C, x - 1, y, cost);
        push(&mut Q, &mut C, x + 1, y, cost);
        push(&mut Q, &mut C, x, y - 1, cost);
        push(&mut Q, &mut C, x, y + 1, cost);

        for xx in x-2..x+3 {
            for yy in y-2..y+3 {
                push(&mut Q, &mut C, xx, yy, cost + 1);
            } 
        }
    }

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


Measured memory_bytes: 12156
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();
            String T = sc.next();
            int A = sc.nextInt();
            int B = sc.nextInt();
            String U = sc.next();

            int a = S.equals(U) ? --A : A;
            int b = T.equals(U) ? --B : B;

            System.out.println(a + " " + b);
        }
    }

}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int n = S.length()-1;
        long ans = 0;
        for(int i = 0;i < (1 << n);i++){
            String x = ""+S.charAt(0);
            long sum = 0;
            for(int j = 0;j < n;j++){
                if((i & (1<<j)) >= 1){
                    x += "+" + S.charAt(j+1);
                }
                else{
                    x += S.charAt(j+1);
                }
            }
            String[] split = x.split("\\+");
            for(int j = 0;j < split.length;j++){
                sum += Long.valueOf(split[j]);
            }
            ans += sum;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24788
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *h = map(int, read().split())
ans = 0
tmp = 0
for i in range(1, n):
    # print(tmp)
    if h[i] <= h[i - 1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)
print(ans)

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

int main(){
  int A,B,C,X;
  cin >> A>>B>>C>>X;
  int Y;
  Y=X/50;
  int ans=0;
  for (int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(i*10+j*2+k==Y){
          ans++;
        }
      }
    }
  }
  cout << ans <<endl;
  
    
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int k;
	cin >> k;
	--k;
	vector<int> arr = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	cout << arr[k];
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
s=[0]*(n+1)
s[0]=a[0]
for i in range(n):
    s[i+1]=s[i]+a[i]
s.sort()
ret=0
cnt=1
bef=-10**20
for i in range(n+1):
    if bef!=s[i]:
        ret+=cnt*(cnt-1)//2
        bef=s[i]
        cnt=1
    else:
        cnt+=1
ret+=cnt*(cnt-1)//2
print(ret)

Measured memory_bytes: 25976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,m,arr[100005],pen[100005];
     cin>>t>>m;
     for(int i=0;i<=t;i++)
        arr[i]=0,pen[i]=0;
     ll cnt=0,p=0;
     for(int i=0;i<m;i++)
     {
         string str;
         ll a;
         cin>>a>>str;
         if(arr[a]==1)
            continue;
         else if(str=="WA")
             pen[a]++;
         else if(str=="AC")
            arr[a]=1,cnt++,p+=pen[a];

     }
     cout<<cnt<<" "<<p<<endl;
}


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

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


bool contain(char a){
    string test = "ATGC";
    rep(i,4){
        if(a==test[i])return true;
    }
    return false;
}
int main(){

    string s;cin >> s;
    int len = s.length();
    int counter = 0;
    int ans = 0;
    rep(i,len){
       if(contain(s[i])){
            counter++;
            ans = max(ans,counter);
       }else {
           counter = 0;
       }
    }

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

Measured memory_bytes: 3532
#include<stdio.h>
int main()
{
    int i,j;
    
    int N;
    scanf("%d ",&N);
    char S[N];
    int X[N];
    X[0]=0;
    int b=0;
    
    for(i=0; i<N; i++)
    {
     scanf(" %c",&S[i]);   
        if(S[i]=='I')
        {
        X[i+1]=X[i]+1;
        }
        if(S[i]=='D')
        {
            X[i+1]=X[i]-1;
        }
    }
    
    for(i=1; i<N+1; i++)
    {
    
      if(X[i] > b)
      {
          b = X[i];
      }
    }
    printf("%d ",b);
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r;
    cin >> r;
    cout << 3 * pow(r, 2);

    return 0;
}


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

using namespace std;

int main() {

  array<array<int, 18>, 301> dp;
  for ( auto ar : dp ) {
	fill( ar.begin(), ar.end(), 0 );
  }
  // dp[ 現在の金 ][ 最大sq ]
  dp[ 0 ][ 1 ] = 1;
  for ( int i = 1; i <= 300; i++ ){
	for ( int j = 1; j <= 17; j++ ) {
	  for ( int k = 0; k <= j; k++ ) {
		if ( i - j * j >= 0 ) {
		  dp[ i ][ j ] += dp[ i - j * j ][ k ];
		}
	  }
	}	  
  }

  array<int, 301> ans;
  fill( ans.begin(), ans.end(), 0 );
  for ( int i = 1; i <= 300; i++ ) {
	for ( int j = 1; j <= 17; j++ ) {
	  ans[ i ] += dp[ i ][ j ];
	}
  }
  
  while( true ) {
	int n = 0;
	cin >> n;
	if ( n == 0 ) break;
	cout << ans[ n ] << endl;
  }
}
  

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

#define int long long

const int N = 200005;

int n, k, a[N], f[N];

bool check(int t) {
	int res = 0;
	for (int i = 1; i <= n; i++) {
		int u = t / f[i];
		res += max(0LL, a[i] - u);
	}
	if (res <= k) return true;
	return false;
}

main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (int j = 1; j <= n; j++) {
		cin >> f[j];
		f[j] = -f[j];
	}
	sort(f + 1, f + n + 1);
	for (int j = 1; j <= n; j++) {
		f[j] = -f[j];
	}
	int l = 0, r = 1e13;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (check(mid)) {
			r = mid;
		} else {
			l = mid;
		} 
	}
	for (int i = l; i <= r; i++) {
		if (check(i)) {
			return cout << i, 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int d,n,cnt = 0,tmp = 1;
	cin >> d >> n;
	for(int i = 0;i < d;i++) tmp *= 100;
	for(int i = 1;;i++){
		if(i % tmp == 0 && i % (tmp * 100)) cnt++;
		if(cnt == n){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let p: i32 = read();

    let ans = (a * 3 + p) / 2;

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

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

    REP(i,1300){
        double tax_8 = i*0.08;
        double tax_10 = i*0.1;
        if(a == (int)tax_8 && b == (int)tax_10){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

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

using namespace std;

int main(){
  int n,p;
  scanf("%d %d", &n,&p);
  int k0=0,k1=0;
  for(int i=0;i<n;i++){
    int a;
    scanf("%d", &a);
    if(a%2==0){
      k0++;
    }else{
      k1++;
    }
  }
  long long ans;
  if(k1==0){
    ans=(1LL<<n);
  }else{
    ans=(1LL<<(n-1));
  }
  if(p==1){
    ans=(1LL<<n)-ans;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

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

int main()
{
	int N, X;
	cin >> N >> X;
	vector<int> x(N);
	for (auto &e : x) {
		cin >> e;
	}

	int ans = abs(x[0] - X);
	for (int i = 1; i < N; ++i) {
		ans = gcd(ans, abs(x[i] - X));
	}
	cout << ans << endl;
}


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

#define pb push_back
const int maxn = 100000+5;
const int INF = 0x3f3f3f3f;

int N;
string str[maxn];
int mem[maxn];
typedef long long ll;

void Print()
{
	for(int i = 0; i < N; i++)
	{
		cout << str[i] << endl;
	}
}

ll solve()
{
	for(int i = 0; i < N; i++)
	{
		sort(str[i].begin(), str[i].end());
	}

	sort(str, str+N);
	//Print();

	ll ans = 0;
	ll point = 1;
	for(int i = 0; i < N-1; i++)
	{
		if(str[i] == str[i+1])
		{
			ans += point;
			point++;
		}
		else 
		{
			point = 1;
		}
	}	
	return ans;
}

int main()
{
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		cin >> str[i];
	}
	printf("%lld\n", solve());
}

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

def two_divisor(x):
  cnt = 0
  while x % 2 == 0:
    x //= 2
    cnt += 1
  return cnt

ans = 0
for i in range(N):
  if A[i] % 2 == 0:
    ans += two_divisor(A[i])
    
print(ans)

Measured memory_bytes: 9960
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    L = int(readline())

    ans = pow(L / 3, 3)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9316
S = int(input())
p = 10 ** 9
if S > p:
    r = S % p
    r = 0 if r == 0 else p - r 
    print(p, 1, r, (S + r) // p,  0, 0)
else:
    print(1, 0, 0, S, 0, 0)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

    ll tmp_length = 0, ans = 0;
    REP(i, s.size()) {
        // cout << "i=" << i << " ans=" << ans << " tmp_length=" << tmp_length << endl;
        if(s[i] == 'A') {
            tmp_length++;
        } else if (i >= 1 && i < s.size()-1 && s[i] == 'B' && s[i+1] == 'C') {
            ans += tmp_length;
            i++;
        } else {
            tmp_length = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main()  {
	var x, y int
	for {
		fmt.Scan(&x, &y)
		if x == 0 && y == 0 {
			break
		}
		num := []int{x, y}
		sort.Sort(sort.IntSlice(num))
		fmt.Println(num[0], num[1])
	}
}


Measured memory_bytes: 1340
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int N;
int A,B,C;
int l[10];
int ans=INT_MAX;

inline int abs(int x)
{
	return x<0?-x:x;
}

inline void dfs(int pos, vector<int> va, vector<int> vb, vector<int> vc)
{
	if (pos<=N)
	{
		dfs(pos+1,va,vb,vc);
		va.push_back(l[pos]);
		dfs(pos+1,va,vb,vc);
		va.pop_back();
		vb.push_back(l[pos]);
		dfs(pos+1,va,vb,vc);
		vb.pop_back();
		vc.push_back(l[pos]);
		dfs(pos+1,va,vb,vc);
		vc.pop_back();
	}
	else 
	{
		if (!va.empty()&&!vb.empty()&&!vc.empty())
		{
			int suma=0,sumb=0,sumc=0;
			for (int i=0; i<va.size(); i++) suma+=va[i];
			for (int i=0; i<vb.size(); i++) sumb+=vb[i];
			for (int i=0; i<vc.size(); i++) sumc+=vc[i];
			ans=min(ans,abs(suma-A)+(int)(va.size()-1)*10+abs(sumb-B)+(int)(vb.size()-1)*10+abs(sumc-C)+(int)(vc.size()-1)*10);
		}
	}
	return;
}

int main()
{
	cin >> N >> A >> B >> C;
	for (int i=1; i<=N; i++) cin >> l[i];
	dfs(1,vector<int>(),vector<int>(),vector<int>());
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
<?php
  
  list($n, $k) = explode(" ",trim(fgets(STDIN)));

  $p = explode(" ", trim(fgets(STDIN)));

  $sum = 0;
  for($i=0;$i<$k;$i++){
    $sum+=$p[$i];
  }

  $max = $sum;
  for($i=$k;$i<$n;$i++){

    $sum = $sum+$p[$i]-$p[$i-$k];
    if($max < $sum){
         $max=$sum;
      }    
//    echo $max.PHP_EOL;
  }

  echo ($max+$k)/2;

Measured memory_bytes: 18932
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;
typedef long long ll;

const int MAXN = 1e6 + 100;
const int inf = 0x3f3f3f3f;
ll n, k;
ll dp[MAXN];
ll w[MAXN];
ll v[MAXN];
ll ans;

int main(){
	scanf("%lld %lld", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%lld %lld", &w[i], &v[i]);
	}
	memset(dp, inf, sizeof dp);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1e5; j >= 0; j--)
			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
	}
	for(int i = 1; i <= 1e5; i++){
		if(dp[i] <= k)ans = max(ans, (ll)i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define int long long
using namespace std;
int digit(int x)
{
    int s=0;
    while(x)
    {
        s+=x%10;
        x/=10;
    }
    return s;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,ans=200;cin>>n;
    for(int i=1;i<=n-1;i++)
    {
        ans=min(ans,digit(i)+digit(n-i));
    }
    cout<<ans;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , m , x , dp[MAXN] , br[MAXN];

int main() {
    fast_io;

    cin >> n >> m;
    for(ll i = 0 ; i < m ; i++){
        cin >> x;
        br[x] = 1;
    }

    dp[0] = 1;
    for(ll i = 1 ; i <= n ; i++){
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        if(br[i])   dp[i] = 0;
    }
    cout << dp[n] << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

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

const int N = 100005;
const int INF = 1000000007;

int n,k;
int x[N];

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),k=read();
	rep(i,1,n) x[i]=read();
	if (x[n]<=0) {
		printf("%d\n",-x[n-k+1]);
	} else if (x[1]>=0) {
		printf("%d\n",x[k]);
	} else {
		int left,right;
		rep(i,1,n) if (x[i]==0) {left=i-1; right=i+1; k--; break;} else if (x[i]>0) {left=i-1;right=i; break;}
		if (k==0) {puts("0"); return 0;}
		int ans=INF;
		rep(i,1,left) {
			if (left-i+1>k) continue;
			int tmp1=left-i+1,tmp2=k-tmp1;
			if (n-right+1<tmp2) break;
			ans=min(ans,x[right+tmp2-1]-x[i]+min(-x[i],x[right+tmp2-1]));
		}
		printf("%d\n",ans);
	}

	return 0;
	
}


Measured memory_bytes: 640
N = int(input())
A = [int(input()) for i in range(N)]
 
 
cnt = 1
a = A[0]
while True:
	if a == 2:
		print(cnt)
		break
	cnt += 1

	a = A[a-1]

	if cnt > N:
		print(-1)
		break

	

Measured memory_bytes: 7084
#include<stdio.h>
int main(void){
    int a,b,c,d,i,L;
    scanf("%d%d%d%d%d",&L,&a,&b,&c,&d);
    for(;;){
        a=a-c;
        b=b-d;
        L--;
        if(a<=0&&b<=0){
            break;
        }
    }
    printf("%d\n",L);
return 0;
}

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

long long int check(vector<vector<long long int>> &dp,vector<vector<long long int>> &v,long long int n,long long int w){
  if(w==0 || n==0) return 0;
  if(dp[n][w] != -1) return dp[n][w];
  
  if(w < v[n-1][1]) dp[n][w] = check(dp,v,n-1,w);
  else dp[n][w] = max(check(dp,v,n-1,w-v[n-1][1]) + v[n-1][0] , check(dp,v,n-1,w));
  return dp[n][w];
}	
     
int main(){
  long long int n,w,vi,wi;
  cin >> n >> w;
  vector<vector<long long int>> v(n);
  for(long long int i=0;i<n;i++){
    cin >> wi >> vi;
    v[i].push_back(vi);
    v[i].push_back(wi);
  }
  
  vector<vector<long long int>> dp(n+1,vector<long long int>(w+1,-1));
  cout << check(dp,v,n,w) << endl;
  return 0; 
}


Measured memory_bytes: 80256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
double round(double r)
{
    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}

char str[6];

int main()
{
    cin>>str;
    int l,r;
    l=r=0;
    int ans=0;
    for(int i=0;i<3;i++)
    {
        if(str[i]=='R')
            r++;
        else
        {
            ans=max(r-l,ans);
            l=r=i;
        }
    }
    ans=max(r-l,ans);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+10;
int n, vis[N], c[N];
char s[N];
vector<int> g[N];
void add(int x, int v) {
	for (; x<=n; x+=x&-x) c[x]+=v;
}
int qry(int x) {
	int r = 0;
	for (; x; x^=x&-x) r+=c[x];
	return r;
}
int main() {
	while (~scanf("%s", s+1)) {
	n = strlen(s+1);
	int d = 0;
	REP(i,0,1) g[i].clear();
	REP(i,1,n) c[i]=0,vis[i]=0;
	REP(i,1,n) s[i]-='a',d^=1<<s[i],g[s[i]].pb(i);
	if (d&(d-1)) {cout<<-1<<endl;continue;}
	ll ans = 0;
	int now = n;
	REP(i,1,n) if (!vis[i]) {
		int nxt = g[s[i]].back();
		g[s[i]].pop_back();
		int x = nxt-qry(nxt);
		if (i==nxt) ans += max((n+1)/2-x,0);
		else ans += max(now---x,0), add(nxt+1,1);
		vis[nxt] = 1;
	}
	printf("%lld\n", ans);
	}
}









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

const int mod = 998244353;
const int MN = 4010;

int N;
string X, g, tmp;
string A[6];

string gcd(string &a, string &b) {
    if(a.size() < b.size()) return gcd(b, a);
    if(b.size() == 0) return a;

    int n = a.size();
    int m = b.size();
    for(int i = 0; i <= n - m; i++) {
        if(a[n - 1 - i] == '1') {
            for(int j = 0; j < m; j++) {
                int t = a[n - 1 - i - j] - '0';
                int d = b[m - 1 - j] - '0';
                a[n - 1 - i - j] = '0' + (t ^ d);
            }
        }
    }
    while(a.size() && a.back() == '0') a.pop_back();
    return gcd(b, a);
}

int chk[MN], po[MN], la;

int cc[MN];
int dp(int x) {
    if(x == (int)X.size() - (int)g.size() + 1) return la;
    int &ret = cc[x];
    if(ret != -1) return ret;

    ret = dp(x + 1);
    if(X[x] == '1') {
        ret += po[ (int)X.size() - (int)g.size() - x ];
        ret %= mod;
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(false);

    po[0] = 1;
    for(int i = 1; i < MN; i++) {
        po[i] = 1LL * po[i - 1] * 2 % mod;
    }

    cin >> N >> X;

    for(int i = 0; i < N; i++) {
        cin >> A[i];
        reverse(A[i].begin(), A[i].end());
    }

    g = A[0];
    for(int i = 1; i < N; i++) {
        g = gcd(g, A[i]);
    }

    reverse(g.begin(), g.end());

    int n = X.size();
    int m = g.size();
    tmp = X;
    for(int i = 0; i <= n - m; i++) {
        chk[i] = tmp[i] - '0';
        if(tmp[i] == '1') {
            for(int j = 0; j < m; j++) {
                int t = tmp[i + j] - '0';
                int d = g[j] - '0';
                tmp[i + j] = '0' + (t ^ d);
            }
        }
    }

    la = 1;
    for(int i = n - m + 1; i < n; i++) {
        if(tmp[i] == '1') {
            la = X[i] - '0';
            break;
        }
    }

    memset(cc, -1, sizeof(cc));
    cout << dp(0);
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>
#include <iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;


int main(void){
    ll N,L;
    cin>>N>>L;
    ll ans=(2*L+N-1)*N/2;
    if(L>=0) ans-=L;
    else if(L+N-1<0) ans-=L+N-1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// coded by- mrNOBODY_

#include <bits/stdc++.h>
#include<cctype>
#define ll long long 
#define ull unsigned long long
using namespace std;

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

	char x;
	cin>>x;
	if(tolower(x) == int(x))
	{
		cout<<"a";
	}
	else
	{
		cout<<"A";
	}
	

	return 0;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

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

    int res = 0;
    string s; cin >> s;
    forn(i,si(s)) {
        if (i % 2 == 0) {
            if (s[i] == 'p') res--;
        }
        else {
            if (s[i] == 'g') res++;
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		Map<String, Integer> map = new TreeMap<>();
		int max = 0;

		for (int i = 0; i < n; i++) {
			String s = scan.next();
			// すでに同じ文字があったら
			if(map.containsKey(s)) {
				// valに加算
				map.put(s, map.get(s) + 1);
			}else{
				map.put(s, 1);
			}
			max = Math.max(max, map.get(s));
		}

		for(String key: map.keySet()) {
			// maxと等しいkeyを出力
			if(map.get(key) == max) {
				System.out.println(key);
			}
		}
	}
}

Measured memory_bytes: 78456
package main

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

var r = bufio.NewReader(os.Stdin)

func main() {
    var x,h,m,s int
    fmt.Fscan(r,&x)
    h = x/3600
    m = (x-h*3600)/60
    s = x-h*3600-m*60
    fmt.Printf("%d:%d:%d\n",h,m,s)
}
    


Measured memory_bytes: 1148
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		long[][] dp=new long[n-1][21];
		dp[0][a[0]]=1;
		for(int j=1; j<n-1; j++){
			for(int i=0; i<21; i++){
				if(i+a[j]<21){
					dp[j][i+a[j]]+=dp[j-1][i];
				}
				if(i-a[j]>=0){
					dp[j][i-a[j]]+=dp[j-1][i];
				}
			}
		}
		println(dp[n-2][a[n-1]]+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

int main(void){
	int N;
	double T,A;
	std::cin>>N>>T>>A;
	double min=1000000;
	double min_num;

	for(int i=0;i<N;i++){
		double H;
		std::cin>>H;
		double temperture = T - (0.006 * H);
		double diff = std::abs(temperture - A);
//		std::cout<<"temperture = " <<temperture<<" diff = "<<diff<<std::endl;
		if(diff < min){
			min = diff;	
			min_num = i;
		}
	}

	min_num++;

	std::cout<<min_num<<std::endl;
	return 0;
}


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

typedef struct {
  char mark;
  int value;
} Card;

void BubbleSort(Card *,int);
void SelectionSort(Card *,int);
void Pri(Card *,int);
int judge(Card *,Card *,int);

int main(){
  Card C1[N], C2[N];
  int i, n;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&C1[i].mark,&C1[i].value);
  }
  for(i=0;i<n;i++){
    C2[i] = C1[i];
  }
  BubbleSort(C1,n);
  Pri(C1,n);
  printf("Stable\n");
  SelectionSort(C2,n);
  Pri(C2,n);
  if( judge(C1,C2,n)==0){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }
  return 0;
}
void BubbleSort(Card C[], int n)
{
  int i, j;
  Card cng;

  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(C[j].value<C[j-1].value ){
        cng=C[j];
        C[j]=C[j-1];
        C[j-1]=cng;
      }
    }
  }
}
void SelectionSort(Card C[], int n){
  int i,j,min;
  Card cng;

  for(i=0;i<=n-2;i++){
    min=i;
    for(j=i;j<=n-1;j++){
      if(C[j].value<C[min].value){
    min=j;
      }
    }
    cng=C[i];
    C[i]=C[min];
    C[min]=cng;
  }
}

void Pri(Card C[],int n)
{
  int i;

  for(i=0;i<n;i++){
    if(i>0){
      printf(" ");
    }
    printf("%c%d",C[i].mark,C[i].value);
  }
  printf("\n");
}

int judge(Card C1[],Card C2[],int n)
{
  int i;

  for(i=0;i<n;i++)
    if(C1[i].mark!=C2[i].mark){
      return 1;
    }
  return 0;
}



Measured memory_bytes: 2092
#include <stdio.h>
int main()
{
	int x,y,i;
	for(i=1;;i++)
	{
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)
		{	
			break;
		}
		if(x<=y)
		{
			printf("%d %d\n",x,y);
		}
		else
		{
			printf("%d %d\n",y,x);
		}
	}
		
return 0;}

Measured memory_bytes: 1764
#include <bits/stdc++.h>
using namespace std;
 
 
int main(void){
  int N;
  cin >> N;
  vector<int> X(N);
  long long xsum = 0, sum = 0;
  for(int i = 0; i < N; i++){
   cin >> X[i]; 
    sum += X[i];
  }
  double ave = round(double(sum) / N);
  //cout << ave << endl;
  for(int i = 0; i < N; i++){
    xsum += (X[i] - ave) * ( X[i] - ave);
  }
  cout << xsum;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,k,d;cin>>x>>k>>d;
  ll ans=x,num=abs(x)/d,sign=x/abs(x);
  if(num<=k) {
    ans-=sign*num*d;
    k-=num;
    if(k%2!=0) ans-=sign*d; 
  }
  else ans-=sign*k*d;
  print(abs(ans));
  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=6e5,mod=924844033;
int b[N],n,rev[N],w[N],limn,a[N],siz[N],fst[N],nxt[N],to[N],fac[N],ifac[N],mm;
void ade(int u,int v){to[++mm]=v,nxt[mm]=fst[u],fst[u]=mm;}
void dfs(int u,int fa)
{
    siz[u]=1;++a[n];
    for(int i=fst[u];i;i=nxt[i])
    {
        int v=to[i];if(v==fa)continue;
        dfs(v,u),siz[u]+=siz[v];
    }
    if(u!=1)--a[siz[u]];
    --a[n-siz[u]];
}
int qpower(int a,int b)
{
    int ans=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;
    return ans;
}
void prework(int n)
{
    limn=1;while(limn<=(n<<1))limn<<=1;
    for(int i=1;i<limn;i++)rev[i]=(rev[i>>1]>>1)|((i&1)?(limn>>1):0);
    for(int i=1;i<limn;i<<=1)
    {
        int omg=qpower(5,(mod-1)/(i<<1));
        w[i]=1;
        for(int j=1;j<i;j++)w[i+j]=1ll*w[i+j-1]*omg%mod;
    }
    fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
    ifac[n]=qpower(fac[n],mod-2);
    for(int i=n-1;i>=0;i--)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
void DFT(int a[])
{
    for(int i=0;i<limn;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
    for(int i=1;i<limn;i<<=1)
        for(int j=0;j<limn;j+=i<<1)
            for(int k=0;k<i;k++)
            {
                int x=1ll*w[i+k]*a[i+j+k]%mod;
                a[i+j+k]=(a[j+k]-x)%mod,a[j+k]=(a[j+k]+x)%mod;
            }
}
void IDFT(int a[])
{
    reverse(a+1,a+limn);DFT(a);int iv=mod-(mod-1)/limn;
    for(int i=0;i<limn;i++)a[i]=1ll*iv*a[i]%mod;
}
int main()
{
    scanf("%d",&n);
    for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),ade(u,v),ade(v,u);
    dfs(1,0);
    prework(n);
    for(int i=0;i<=n;i++)a[i]=1ll*a[i]*fac[i]%mod,b[i]=ifac[i];
    reverse(a,a+n+1);DFT(a),DFT(b);
    for(int i=0;i<limn;i++)a[i]=1ll*a[i]*b[i]%mod;
    IDFT(a);reverse(a,a+n+1);
    for(int i=1;i<=n;i++)printf("%d\n",(1ll*a[i]*ifac[i]%mod+mod)%mod);
}

Measured memory_bytes: 31408
#include"bits/stdc++.h"
using namespace std;

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

    if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }


    vector<int> num(26, 0);
    for (char c : S) {
        num[c - 'a']++;
    }

    if (S.size() < 26) {
        //末尾に出てこないのを付ければいい
        for (int i = 0; i < 26; i++) {
            if (num[i] == 0) {
                cout << S << (char)('a' + i) << endl;
                return 0;
            }
        }
    } else {
        vector<bool> app(26, false);
        char max = S[25];
        app[max - 'a'] = true;
        for (int i = 24; i >= 0; i--) {
            if (S[i] < max) {
                for (int k = 0; k < 26; k++) {
                    if (S[i] < 'a' + k && app[k]) {
                        S[i] = 'a' + k;
                        cout << S.substr(0, i + 1) << endl;
                        return 0;
                    }
                }
            } else {
                max = S[i];
                app[S[i] - 'a'] = true;
            }
        }

        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <bits/stdc++.h>
#include<vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <math.h>
#include <iomanip>
using namespace std;
#define PI 3.1415926535897932

int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double ax,ay,bx,by,aangle,bangle,arad,brad;
  aangle = (h*60.0+m)*0.5;
  bangle = m*6.0;
  arad = aangle*PI/180.0;
  brad = bangle*PI/180.0;
  if(arad>=0 && arad<=PI/2.0){
    ax = sin(arad)*a;
    ay = cos(arad)*a;
  }else if(arad>PI/2.0 && arad<=PI){
    ax = cos(arad-PI/2.0)*a;
    ay = -sin(arad-PI/2.0)*a;
  }else if(arad>PI && arad<=1.5*PI){
    ax = -sin(arad-PI)*a;
    ay = -cos(arad-PI)*a;
  }else{
    ax = -cos(arad-1.5*PI)*a;
    ay = sin(arad-1.5*PI)*a;
  }

  if(brad>=0 && brad<=PI/2.0){
    bx = sin(brad)*b;
    by = cos(brad)*b;
  }else if(brad>PI/2.0 && brad<=PI){
    bx = cos(brad-PI/2.0)*b;
    by = -sin(brad-PI/2.0)*b;
  }else if(brad>PI && brad<=1.5*PI){
    bx = -sin(brad-PI)*b;
    by = -cos(brad-PI)*b;
  }else{
    bx = -cos(brad-1.5*PI)*b;
    by = sin(brad-1.5*PI)*b;
  }

  cout << fixed << setprecision(15) << (double)(sqrt(pow((ax-bx),2.0)+pow((ay-by),2.0))) << endl;

}


Measured memory_bytes: 4076
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    int n,R=0,G=0,B=0;
    ll ans =0;
    char s[4005];
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='R') R++;
        else if(s[i]=='G') G++;
        else B++;
    }
    ans = (ll)R*G*B;
    for(int i=1;i<n;i++){
        for(int d=1;i+d+d<=n;d++){
            if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B')) --ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int dividedValue = N;
		int sum = 0;
		while (dividedValue > 0) {
			sum += dividedValue % 10;
			dividedValue /= 10;
		}
		
		if ((N % sum) == 0)  {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
}





Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int month, M, N, L;

int main() {
  while(cin >> L, L) {
    month = 0;
    
    rep(i, 12) {
      cin >> M >> N;
      L -= M - N;
      if(L <= 0 && month == 0) {
        month = i + 1;
      }
    }

    if(month == 0)
      cout << "NA" << endl;
    else
      cout << month << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){
    
    float T=0,X=0;

    cin >> T>>X;

    cout << setprecision(10)<<T/X<<endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Counter<T> extends TreeMap<T,Long>{
    public Counter(){
        super();
    }
    public Long count(Object elm){
        return getOrDefault(elm,0L);
    }
    public void add(T elm, long amount){
        if(!this.containsKey(elm)) put(elm, amount);
        else replace(elm, get(elm)+amount);
        if(this.count(elm)==0L) this.remove(elm);
    }
}
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] V = new long[N];
        for(int n=0; n<N; n++) V[n]=sc.nextInt();
        long ans = 0;
        for(int A=0; A<=Math.min(N,K); A++) for(int B=0; A+B<=Math.min(N,K); B++){
            Counter<Long> popedJewels = new Counter<>();
            for(int a=0; a<A; a++) popedJewels.add(V[a],1);
            for(int b=0; b<B; b++) popedJewels.add(V[N-B+b], 1);
            for(int p=0; p<K-A-B; p++){
                if(!popedJewels.isEmpty() && popedJewels.firstKey()<0 && popedJewels.count(popedJewels.firstKey())>0){
                    popedJewels.add(popedJewels.firstKey(),-1);
                }
            }
            long total=0;
            for(long j:popedJewels.keySet()) total += j*popedJewels.get(j);
            ans = Math.max(ans,total);
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 28748
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if b[i]-a[i]>0:
    cnt+=a[i]
    cnt+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
  else:
    cnt+=b[i]
print(cnt)
  


Measured memory_bytes: 18476
N,M,K = map(int,input().split())
a = list(map(int,input().split()))	
b = list(map(int,input().split()))

A = [0]
B = [0]
A.extend(a)
B.extend(b)
time = sum(A)
ai = len(A)-1
bi = 0
con = 0
flg = None
count = 0

    

while True:
    #print("---------")
    #print(str(ai)+":"+str(bi))
    if time > K:
        if flg is not None:
            con = max(con,flg-1)
            flg = None
        
        if ai == 0:
            break
        time -=A[ai]
        ai -= 1
    else:
        #print("b")
        flg = ai+bi
        time +=B[bi]
        bi += 1
        if bi == len(B):
            if time > K:
                if flg is not None:
                    con = max(con, flg-1)
                pass
            else:
                con = max(con,ai+bi-1)
            break
    #print(flg)
print(con)

Measured memory_bytes: 111104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <vector>
#define llint long long
#define mod 1000000007
#define inf 1000000000000

using namespace std;

llint n, k;
vector<llint> vec;
llint dp[105][100005];
llint dif[100005];

llint get(llint x)
{
	llint ub = n+1, lb = x, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(n/x > n/mid) ub = mid;
		else lb = mid;
	}
	return lb;
}

int main(void)
{
	cin >> n >> k;
	
	llint cur = 1;
	while(1){
		llint res = get(cur);
		vec.push_back(res);
		if(res >= n) break;
		cur = res+1;
	}
	int m = vec.size();
	vec.insert(vec.begin(), 0);
	
	//for(int i = 0; i <= m; i++) cout << vec[i] << " "; cout << endl;
	
	dp[0][1] = 1;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= m; j++) dif[j] = 0;
		for(int j = 1; j <= m; j++){
			llint p = upper_bound(vec.begin(), vec.end(), n/vec[j]) - vec.begin()-1;
			dif[1] += dp[i-1][j], dif[1] %= mod;
			dif[p+1] += mod - dp[i-1][j], dif[p+1] %= mod;
			dp[i][p+1] += (n/vec[j]-vec[p]) * dp[i-1][j] % mod, dp[i][p+1] %= mod;
		}
		llint sum = 0;
		for(int j = 1; j <= m; j++){
			sum += dif[j], sum %= mod;
			dp[i][j] += sum * (vec[j]-vec[j-1]) % mod, dp[i][j] %= mod;
		}
	}
	llint ans = 0;
	for(int j = 1; j <= m; j++) ans += dp[k][j], ans %= mod;
	cout << ans << endl;
	
	/*for(int i = 0; i <= k; i++){
		for(int j = 0; j <= m; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	return 0;
}

Measured memory_bytes: 79608
use proconio::*;

fn solve(n: u64) {
    let m = n - 1;
    if m >= 26 {
        solve(m / 26);
    }

    print!("{}", ((('a' as u64) + m % 26) as u8) as char);
}

fn main() {
    input! {
        n: u64
    }

    solve(n);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  cout << S.substr(0, S.size() - 8) << endl;
  return 0;
}

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

int main() {

  int N;
  cin >> N;

  vector<long long> A(N);
  for(int i = 0;i < N;i++) {
    cin >> A.at(i);
  }

  long long ans = 0;
  for(int i = 0;i < 60;i++) {
    long long z = 0,o = 0;
    for(int j = 0;j < N;j++) {
      long long a = A.at(j);
      if((a>>i)&1) o++;
      else z++;
    }
    long long num = z*o;
    for(int j = 0;j < i;j++) {
      num *= 2;
      num %= MOD;
    }
    ans += num;
    ans %= MOD;
  }

  cout << ans << endl;
}





Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
long long a, b, k;
void solve(){
    cin >> a >> b >> k;
    if(b - a + 1 < 2 * k){
        for(int i = a; i <= b; i++)
        cout << i << endl;
    }
    else {
        for(int i = a; i < a + k; i++)
        cout << i << endl;
        for(int j = b - k + 1; j <= b; j++)
        cout << j << endl;
    }
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

const static double PI = 4*atan(1.0);

struct Point{double x,y;};


void koch(int n, Point a, Point b){
  if(n==0)return;
  Point s,t,u;
  double th = PI*60.0/180.0;

  s.x = (2.0*a.x+1.0*b.x)/3.0;
  s.y = (2.0*a.y+1.0*b.y)/3.0;
  t.x = (1.0*a.x+2.0*b.x)/3.0;
  t.y = (1.0*a.y+2.0*b.y)/3.0;

  u.x = (t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y = (t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}


int main(){
  int n;
  Point a,b;

 scanf("%d",&n);

 a.x = 0;
 a.y = 0;
 b.x = 100;
 b.y = 0;

 printf("%.8f %.8f\n",a.x,a.y);
 koch(n,a,b);
 printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

Measured memory_bytes: 2692
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal A = new BigDecimal(sc.next());
		BigDecimal B = new BigDecimal(sc.next());
		BigDecimal N = new BigDecimal(sc.next());
		BigDecimal MAX = BigDecimal.ZERO;
		if (N.compareTo(B) != -1) {
			MAX = A.multiply(B.subtract(BigDecimal.ONE)).divide(B, 0, RoundingMode.DOWN);
		} else {
			MAX = A.multiply(N).divide(B, 0, RoundingMode.DOWN).subtract(A.multiply(N.divide(B, 0, RoundingMode.DOWN)));
		}
		System.out.println(MAX);
	}

}


Measured memory_bytes: 36124