akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#define  ms(a,b) memset(a,b,sizeof(a))

using namespace std;
typedef long long LL;
const LL INF=1e17L;
const int inf=0x3f3f3f3f;
const int maxn=1e5+5;
const int Mod=1e9+7;
LL n;
LL A,B,a[maxn];
bool judge(LL m)
{
    LL num=0;
    for(int i=1;i<=n;i++)
    {
        LL l=0,r=m,ans=-1;
        while(l<=r)
        {
            LL mid=(l+r)>>1;
            LL t=A*mid+(m-mid)*B;
            if(t>=a[i])
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        if(ans==-1) return false;
        num+=ans;
    }
    return num<=m;
}
int main()
{
    cin>>n>>A>>B;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    LL l=0,r=1e9,ans;
    while(l<=r)
    {
        LL mid=(l+r)>>1;
        if(judge(mid))
        {
            ans=mid;
            r=mid-1;
        }else l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
// arock - 2019-01-16

#include <iostream>
#include <vector>

template <class T> std::vector<T> read(int n) {
    std::vector<T> res(n);
    for (auto& r : res) {
        std::cin >> r;
    }

    return res;
}

int main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    
    int H, W; 
    std::cin >> H >> W;
    auto grid = read<std::string>(H);

    const int MOD = 1000000007;
    
    std::vector<std::vector<int>> dp(H, std::vector<int>(W));
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i && grid[i - 1][j] == '.') {
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            }
            if (j && grid[i][j - 1] == '.') {
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
            }
        }
    }

    std::cout << dp[H - 1][W - 1] << '\n';
}


Measured memory_bytes: 5248
import math
a, b, C = map(float, input().split())
rad_C = C*math.pi/180
c2 =a**2 + b**2 -2*a*b*math.cos(rad_C)
S = 0.5*a*b*math.sin(rad_C)
L = a + b + math.sqrt(c2)
h = 2*S/a
print(S)
print(L)
print(h)


Measured memory_bytes: 5688
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

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

    static class Partition {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long m = in.nextLong();
            long result = 0;
            List<Long> list = divisor(m);
            for (Long b : list) {
                long last = m - (b * (n - 1));
                if (b <= last) {
                    result = Math.max(result, b);
                }
            }
            out.println(result);
        }

        static List<Long> divisor(long x) {
            List<Long> result = new ArrayList<>();
            for (long i = 1; i * i <= x; i++) {
                if (x % i == 0) {
                    result.add(i);

                    long j = x / i;
                    if (j != i) {
                        result.add(j);
                    }
                }
            }
            Collections.sort(result);
            return result;
        }

    }
}



Measured memory_bytes: 35980
main :: IO ()
main = do
    s <- getLine
    putStrLn $ if check_odd s then "Yes" else "No"

check_odd :: String -> Bool
check_odd s
    | s == "" = True
    | head s == 'L' = False
    | otherwise = check_even (tail s)

check_even :: String -> Bool
check_even s
    | s == "" = True
    | head s == 'R' = False
    | otherwise = check_odd (tail s)

Measured memory_bytes: 380
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	int hight[n];
	int count=0;
	for(int i=0; i<n; i++){
		scanf("%d", &hight[i]);
		if(hight[i]>=k) count++;
	}
	
	printf("%d", count);
	
	
	return 0;
}

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


def main():
    n = int(input())
    s = input()
    val = 0
    ans = 0

    for si in s:
        if si == 'I':
            val += 1
        elif si == 'D':
            val -= 1

        ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  string ans = "APPROVED";

  for ( int i = 0; i < n; i++ ) {
    int a;
    cin >> a;
    if ( a%2 == 0 && a%3 != 0 && a%5 != 0 ) {
      ans = "DENIED";
    }
  }

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


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

int main() {
int l,r,t;
    cin>>l>>r>>t;
    int ans=(r-l)/t;
    if(r%t==0||l%t==0){
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define INT long long
#define MOD 1000000007
using namespace std;
INT n, d, x[20][20], ans;
map<INT, INT> s;
int main(void)
{
    ios::sync_with_stdio(false);
    cin>>n>>d;
    for(int i = 0 ; i*i <= 1000000000 ; i++)
        s[i*i] = 1;
    for(int i = 0 ; i < n ; i++ )
        for(int j = 0 ; j < d ; j++ )
            cin>>x[i][j];
    for(int i = 0 ; i < n-1 ; i++ )
        for(int j = i+1 ; j < n ; j++ )
        {
            int dt = 0;
            for(int k = 0 ; k < d ; k++ )
            {
                dt += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            if( s[dt] == 1 ) ans++;
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



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

    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        string s = to_string(i);
        int si = s.size();
        int check = 0;
        rep(j,si){
            check += (ll) s[j] - 48;
            //cout << (ll) s[j] << endl;
        }
        if(a <= check && check <= b) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3752
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int main(){
	std::ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)
		cout<<"Possible"<<endl;
	else
		cout<<"Impossible"<<endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<int> s[26];
int n,m;
string str;
int main(){
    scanf("%d",&n);
    cin>>str;
    for(int i=0;i<n;i++)
        s[str[i]-'a'].insert(i);
    scanf("%d",&m);
    int k;
    for(int i=0;i<m;i++){
        scanf("%d",&k);
        if(k==1){
            int p;char q;
            scanf("%d %c",&p,&q);
            s[str[p-1]-'a'].erase(p-1);
            s[q-'a'].insert(p-1);
            str[p-1]=q;
        }
        else{
            int p,q;
            scanf("%d %d",&p,&q);
            int sum=0;
            p--;q--;
            for(int i=0;i<26;i++)
                if(*s[i].lower_bound(p)<=q&&s[i].lower_bound(p)!=s[i].end())
                    sum++;
            printf("%d\n",sum);
        }
        getchar();

    }


}


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

int main(){
 string s,p,op;
 int a,b,q;

 cin >> s >> q;

 for(int i=0;i<q;i++){
  cin >> op >> a >> b;
  if(op=="print")cout << s.substr(a,b-a+1) << endl;
  else if(op=="reverse")reverse(s.begin()+a,s.begin()+b+1);
  else{
   cin >> p ;
   s=s.substr(0,a)+p+s.substr(b+1,s.length()-b-1);
  }
 }

 return 0;
}

Measured memory_bytes: 3160
#include <iostream>                                                                                    
#include <iomanip>
#include <cmath>

using namespace std;

struct Loc{
  int x;
  int y;
};

int get_int_perm(int a) {
  int res = 1;
  for (int i = 2; i <= a; ++i) {
    res *= i;
  }
  return res;
}


double dist(Loc l1, Loc l2) {
  double x_d = (l1.x - l2.x);
  x_d *= x_d;

  double y_d = (l1.y - l2.y);
  y_d *= y_d;

  return sqrt(x_d + y_d);
}

int main () {
  int N;
  cin >> N;
  Loc locs[N];
  for (int i = 0; i < N; ++i) {
    cin >> locs[i].x;
    cin >> locs[i].y;
  }
  //double dist[N][N];
  double sum = 0;
  int n_minus_one_perm = get_int_perm(N-1);
  for (int i = 0; i < N; ++i) {
    for (int j = i+1; j < N; ++j) {
      //dist[i][j] = 
      sum += dist(locs[i], locs[j]) * n_minus_one_perm;
    }   
  }
  cout << setprecision(16);
  cout << 2*sum/get_int_perm(N) << endl;

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let (n, l): (usize, usize) = util::get2();
    let a: Vec<usize> = util::gets();

    if let Some((i, _)) = a.windows(2).enumerate().find(|&(_, v)| v[0] + v[1] >= l) {
        println!("Possible");
        for k in 1..i + 1 {
            println!("{}", k);
        }
        for k in (i + 2..n).rev() {
            println!("{}", k);
        }
        println!("{}", i + 1);
    } else {
        println!("Impossible");
    }
}


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll dist(ll d1, ll d2) {
    ll d = abs(d1-d2);
    return min(d, 24-d);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> D(n); cin >> D;
    sort(all(D));
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(25, vector<ll>(25, -linf)));
    dp[0][0][0] = linf;
    rep(i, n) rep(j, 25) rep(k, 25) {
        if (dp[i][j][k] < 0) continue;
        {
            ll nj = D[i];
            chmax(dp[i+1][nj][k], min({dp[i][j][k], dist(j, nj), dist(nj, k)}));
        }
        {
            ll nk = 24-D[i];
            chmax(dp[i+1][j][nk], min({dp[i][j][k], dist(k, nk), dist(j, nk)}));
        }
    }
    ll ans = -linf;
    rep(i, 25) rep(j, 25) {
        chmax(ans, dp[n][i][j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N = int(input())
A = [int(i) - 1 for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0
prev = -10
for a in A:
    if a == prev + 1:
        ans += C[prev]
    ans += B[a]
    prev = a

print(ans)

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


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

    vector<string> s(N);
    for(int i = 0; i < N; ++i){
        cin >> s[i];
        sort(begin(s[i]), end(s[i]));
    }

    sort(begin(s), end(s));

    // for(int i = 0; i < N; ++i){
    //     cout << s[i] << endl;
    // }

    long long int ans = 0;
    string tmp = s[0];
    long long int cnt = 1;
    for(long long int i = 1; i < N; ++i){
        if(tmp == s[i]){
            ++cnt;
        }else{
            if(cnt != 1){
                ans += cnt*(cnt-1) / 2;
            }
            cnt = 1;
            tmp = s[i];
        }
    }

    if(cnt != 1){
        ans += cnt*(cnt-1) / 2;
    }
    
    cout << ans << endl;
}

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

int n, A[50];

int solve(int i, int m) {
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i+1, m) || solve(i+1, m-A[i]);
    return res;
}


int main() {
    int M, q;

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 3140
import java.util.Scanner;

public class Main
{
    public static void main(String[] args) 
    {
       Scanner sc=new Scanner(System.in);
       int k=sc.nextInt(), n=sc.nextInt(),ans=-1;
       int a[]=new int[n];
       a[0]=sc.nextInt();
       for(int i=1; i<n; i++)
       {
            a[i]=sc.nextInt();
            ans=Math.max(ans, Math.abs(a[i]-a[i-1]));            
       }
       ans=Math.max(ans,k- Math.abs(a[0]-a[n-1]));
       System.out.println(k-ans);
              
    }

    
}

Measured memory_bytes: 60380
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()] 


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = S()
    if '7' in n:
        print('Yes')
    else:
        print('No')
    return


if __name__ == "__main__":
    solve()

Measured memory_bytes: 65620
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
#include<algorithm>
using namespace std;

int main(void)
{
	int N, M;
	cin >> N >> M;

	typedef pair<int, int> State;
	vector<State> ab(M);
	for(int i=0; i<M; i++){
		int a, b;
		cin >> a >> b;

		ab[i].first = a;
		ab[i].second = b;
	}

	auto f = [](State& left, State& right){
		if(left.second == right.second)
			if(left.first <= right.first)
				return true;
			else
				return false;
		else if(left.second < right.second)
			return true;
		else
			return false;
	};

	sort(ab.begin(), ab.end(), f);

	int ret = 0;
	int pos = -1;
	for(int i=0; i<M; i++){
		//cout << pos << " : "<< ab[i].first << " " << ab[i].second << endl;
		if(pos >= ab[i].first && pos <= ab[i].second)
			continue;

		ret++;
		pos = ab[i].second - 1;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int _a, _b;
    for (int i = 0; i < 1010; i++){
        _a = i * 8 / 100;
        _b = i * 10 / 100;
        if (_a == a && _b == b) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

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

#define vi vector<int>
#define pb push_back

int main() {
    int n, tmp, i0 = 0, i1 = 0, i2 = 0;
    cin >> n;
    rep(i, n) {
        cin >> tmp;
        int m2 = 0;
        for(m2; tmp % 2 == 0; m2++)
            tmp /= 2;
        if(m2 == 0)
            i0++;
        else if(m2 == 1)
            i1++;
        else
            i2++;
    }

    if (i1 !=0)i0++;
    string ans = "Yes";
    if (i0 - 1 <= i2)
        ;
    else
        ans = "No";

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

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

using namespace std;

typedef long long ll;

int main() {
  string x; cin >> x;
  int k = 0; int n = x.length();
  for(int i = 0; i < n; i++) {
    if(x[i] == x[i + 1] and i + 1 == n - 1) {
      k++;
      break;
    }
    else if(x[i] == x[i + 1]) {
      k += 2;
      i += 2;
    }
    else {
      k++;
    }
  }
  cout << k << '\n';
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi dp(N+1,INF);
  dp[0] = 0;
  srep(i,1,N+1) {
    // 1
    if(i-1>=0) {
      dp[i] = min(dp[i],dp[i-1]+1);
    }
    // 6^l
    srep(l,1,7) {
      if(i-pow(6,l)>=0) {
        dp[i] = min(dp[i],dp[i-pow(6,l)]+1);
      }
    }
    // 9^l
    srep(l,1,6) {
      if(i-pow(9,l)>=0) {
        dp[i] = min(dp[i],dp[i-pow(9,l)]+1);
      } 
    }
  }
  cout << dp[N] <<endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <map>

using namespace std;

int v[100010];
map<int,int> q;

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n;
    long long sol=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        q[v[i]]++;
    }
    for(int i=1;i<=n;i++)
        if(q[v[i]]!=0)
        {
            if(q[v[i]]>=v[i]) sol=sol+q[v[i]]-v[i];
            else sol=sol+q[v[i]];
            q[v[i]]=0;
        }
    printf("%lld",sol);
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[5],k,maxn=10,ans=0;
	for(int i=0;i<5;i++){
		cin>>a[i];
		if(a[i]%10<maxn && a[i]%10!=0){
			maxn=a[i]%10;
			k=i;
		} 
	}
	//cout<<k<<endl;
	for(int i=0;i<5;i++){
		if(i!=k){
			ans+=a[i]-a[i]%10;
			if(a[i]%10!=0) ans+=10;
		}
		else ans+=a[i];
	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N; 
  cin>>N;
  vector<vector<int>> G(N+1);
  vector<pair<int,int>> g(N-1);
  for (int i(0);i<N-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].pb(b);
    G[b].pb(a);
    g[i] = {a,b};
  }
  queue<pair<int,int>> q;//number, color
  q.push({1,0});
  vector<int> pathed(N+1,0);
  map<int,map<int,int>> color;
  pathed[1] = 1;
  int K(0);
  while(!q.empty()){
    pair<int,int> now = q.front();q.pop();  
    //cout << now.first << " ";
    int color_num = 1;
    for (int i(0);i<G[now.first].size();i++){
      int next = G[now.first][i];
      if (pathed[next] == 0){
        if (color_num == now.second) color_num++;
        q.push({next,color_num});
        pathed[next] = 1;
    //    cout << color_num << endl;
        color[min(now.first,next)][max(now.first,next)] = color_num;
        K = max(K,color_num);
        color_num++;
      }
    }
  }
  cout << K << endl;
  for (int i(0);i<N-1;i++){
    int a = g[i].first;
    int b = g[i].second;
    cout << color[a][b] << endl;
  }
  return 0;
}



Measured memory_bytes: 16640
<?php 
fscanf(STDIN, "%d %d", $k,$x);
$arr = array();
for ($i=0; $i < $k; $i++) {
  $arr[] = $x + $i;
}
for ($i=1; $i < $k; $i++) {
  $arr[] = $x - $i;
}
sort($arr);
$str = "";
foreach ($arr as $value) {
  $str .= "{$value} ";
}
echo trim($str);
?>

Measured memory_bytes: 3700
r,c = gets.split.map(&:to_i)

h = []
r.times do
  h << gets.split.map(&:to_i)
end

h.each{|x| x << x.inject(&:+)}
h = h.transpose.each{|x| x << x.inject(&:+)}.transpose

puts h.map{|x| x.join ' '}.join "\n"

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = (1LL<<40);
using namespace std;
ll exp(ll a , ll b){
	if(b == 0)	return 1;
	int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
	return x;
}

int main(int argc,char ** argv){
	dhoom;
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a , a + 3);
	int x = (2*a[2] - a[0] - a[1]); 
	if(x%2 == 0)
		cout << x/2 << endl;
	else 
		cout << x/2 + 2 <<endl;
	return 0;
}


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

int main(){
	int a,b;
	while(cin>>a>>b,a,b){
		double ans=1e8;
		
		for(int i=0;i<a;i++){
			double c=abs(sqrt((i*i)+((a-i)*(a-i)))-b);
			if(ans>c)ans=c;
			}
			
			printf("%9lf\n",ans);
		}
		return 0;
	}

Measured memory_bytes: 3132
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
	ll n, m, h, w;
	ll x;
	//cin >> x;
	string s;
	cin >> a;
	cin >> b;
	e = 10000;
	for (int i = 0; i < a; i++)
	{
		cin >> c;
		cin >> d;
		if (d<=b)
		{
			e = min(c, e);
		}
	}
	if (e!=10000)
	{
		cout << e << endl;

	}
	else
	{
		cout << "TLE" << endl;

	}
	//cout << sum << endl;
	//cout <<  endl;
	return 0;
}

//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}




//
//ll insuusyurui[1000] = {};
//ll insuukazu[1000] = {};
//ll memo[4000] = {};
//ll memo2[4000] = {};
//cin >> n;
//cin >> m;
//a = 2;
//// √n ≧ a ( n ≧ a * a ) の間ループ処理
//while (n >= a * a) {
//	// a で割り切れたら、a は素因数
//	// そして、割られる数を a で割る
//	// a で割り切れなかったら、 a を 1 増加させる
//	if (n % a == 0) {
//		printf("%lld * ", a);
//		insuukazu[c]++;
//		n /= a;
//	}
//	else {
//		a++;
//		//if (insuukazu[c] != 0)
//		{
//			c++;
//			//cout << c << endl;
//
//		}
//	}
//}
//printf("%lld\n", n);
//for (int i = 0; i < c; i++)
//{
//	//cout << insuukazu[i] << endl;
//}
//
//cout << "Yes" << endl;

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


enum { NUM_FACTORIAL = 1012345 };
ll f[NUM_FACTORIAL];
ll f_inv[NUM_FACTORIAL];
ll MOD = 998244353;

// MODが素数以外でも使えるバージョン。階乗の逆元を求める。
ll extgcd(ll a, ll b, ll& x, ll& y)
{
	ll d = a;
	if (b != 0)
	{
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else
	{
		x = 1;
		y = 0;
	}
	return d;
}

// 逆元を求める
ll mod_inverse(ll a, ll m)
{
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x%m) % m;
}

void mod_factorial_init()
{
	f[0] = 1;
	for (int i = 1; i < NUM_FACTORIAL; ++i)
	{
		f[i] = f[i - 1] * i;
		f[i] %= MOD;
	}

	for (int i = 0; i < NUM_FACTORIAL; ++i)
	{
		f_inv[i] = mod_inverse(f[i], MOD);
	}
}

// 組み合わせを求める。事前計算O(n)で、0～nまでと範囲も広いので、MODつきならパスカルの三角形よりも良い。最有力。
ll mod_comb(ll n, ll k) {
	if (k > n)
	{
		return 0;
	}

	return ((f[n] * f_inv[k]) % MOD * f_inv[n - k]) % MOD;
}


int main()
{
	mod_factorial_init();

	ll N, A, B, K;
	cin >> N >> A >> B >> K;

	ll ans = 0;

	for (ll r = 0; r <= N; r++)
	{
		if ((K - r * A) % B == 0)
		{
			ll b = (K - r * A) / B;
			if (b >= 0)
			{
				ll tmp = (mod_comb(N, r) * mod_comb(N, b)) % MOD;
				ans += tmp;
				ans %= MOD;
			}
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 16128
N  = int(input())
H = list(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])

for i in range(2, N):
    dp[i] = min(dp[i-2]+abs(H[i]-H[i-2]), dp[i-1]+abs(H[i]-H[i-1]))
print(dp[-1])

Measured memory_bytes: 20500
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int h,w,ch,cw,dh,dw;
string s[1000];
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};

vector<int> dijkstra(vector<vector<pair<int,int>>>& graph,int s){
    int n=(int)graph.size();
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    vector<int> dist(n,inf);
    dist[s]=0;
    pq.push({0,s});
    while(pq.size()){
        auto p=pq.top();
        pq.pop();
        int v=p.second;
        if(dist[v]<p.first)continue;
        for(auto edge:graph[v]){
            int u=edge.first;
            int w=edge.second;
            if(dist[v]+w<dist[u]){
                dist[u]=dist[v]+w;
                pq.push({dist[u],u});
            }
        }
    }
    return dist;
}

int main(){
    cin>>h>>w>>ch>>cw>>dh>>dw;
    --ch;--cw;--dh;--dw;
    rep(i,h)cin>>s[i];
    vector<vector<pair<int,int>>> g(h*w);
    rep(x,h){
        rep(y,w){
            if(s[x][y]=='#')continue;
            int f=x*w+y;
            for(int i=0;i<4;++i){
                int nx=x+dx[i];
                int ny=y+dy[i];
                int t=nx*w+ny;
                if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#')continue;
                g[f].push_back({t,0});
                g[t].push_back({f,0});
            }
            for(int i=-2;i<=2;++i){
                int nx=x+i;
                for(int j=-2;j<=2;++j){
                    int ny=y+j;
                    int t=nx*w+ny;
                    if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#')continue;
                    g[f].push_back({t,1});
                    g[t].push_back({f,1});
                }
            }
        }
    }
    vector<int> d=dijkstra(g,ch*w+cw);
    rep(i,h){
        rep(j,w){
            if(d[i*w+j]==inf)d[i*w+j]=-1;
        }
    }
    cout<<d[dh*w+dw]<<endl;
}


Measured memory_bytes: 202892
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define ll long long int

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a;
    a.push_back(0);
    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        a.push_back(x);
    }

    map<int, int> m;
    int buf = 1;
    int c = 0;
    while(m.find(buf) == m.end()) {
        m[buf] = c;
        buf = a[buf];
        if (++c == k) {
            cout << buf;
            return 0;
        } 
    }

    int rep = 0;
    m.clear();
    while(m.find(buf) == m.end()) {
        m[buf] = c;
        buf = a[buf];
        ++rep;
    }

    int ret = 1;
    for (int i = 0; i < c + (k - c) % rep; ++ i) {
        ret = a[ret];
    }
    cout << ret;

    return 0;
}

Measured memory_bytes: 12392
import java.util.Deque
import java.util.ArrayDeque
import java.util.ArrayList

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    val G = Array(N){ArrayList<Pair<Int, Int>>()}

    for (i in 0 until M) {
        val L = sc.nextInt() - 1
        val R = sc.nextInt() - 1
        val D = sc.nextInt()
        G[L].add(Pair(R, D))
        G[R].add(Pair(L, -D))
    }

    val dist = IntArray(N)
    val checked = BooleanArray(N)
    val q : Deque<Int> = ArrayDeque<Int>()

    for (i in 0 until N) {
        if (checked[i]) {
            continue
        }
        checked[i] = true
        dist[i] = 0
        q.add(i)

        while (!q.isEmpty()) {
            val pos = q.poll()
            for ((node, w) in G[pos]) {
                if (!checked[node]) {
                    checked[node] = true
                    dist[node] = dist[pos] + w
                    q.add(node)
                } else if (dist[node] != dist[pos] + w) {
                    println("No")
                    return
                }
            }
        }
    }
    println("Yes")
}


Measured memory_bytes: 145592
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			int cup[] = {1,0,0};
			String ID = "ABC";
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf,",");
				int a = ID.indexOf(st.nextToken().charAt(0));
				int b = ID.indexOf(st.nextToken().charAt(0));

				cup[a] = cup[a]^cup[b];
				cup[b] = cup[a]^cup[b];
				cup[a] = cup[a]^cup[b];
			}
			for (int i=0;i<3;i++) {
				if (cup[i]==1) System.out.println(ID.charAt(i));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17000
#include <iostream>

int main() {
  int n, m;
  std::cin >> n >> m;
  int a[m][n], b[m], c[n] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      std::cin >> a[j][i];
    }
  }
  for (int i = 0; i < m; i++) {
    std::cin >> b[i];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      c[j] += a[i][j] * b[i];
    }
  }
  for (int i = 0; i < n; i++) {
    std::cout << c[i] << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>

int main(void){

	int a,b,x,y;
	
	scanf("%d",&a);
	scanf("%d",&b);
	
	if(a<b){
		x=a;
		a=b;
		b=x;
	}
	
	y=a%b;
	while(y!=0){
		a=b;
		b=y;
		y=a%b;
	}
	
	printf("%d\n",b);
	
	return 0;
}


Measured memory_bytes: 2100
W,H,N=map(int,input().split())
x1=0
x2=W
y1=0
y2=H
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x,x1)
    if a==2:
        x2=min(x,x2)
    if a==3:
        y1=max(y,y1)
    if a==4:
        y2=min(y,y2)
if x1<x2 and y1<y2:
    print((x2-x1)*(y2-y1))
else:
    print(0)


Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int a, b;
	cin >> a >> b;
	cout << max({ 2 * a - 1, 2 * b - 1, a + b }) << endl;;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  string s[3];
  rep(j,3) cin>>s[j];
  int na=s[0].size(),nb=s[1].size(),nc=s[2].size();
  int i[3];
  i[0]=0;
  i[1]=-1;
  i[2]=-1;
  int f=0;
  int c;
  while(i[0]<na&&i[1]<nb&&i[2]<nc){
    c=s[f][i[f]]-'a';
    i[c]++;
    f=c;
    // cout<<char('a'+c)<<endl;
  }
  char ans='A'+c;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

matrixA = []
vectorB = []
c = [[0 for r in range(1)]for s in range(n)]
sums = 0


for a in range(n):
    matrixA.append(list(map(int, input().split())))

for b in range(m):
    vectorB.append(int(input()))


for index_row in range(len(matrixA)):
    for index_column in range(len(matrixA[index_row])):

        col_m1 = matrixA[index_row][index_column]
        col_m2 = vectorB[index_column]
        sums = sums + (col_m1*col_m2)
  
    c[index_row] = sums
    sums = 0

for i in c:
    print(i)


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

using namespace std;

typedef long long int ll;

#define fin(ans) cout << (ans) << endl;

//n ~ mの和
ll sigma(ll n, ll m)
{
    return ((n + m) * (m - n + 1) * 0.5);
}

void Main()
{
    ll x;
    cin >> x;
    ll ans;
    for (ll i = 1; i <= x; i++)
    {
        if (sigma(1, i) >= x)
        {
            ans = i;
            break;
        }
    }
    fin(ans);
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }
    vector<vector<double>>dp(n+1,vector<double>(n+1,0));
    dp[0][0]=1;
    
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
                dp[i][j]=(1-a[i-1])*dp[i-1][j];
            else
                dp[i][j]=a[i-1]*dp[i-1][j-1]+(1-a[i-1])*dp[i-1][j];
        }
    }
    double ans=0;
    for(int i=(n/2 +1);i<=n;i++)
    {
        ans+=dp[n][i];
    }
    //cout<<ans<<endl;
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 73808
N = int(input())
W = list(map(int, input().split()))

l = W[0]
r = sum(W[1:])
diff = abs(l - r)
for i in range(1, N):
  l += W[i]
  r -= W[i]
  new_diff = abs(l - r)
  if new_diff < diff:
    diff = new_diff
print(diff)

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

int main()
{
    string s;

    cin >> s;

    if(s.at(s.size()-1) == 's')
    {
        cout << s << "es" <<endl;
    }else{
        cout << s << "s" <<endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;
int main(){
  long double pi =3.14159265358979323846;
  long long int A,B,H,M;
  long double x;
  cin>>A>>B>>H>>M;
  
  x=A*A+B*B-2.0*A*B*cos(abs(H*pi/6.0+pi*M/360.0-M*pi/30.0));
  cout<<fixed<<setprecision(12)<<sqrt(x)<<endl;
}






Measured memory_bytes: 4104
N, L = map(int, input().split())
A = []

for i in range(1,N+1):
  A.append(L+i-1)

if L < 0 and 0 not in A:
  A.remove(A[-1])
  print(sum(A))
elif 0 in A:
  print(sum(A))
elif L >= 0:
  A.remove(A[0])
  print(sum(A))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

// gcdも呼ぶ！！！
// lcmも呼ぶ！！！
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
// gcdも呼ぶ！！！
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}
int nlcm(vector<int> numbers) {
    int l;
    l = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        l = lcm(l, numbers[i]);
    }
    return l;
}

int main() {

    ll n,m;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    fin(nlcm(v));
}




Measured memory_bytes: 3168
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      q: usize,
      stxs: [(i64,i64,i64);n],
      ds: [i64; q]
    }
    let mut ts = vec![];
    for &(s, t, x) in stxs.iter() {
        let l = s-x;
        let r = t-x;
        ts.push((l, r, x));
    }
    ts.sort_by_key(|v| v.0);

    let mut cur = 0;
    let mut q = std::collections::BinaryHeap::new();
    for d in ds {
        while cur < n && ts[cur].0 <= d {
            let t = ts[cur];
            cur += 1;
            q.push((-1 * t.2, t.1));
        }

        while let Some(t) = q.pop() {
            if d < t.1 {
                q.push(t);
                break;
            }
        }

        match q.peek() {
            Some(t) => println!("{}", -1 * t.0),
            None => println!("{}", -1)
        }
    }
}


Measured memory_bytes: 23272
#include<cstdio>
int t,a[10];
bool f;
int main(){
	scanf("%d",&t);
	if((t/1000==t%1000/100 && t%1000/100==t%100/10) || (t%1000/100==t%100/10 && t%100/10==t%10)) f=1;
	printf("%s",f?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int x,y,i=1,j=1;
	
	while(j && i<=3000){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0) { j=0;
		}else if(x<=y){	printf("%d %d\n",x,y);
				i++;
				j=1;
				continue;
		}else
		{
			printf("%d %d\n",y,x);
				i++;
				j=1;
				continue;
		}
	}
}


Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string, string> s_s;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    map<s_s ,ll> mp;
    string t;
    for(int i = 2 * n - 1; i >= n; i--){
        t.push_back(s[i]);
    }
    //cout << s << " " << t << endl;
    for(int i = 0; i < n; i++){
        s.pop_back();
    }
    for(int S = 0; S < 1 << n; S++){
        string red, blue;
        for(int i = 0; i < n; i++){
            if(S>>i & 1){
                red.push_back(t[i]);
            } else {
                blue.push_back(t[i]);
            }
        }
        mp[{red, blue}]++;
    }
    for(int S = 0; S < 1 << n; S++){
        string red, blue;
        for(int i = 0; i < n; i++){
            if(S>>i & 1){
                red.push_back(s[i]);
            } else {
                blue.push_back(s[i]);
            }
        }
        ans += mp[{blue, red}];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 91904
import java.util.*;class Main{public static void main(String[]a){int x,y,z,w;x=y=z=0;for(Scanner s=new Scanner(System.in).useDelimiter("[\\s,]");s.hasNext();++z,y+=w)x+=s.nextInt()*(w=s.nextInt());System.out.println(x+"\n"+Math.round(y/(float)z));}}

Measured memory_bytes: 12000