akhauriyash/Code-Regression huggingface dataset:
while True:
    m, f, r = map(int,input().split())
    if m + f < 0:
        break
    if m < 0 or f < 0:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")

Measured memory_bytes: 7588
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let n: usize = read!();
    for i in 0.. {
        if n<=i*111 {println!("{}",i*111); exit(0);}
    }
}

Measured memory_bytes: 2080
#include<iostream>
#include<vector>
#include<set>
#include<map>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int *a = new int[n];
    int *b = new int[n];
    map<int, int> c;
    int max = 0;
    vector<set<int> > v;

    for (int i = 0; i <= n; i++) {
        v.push_back(set<int>());
    }

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

    for (int i = 1; i < n; i++) {
        v[a[i]].insert(i);
        v[b[i]].insert(i);
    }

    for (int i = 1; i <= n; i++) {
        if (v[i].size() > max) {
            max = v[i].size();
        }
    }

    for (int i = 1; i <= n; i++) {
        set<int> already;
        for (auto j = v[i].begin(); j != v[i].end(); ++j) {
            if (c.find(*j) != c.end()) {
                already.insert(c[*j]);
            }
        }
        int cn = 1;
        for (auto j = v[i].begin(); j != v[i].end(); ++j) {
            if (c.find(*j) == c.end()) {
                while (1) {
                    if (already.find(cn) == already.end()) {
                        c[*j] = cn++;
                        break;
                    } else {
                        cn++;
                    }
                }
            }
        }
    }

    cout << max << endl;
    for (int i = 1; i < n; i++) {
        cout << c[i] << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

int diameter(const Graph &G) {
    int n = (int)G.size();
    vector<int> dis(n, -1);
    dis.at(0) = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int cur = que.front(); que.pop();
        for (int nx : G.at(cur)) {
            if (dis.at(nx) == -1) {
                dis.at(nx) = dis.at(cur) + 1;
                que.push(nx);
            }
        }
    }
    int maxi = -1, ind = -1;
    for (int i=0; i<n; ++i) if (chmax(maxi, dis.at(i))) ind = i;

    dis.assign(n, -1);
    dis.at(ind) = 0;
    que.push(ind);
    while (!que.empty()) {
        int cur = que.front(); que.pop();
        for (int nx : G.at(cur)) {
            if (dis.at(nx) == -1) {
                dis.at(nx) = dis.at(cur) + 1;
                que.push(nx);
            }
        }
    }
    int res = -1;
    for (int i=0; i<n; ++i) chmax(res, dis.at(i));
    return res;
}

void solve() {
    int n;
    cin >> n;
    Graph G(n);
    for (int i=0; i<n-1; ++i) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    int dia = diameter(G);
    if (dia%3 == 1) cout << "Second" << '\n';
    else cout << "First" << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 13556
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        self.chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            k = map(int, raw_input().split())
            s = raw_input()
            ans = ''
            for i in range(len(s)):
                ans += self.chars[self.chars.index(s[i]) - k[i % len(k)]]
            print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    vector<int> Al(N,0);
    vector<int> Bl(N,0);
    vector<int> Cl(N,0);
    vector<int> A(N,0);
    vector<int> B(N,0);
    vector<int> C(N,0);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
        cin >> B.at(i);
        cin >> C.at(i);
    }
    Al.at(0) = A.at(0);
    Bl.at(0) = B.at(0);
    Cl.at(0) = C.at(0);

    for (size_t i = 1; i < N; i++)
    {
        Al.at(i) = max(Cl.at(i-1),Bl.at(i-1))+A.at(i);
        Bl.at(i) = max(Cl.at(i-1),Al.at(i-1))+B.at(i);
        Cl.at(i) = max(Al.at(i-1),Bl.at(i-1))+C.at(i);
    }
    cout << max(Al.at(N-1),max(Bl.at(N-1),Cl.at(N-1))) << endl;



    return 0;
}

Measured memory_bytes: 5612
#include<stdio.h>
#define NIL -1

int depth(int);
int sibling(int);
int height(int);
void output(int);


typedef struct{
  int parent;
  int left;
  int right;
}vertex;

int D[25];
int ver[25];
vertex Tree[25];

int main(){
  
  int i,n,l,r;
  
  scanf("%d",&n);
  
  for( i=0 ; i<n ; i++){
    Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
  }
  for( i=0 ; i<n ; i++){
    scanf("%d",&ver[i]);
    
    if(i == 0){
      Tree[ ver[i] ] .parent= NIL;
    }

    scanf("%d",&Tree[ver[i]].left);
    scanf("%d",&Tree[ver[i]].right);
    
    l = Tree[ver[i]].left;
    r = Tree[ver[i]].right;
    Tree[l].parent = Tree[r].parent = ver[i];
  }

  for( i=0 ; i<n ; i++){
    D[i] = depth(i);
  }
  for( i=0 ; i<n ; i++){
    output(i);
  }
 
  return 0;
}

int depth(int i){
  int d =0;
  while(1){
    if(Tree[i].parent == NIL) break;
    d++;
    i = Tree[i].parent;
  }
  return d;
}

int height(int i){
  int RightHeight=0,LeftHeight=0;
  
  if( Tree[i].left == NIL && Tree[i].right == NIL )return 0;
  if(Tree[i].left!=NIL)LeftHeight = height(Tree[i].left)+1;
  if(Tree[i].right!=NIL)RightHeight = height(Tree[i].right)+1;
  
  if(RightHeight>LeftHeight)return RightHeight;
  else return LeftHeight;
} 

int sibling(int i){
  int s;
  s = Tree[i].parent;
  if( s == -1)return NIL;
  if( i == Tree[s].left)return Tree[s].right;
  else if(i == Tree[s].right)return Tree[s].left;
  else if( Tree[s].right == NIL && Tree[s].left == NIL)return NIL;
}

void output(int i){
  //int d;
  
  printf("node %d: parent = %d, sibling = %d, degree = ",i,Tree[i].parent,sibling(i));
  if(Tree[i].left ==NIL && Tree[i].right ==NIL)printf("0, ");
  else if(Tree[i].left == NIL || Tree[i].right == NIL)printf("1, ");
  else printf("2, ");
 
  printf("depth = %d, height = %d, ",D[i],height(i));
 
  if(Tree[i].left == NIL && Tree[i].right == NIL && Tree[i].parent!=NIL)printf("leaf\n");
  else if(Tree[i].parent == NIL)printf("root\n");
  else printf("internal node\n");
}

Measured memory_bytes: 612
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll h, w;
    cin>>h>>w;
    vector<vector<ll> > v(h, vector<ll> (w));
    for(ll i=0; i<h; i++){
        for(ll j=0; j<w; j++){
            char c;
            cin>>c;
            if(c=='.'){
                v[i][j]=1;
            }
            else{
                v[i][j]=0;
            }
        }
    }
    ll i = 0;
    for(; i<h; i++){
        if(v[i][0]==1){
            v[i][0]=1;
        }
        else{
            break;
        }
    }
    for(; i<h; i++){
        v[i][0]=0;
    }
    i = 0;
    for(; i<w; i++){
        if(v[0][i]==1){
            v[0][i]=1;
        }
        else{
            break;
        }
    }
    for(; i<w; i++){
        v[0][i]=0;
    }
    for(i=1; i<h; i++){
        for(ll j=1; j<w; j++){
            if(v[i][j]==1){
                v[i][j]=(v[i-1][j]+v[i][j-1]);
                v[i][j]%=mod;
            }
            else{
                v[i][j]=0;
            }
        }
    }
    cout<<v[h-1][w-1]<<endl;
    return 0;
}






Measured memory_bytes: 11100
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <string>   
using namespace std;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int sa = 999;
  for(int i=0; i<N-2; i++){
    int num = (S[i]-'0')*100 + (S[i+1]-'0')*10 + S[i+2]-'0';
    sa = min(sa,abs(num - 753));
  }
  cout << sa << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    k--;
    ll a, pivot, ans;
    for (ll i = 0; i < n; i++) {
        cin >> a;
        if (a == 1) pivot = i + 1;
    }
    ll left = pivot - 1;
    ll right = n - pivot;
    if (left % k == 0) ans = left / k;
    else {
        ans = left / k + 1;
        right -= k - left % k;
    }
    if (right < 0) right = 0;
    if (right % k == 0) ans += right / k;
    else ans += right / k + 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    char r, g ,b;
    string s;
    cin >> r >> g >> b;
    s += r; s+= g; s += b;
    int ans = stoi(s);
    if(ans%4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define vvi vector<vi>
#define Q queue<ll>
#define DQ deque<ll> 
#define pb push_back
#define pf push_front
#define popf pop_front
#define popb pop_back
#define mp make_pair
#define mt make_tuple
#define f first
#define s second
#define ub upper_bound
#define lb lower_bound
#define loop(x,y,z) for(ll i=x; i<=y; i+=z)
#define rloop(x,y,z) for(ll i=x; i>=y; i-=z)
#define all(x) x.begin(), x.end()
#define sum(x) accumulate(all(x),0LL)
#define minE(x) *min_element(all(x))
#define maxE(x) *max_element(all(x))
#define watch(x) cout<<(#x)<<" is "<<x
#define endl "\n"

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

void display(vi &v,string c){
	for(auto x:v) cout<<x<<c;
}

int main(){
	IOS
	ll t;
	cin>>t;
	vi v(t),dp(t);
	loop(0,t-1,1) cin>>v[i];
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	loop(2,t-1,1){
		dp[i]=min((dp[i-1]+abs(v[i]-v[i-1])),(dp[i-2]+abs(v[i]-v[i-2])));
	}
	cout<<dp[t-1];
	return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-13;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}

long long fact[510000];
long long inv[510000];
long long finv[510000];
long long C(int a,int b){
	if(b<0||b>a)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
int main(){
	fact[0]=1;
	for(int i=1;i<510000;i++){
		fact[i]=fact[i-1]*i%mod;
	}
	inv[1]=finv[0]=1;
	for(int i=2;i<510000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<510000;i++){
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	int a,b;scanf("%d%d",&a,&b);
	long long ret=0;
	for(int i=0;i<=b;i++){
		int R=i;
		int B=b-i;
		if(R-B<0)continue;
		if(R<a)continue;
		if(R==B){
			long long tmp=C(b-1,R);
			int y=R-a;
			tmp=(tmp+mod-C(b-1,R+y+1))%mod;
			ret=(ret+tmp)%mod;
			continue;
		}
		long long tmp=C(b,i);
		int y=R-a;
		tmp=(tmp+mod-C(b,R+y+1))%mod;

	//	printf("%d %d: %lld %lld\n",R,y,C(b,i),tmp);
		ret=(ret+tmp)%mod;
 	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 12160
import java.io.*;
import java.util.*;
import java.math.*;
     
public class Main{
	public static void main(String[] args) throws Exception {
	IO io = new IO();
	PrintWriter out = new PrintWriter(System.out);
	Solver sr = new Solver();
	sr.solve(io,out);
	out.flush();
	out.close();
    	}

	static class Solver
	{
        void solve(IO io, PrintWriter out)
        {
            int t = 1;
            while(t-->0)
            {
                int n = io.nextInt();
              	int[] ar = new int[n];
              	for(int i=0 ; i<n ; i++)
                  ar[i] = io.nextInt();
              	int dp[] = new int[n];
              	Arrays.fill(dp,Integer.MAX_VALUE);
              	dp[0]=0;
              	int end=0;
              	for( ; end<n-1; end++)
                {
                  dp[end+1] = Math.min(dp[end+1],dp[end]+Math.abs(ar[end]-ar[end+1]));
                  if(end+2<n)
                  	dp[end+2] = Math.min(dp[end+2],dp[end]+Math.abs(ar[end]-ar[end+2]));
                  //out.println(dp[end]);
                }
              	out.print(dp[n-1]);
            }
	    }
	}
	//Special thanks to Petr (on codeforces) who inspired me to implement IO class!
	static class IO
	{
    	private static final int BUF_SIZE = 2048;
        BufferedReader br;
        private IO() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        private boolean isSpace(char c) {
            return c == '\n' || c == '\r' || c == ' ';
        }
        String next() {
            try {
                StringBuilder sb = new StringBuilder();
                int r;
                while ((r = br.read()) != -1 && isSpace((char) r));
                if (r == -1) {
                    return null;
                }
                sb.append((char) r);
                while ((r = br.read()) != -1 && !isSpace((char) r)) {
                    sb.append((char) r);
                }
                return sb.toString();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
	}
}

Measured memory_bytes: 36756
#include <bits/stdc++.h>
// #include "bits/stdc++.h"
 
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int n,x,y;
 
  cin >> n;
  y = n;
  
  rep(i,0,8){
    x += n%10;
    n = n/10;
  }
 
  
  if(y%x == 0) printf("Yes\n");
  else printf("No\n");
 
  return 0;
}

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

using namespace std;

#define lli long long int
#define pb  push_back
#define mp  make_pair

vector <lli> vv;

int main(){
    lli T, flag, res;
    cin >> T;

    if(T == 2){
        cout << "2";
        return 0;
    }
    for(lli j=T; 1; j++){
        flag = 0;
        for(lli i=3; i<=j/2; i= i+2){
            if(j%i == 0) {
                flag = 1;
                res = i;
                break;
            }
        }
        if(flag == 0){
            cout << j;
            break;
        }
    }
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define N 100001
int n,m,Q,a,b;
int dp[N],color[N];
vector<int> e[N];

void paint(int v,int d,int c){
	if(!color[v]) color[v]=c;
	if(dp[v]>=d || d==0) return;
	dp[v]=d;
	for(auto u:e[v]) paint(u,d-1,c);
}

int main(void){
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	cin>>Q;
	int v[Q],d[Q],c[Q];
	rep(i,Q)cin>>v[i]>>d[i]>>c[i];
	rep(i,Q){
		int j=Q-1-i;
		paint(v[j],d[j],c[j]);
	}
	rep(i,n)cout<<color[i+1]<<endl;
	return 0;
}

Measured memory_bytes: 8440
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;


int main(void) {
  ll A, B, N;
  cin >> A >> B >> N;

  // floor(Ax/B) - A*floor(x/B)
  // 左と右の差が答えであり最大値を求める
  // A=6 B=2 x=3で計算してみると
  // floor(6*3/2)=9 と 6*floor(3/2) = 6 の差は3
  // 3というのは、floor(3/2)でで切り捨てられている部分を6倍したもの
  // 切り捨てられている部分は3%2/2で求められる
  // x%Bを大きくすると結果も最大になる
  // x%Bは最大でもB-1、制約としてx<=N
  // x%Bの最大値numをBで割ってA倍してfloor
  ll num = min(B - 1, N);
  ll ans = floor((double)num / (double)B * (double)A);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define M 1e9 + 5
#define C 998244353
#define pi 3.14159265359
#define loop(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define rloop(i,a,b) for(ll i = ll(a); i >= ll(b); --i)
#define sloop(i,a) for (std::set<ll>::iterator i = a.begin(); i != a.end(); ++i)
#define pb push_back
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long int ull;

int solve(){
    ll m=0,n,res=0,flag=0,ans=0,ma=-1,mb=-1;
    cin >> n;
    m = 1;
    loop(i,1,n){
        ll temp = n/i;
        if(n%i==0)
            temp--;
        res += temp;
    }
    cout << res << "\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    loop(f,0,t){    
        solve();
    }   
}

Measured memory_bytes: 3684
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let q = read::<usize>();
    let mut queries = vec![];

    for i in 0..q {
        let v = read_vec::<i64>();
        let (a, b, c, d) = (v[0] - 1, v[1] - 1, v[2] - 1, v[3] - 1);
        queries.push((a, b, c, d));
    }
    for (mut a, mut b, mut c, mut d) in queries {
        let mut crossed = 0;
        let mut max_axis = 0;
        for &(mut a, mut b, mut c, mut d, axis) in &[(a, b, c, d, 0), (b, a, d, c, 1)] {
            for level in 1..31 {
                if (b - d).abs() <= 1 {
                    break;
                }
                if a % 3 == 1 && a == c {
                    if level > crossed {
                        crossed = max(crossed, level);
                        max_axis = axis;
                    }
                }
                a /= 3;
                b /= 3;
                c /= 3;
                d /= 3;
            }
        }
        let mut ans = (a - c).abs() + (b - d).abs();
        if crossed != 0 {
            if max_axis == 1 {
                std::mem::swap(&mut a, &mut b);
                std::mem::swap(&mut c, &mut d);
            }
            ans = (b - d).abs();
            let modular = 3i64.pow(crossed - 1);
            ans += 2;
            ans += min(
                a % modular + c % modular,
                modular - a % modular + modular - c % modular - 2,
            );
        }
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

struct state{
    vector<vector<char>> F;
    int x,y;
    bool operator<(const state& r)const{
        return F<r.F;
    }
};

int main(){
    int H,W;
    cin >> H >> W;
    set<state> s;
    vector<vector<char>> init(H,vector<char>(W,'.'));
    init[0][0] = '#';
    s.insert({init,0,0});
    for(int i=0;i<H+W-2;i++){
        set<state> ns;    
        for(auto now:s){
            if(now.x+1<H){
                now.F[now.x+1][now.y] = '#';
                now.x++;
                ns.insert(now);
                now.F[now.x][now.y] = '.';
                now.x--;
            }
            if(now.y+1<W){
                now.F[now.x][now.y+1] = '#';
                now.y++;
                ns.insert(now);
                now.F[now.x][now.y] = '.';
                now.y--;
            }
        }
        s = ns;
    }
    vector<vector<char>> A(H,vector<char>(W));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin >> A[i][j];
    cout << (s.count({A,H-1,W-1})? "Possible":"Impossible") << endl;
}

Measured memory_bytes: 3840
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<lld> v(405,0),s(405,0);
vector<vector<lld> > dp(405,vector<lld>(405,1e18));
int main()
{
     ios;
     lld n;
     cin>>n;
     rep(i,1,n)
     {
         cin>>v[i];
         dp[i][i]=0;
         s[i]=s[i-1]+v[i];
     }
     rep(l,2,n)
     {
         rep(i,1,n-l+1)
         {
             lld j=i+l-1;
             lld temp=0;
             rep(k,i,j-1)
             {
                 temp=(dp[i][k]+dp[k+1][j]-s[i-1]+s[j]);
                 dp[i][j]=min(dp[i][j],temp);
             }
             //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
         }
     }
     cout<<dp[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll N, R, L; cin >> N >> R >> L;
  vector<ll> time(N, 0), score(N, 0);
  priority_queue<P> pq; rep(i, N) pq.emplace(0, -i);

  ll prevtime = 0, looks, lookt;
  rep(i, R) {
    while (1) {
      tie(looks, lookt) = pq.top();
      lookt *= -1;
      if (score[lookt] == looks) break;
      else pq.pop();
    }
    ll d, t, x; cin >> d >> t >> x; d--;

    time[lookt] += t - prevtime;
    prevtime = t;

    score[d] += x;
    pq.emplace(score[d], -d);
  }

  while (1) {
    tie(looks, lookt) = pq.top();
    lookt *= -1;
    if (score[lookt] == looks) break;
    else pq.pop();
  }
  time[lookt] += L - prevtime;

  ll ans, maxt = -1;
  rep(i, N) {
    if (time[i] > maxt) {
      maxt = time[i];
      ans = i;
    }
  }

  outl(ans+1);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



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

using namespace std;

typedef long long ll;

const string YES = "YES";
const string NO = "NO";


struct Bits {
    int length;
    vector<int> bs;

    Bits expand() {
        Bits nb;
        for (int i = 0; i < bs.size(); i++) {
            nb.bs.push_back(bs[i]);
        }
        for (int i = bs.size() - 1; i >= 0; i--) {
            nb.bs.push_back(bs[i] | (1 << length));
        }
        nb.length = length + 1;
        return nb;
    }

    static Bits identity() {
        return {1, {0, 1}};
    }

};


int shift(int x, int n, int a) {
    int sub = x & ((1 << a) - 1);
    return (x >> a) + (sub << (n - a));
}


Bits compute(int n, int c, int shift_v) {
    Bits s;
    if (c == 1) {
        s = Bits::identity();
        for (int i = 0; i < n - 1; i++) {
            s = s.expand();
        }
    } else {
        s = compute(n, c - 2, 0);
        s.bs.resize(s.bs.size() / 2);
        auto sol = compute(n - 1, c - 2, 1);
        for (int b : sol.bs) {
            s.bs.push_back((1 << (n - 1)) ^ (1 << (n - 2)) ^ b);
        }
    }

    for (int &b : s.bs) {
        b = shift(b, n, shift_v);
    }
    return s;
}


void solve(long long N, long long A, long long B) {

    long long goal = A ^B;
    int c = __builtin_popcount(goal);
    if (c % 2 == 0) {
        cout << NO << endl;
        return;
    }
    auto ans = compute(N, __builtin_popcount(A ^ B), 0);

    vector<int> org[2] = {};
    vector<int> nxt[2] = {};
    int k = 0;
    for (int i = 0; i < 17; i++) {
        org[goal >> i & 1].push_back(i);
        nxt[ans.bs.back() >> i & 1].push_back(i);
    }
    int conv[17];

    for (int p = 0; p < 2; p++) {
        for (int i = 0; i < org[p].size(); i++) {
            conv[nxt[p][i]] = org[p][i];
        }
    }
    cout << YES << endl;
    bool fst = true;
    for (auto &b : ans.bs) {
        int res = 0;
        for (int i = 0; i < N; i++) {
            res |= (b >> i & 1) << conv[i];
        }
        if(!fst){
            cout << " ";
        }
        fst = false;
        b = res ^ A;
        cout << b;
    }
    cout << endl;


}

int main() {
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(N, A, B);
    return 0;
}


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

int main() {
    int n,W;
    cin>>n>>W;
    vector<int> w(n);
    vector<long int> val(n);
    for(int i=0;i<n;++i){
        cin>>w[i]>>val[i];
    }
    vector<vector<long long int>> ans(n+1,vector<long long int>(W+1,0));
    for(int i=1;i<=n;++i){
        for(int j=1;j<=W;++j){
            if(w[i-1]<= j){
                ans[i][j] = max(ans[i-1][j-w[i-1]]+val[i-1],ans[i-1][j]);
            }
            else 
                ans[i][j] = ans[i-1][j];
        }
    }
    cout<<ans[n][W]<<endl;
	return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
//#define endl cout << "\n"
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    long double a, b, h, m;
    cin >> a >> b >> h >> m;

    //find angle
    long double angle = 0.5*(60*h - 11*m);
    //cout << angle << endl;
    if(angle>180) angle = angle-360;
    //convert into degree
    angle = (angle*3.14159265359)/180;
    long double cost = cos(angle);
    long double sqs = (a*a)+(b*b) - (2*a*b*(cost));
    long double ans = sqrt(sqs);
    printf("%.9llf", ans);
    bye;
}



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

int main()
{
    int n;
    cin >> n;
    int a[n];
    set<string> boje;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 400) boje.insert("gray");
        else if (a[i] < 800) boje.insert("brown");
        else if (a[i] < 1200) boje.insert("green");
        else if (a[i] < 1600) boje.insert("cyan");
        else if (a[i] < 2000) boje.insert("blue");
        else if (a[i] < 2400) boje.insert("yellow");
        else if (a[i] < 2800) boje.insert("orange");
        else if (a[i] < 3200) boje.insert("red");
        else cnt++;
    }
    int mx, mn;
    mx = boje.size() + cnt;
    if (boje.size() == 0) mn = 1;
    else mn = boje.size();
    cout << mn << " " << mx << "\n";
    return 0;
}


Measured memory_bytes: 256
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());
ll modinv(ll x,ll m=mod)
{
	return power(x,m-2);
}


int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>k;
		// n=s.length();
		repe(i,k,n+2)
		{
			m=((n-i)*(n-i+1))%mod;
			m=(m*modinv(2))%mod;
			j=(i*(i-1))%mod;
			j=(j*modinv(2))%mod;
			m=(m+j)%mod;
			j=(n*(n+1))%mod;
			j=(j*modinv(2))%mod;
			// debug3(i,m,j);
			m=(j-m+1);
			if(m<0) m=(m+mod)%mod;
			c=(c+m)%mod;
		}
		cout<<c<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	vi v(3);
	rep(i, 3) cin>>v[i];
	sort(all(v));
	rep(i, 3){
		if(v[i]%2==0) {
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<(ll)v[0]*v[1]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector <int> h(n);
	rep(i,n)cin>>h[i];
	vector <int> dp(n);
	rep(i,n)dp[i]=INT_MAX;
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	//cout<<dp[1]<<endl;
	for(int i= 2;i<n;++i)
	{
		dp[i] = min( dp[i-1]+abs( h[i]-h[i-1] ),dp[i-2]+abs( h[i]-h[i-2] ) );
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001


int main(){
	
	int N;
	cin>>N;
	
	int M1,M2;
	cin>>M1>>M2;
	
	vector<pair<int,int>> V(N);
	vector<int> C(N);
	for(int i=0;i<N;i++){
		cin>>V[i].first>>V[i].second>>C[i];
	}
	
	vector<vector<int>> dp(N+1,vector<int>(200000,Inf));
	dp[0][0] = 0;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<200000;j++){
			if(dp[i][j]==Inf)continue;
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			int a = j/400;
			int b = j%400;
			a+=V[i].first;
			b+=V[i].second;
			int c = a*400+b;
			dp[i+1][c] = min(dp[i+1][c],dp[i][j]+C[i]);
		}
	}
	
	int ans = Inf;
	for(int i=1;i<200000;i++){
		int a = i/400;
		int b = i%400;
		if(M1*b!=M2*a)continue;
		ans = min(ans,dp[N][i]);
	}
	
	if(ans==Inf){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	
    return 0;
}



Measured memory_bytes: 33152
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int W = int.Parse(input[0]);
            int H = int.Parse(input[1]);
            int x = int.Parse(input[2]);
            int y = int.Parse(input[3]);
            double S = (double)W * (double)H;
            if ((x * 2 == W && y * 2 == H))
            {
                Console.WriteLine((S / 2f).ToString("F9") + " 1");
            }
            else
            {
                Console.WriteLine((S / 2f).ToString("F9") + " 0");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    int ans = 1e9;
    int len = (int)S.size();
    rep(h, len) {
        char ct = S[h];
        int cnt = 0;
        string s = S;
        while (1) {
            string t = "";
            bool flag = true;
            repd(i, 1, s.size()) {
                if (s[i - 1] != s[i]) flag = false;
            }
            if (flag) break;
            repd(i, 1, s.size()) {
                if (s[i - 1] == ct || s[i] == ct) t += ct;
                else t += s[i];
            }
            s = t;
            cnt++;
        }
        chmin(ans, cnt);
    }

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

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(long[]), N = ip[0], M = ip[1], K = ip[2];

	auto com = new COM(N+1, 998244353);

	long res;
	long col = M;
	foreach_reverse(i; 0..N) {
		long now = col;
		now *= com.nCr(N-1, i);
		if(i <= K) res += now;
		col *= M-1;
		col %= 998244353;
		res %= 998244353;
	}
	res.writeln;
}

/*
 * Only N <= 10^7 is acceptable.
 * preparation: O(MAX)
 * query: O(1)
 */
class COM {
	long[] fact, finv, inv;
	private ulong MAX;
	private ulong MOD;

	this(ulong MAX, ulong MOD) {
		this.MAX = MAX;
		this.MOD = MOD;
		fact = new long[](MAX);
		finv = new long[](MAX);
		inv = new long[](MAX);

		// initialize the arrays
		fact[0] = fact[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		foreach(i; 2..MAX) {
			fact[i] = fact[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	ulong nCr(long n, long k) {
		if(n < k) return 0;
		if(n < 0 || k < 0) return 0;
		assert(n < MAX && k < MAX);
		return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
	ulong factorial(long n) {
		return fact[n];
	}
}

/*
 * N <= 10^18, r <= 10^7 is acceptable.
 * query: O(r)
 */
ulong mod_comb(long n, long r, long m) {
	if(n < r || n < 0 || r < 0) return 0;
	if(r*2 > n) r = n - r;
	if(r == 0) return 1;
	if(r == 1) return n;
	auto inv = new ulong[](r+1);
	auto finv = new ulong[](r+1);
	inv[1] = 1;
	finv[0] = finv[1] = 1;
	foreach(i; 2..r+1) {
		inv[i] = m - inv[m % i] * (m / i) % m;
		finv[i] = finv[i - 1] * inv[i] % m;
	}
	ulong res = 1;
	foreach(i; n-r+1..n+1) (res *= i) %= m;
	(res *= finv[r]) %= m;
	return res;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

long rl() {
	return readAs!long;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+100;

ll n,m,T;

int main()
{
    scanf("%lld",&T);
    n = sqrt(T);
    if(n*n!=T)
    {
        for(ll i=n;i>=1;i--)
        {
            m = T/i;
            if(m*i == T)
            {
                printf("%lld\n",i + m -2);
                return 0;
            }
        }
    }
    printf("%lld\n",n*2-2);
    return 0;
}


Measured memory_bytes: 3740
import java.util.Scanner;

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

		int n1 = 0;
		int n2 = 0;
		int n3 = 0;
		int num = 0;
		for (int i = 0; i < 10; i++) {
			num = scan.nextInt();
			if (num >= n1) {
				n3 = n2;
				n2 = n1;
				n1 = num;
			} else if (num >= n2) {
				n3 = n2;
				n2 = num;
			} else if (num >= n3) {
				n3 = num;
			}
		}
		System.out.println(n1 + "\n" + n2 + "\n" + n3);
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef bitset<705> bs;

int n, m;
bool g[705][705];
int color[705];

bs dp;

void die() {
  cout << "-1\n";
  exit(0);
}

void solve() {
  cin >> n >> m;
  for(int i = 1; i <= n; i++) {
    for(int j = i+1; j <= n; j++) {
      g[i][j] = true;
      g[j][i] = true;
    }
  }
  while(m--) {
    int a, b;
    cin >> a >> b;
    g[a][b] = false;
    g[b][a] = false;
  }
  dp.set(0);
  for(int i = 1; i <= n; i++) {
    if(color[i] != 0) continue;
    queue<int> q;
    color[i] = 1;
    int pos = 0;
    int neg = 0;
    q.push(i);
    while(!q.empty()) {
      int curr = q.front();
      q.pop();
      (color[curr] > 0 ? pos : neg)++;
      for(int out = 1; out <= n; out++) {
        if(!g[curr][out]) continue;
        if(color[out] == color[curr]) die();
        if(color[out] == 0) {
          color[out] = -color[curr];
          q.push(out);
        }
      }
    }
    dp = (dp << pos) | (dp << neg);
  }
  int ret = 1e9;
  for(int i = 0; i <= n; i++) {
    if(dp[i]) {
      int a = i;
      int b = n-i;
      ret = min(ret, a*(a-1)/2 + b*(b-1)/2);
    }
  }
  cout << ret << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
}

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


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

int main()
{
    double n, div;
    char a;
    string str;
    while( cin >> n )
    {
        if( n < 0 )
            break;
        
        str = "";
        div = 128;

        for( int i = 0; i < 12; i++ )
        {
            if( i == 8 )
                str += '.';
            a = (int)( n / div ) + '0';
            str += a;
            if( a == '1' )
                n -= div;
            div /= 2;
        }
        if( n != 0 )
            cout << "NA" << endl;
        else
            cout << str << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
using ll = long long;

ll N, C;
vector<ll> x;
vector<ll> v;
vector<ll> rx;
vector<ll> av;
vector<ll> avx;
vector<ll> rav;
vector<ll> ravx;
vector<ll> maxrx;
vector<ll> maxlx;

int main()
{
    

    cin >> N >> C;

    x.resize(N);
    v.resize(N);
    rx.resize(N);
    av.resize(N);
    avx.resize(N);
    maxrx.resize(N);
    rav.resize(N);
    ravx.resize(N);
    maxlx.resize(N);

    for (int i = 0; i < N;i++)
    {
        cin >> x[i] >> v[i];
        av[i] = v[i];
        avx[i] = av[i] - x[i];
        maxrx[i] = av[i] - x[i];
        if (i != 0)
        {
            av[i] += av[i - 1];
            avx[i] = av[i] - x[i];
            maxrx[i] = max(avx[i], maxrx[i - 1]);
        }
    }

    for (int i = 0; i < N; i++)
    {
        rx[i] = C - x[N - i - 1];
        rav[i] = v[N - i - 1];
        ravx[i] = rav[i] - rx[i];
        maxlx[i] = rav[i] - rx[i];
        if (i != 0)
        {
            rav[i] += rav[i - 1];
            ravx[i] = rav[i] - rx[i];
            maxlx[i] = max(ravx[i], maxlx[i - 1]);
        }
    }

    ll ans = 0;

    for (int i = 0; i < N; i++)
    {
        ans = max(ans, avx[i]);
        //cout << ans << endl;

        if(i != N - 1)
        {
            ans = max(ans, av[i] - 2 * x[i] + maxlx[N - i - 2]);
            //cout << "maxlx:" << maxlx[N - i - 2] << endl;
        }
        //cout << ans << endl;

    }

    for (int i = 0; i < N; i++)
    {
        ans = max(ans, ravx[i]);
        //cout << ans << endl;

        if(i != N - 1)
        {
            ans = max(ans, rav[i] - 2 * rx[i] + maxrx[N - i - 2]);
        }
        //cout << ans << endl;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7424
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+2];
		a[0] = 0;
		for(int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}
		a[n+1] = 0;

		// 全ルートの計算
		int sum = 0;
		int pos = 0;
		for(int i = 0; i <= n; i++) {
			sum += Math.abs(pos - a[i]);
			pos = a[i];
		}
		sum += Math.abs(pos);

		PrintWriter out = new PrintWriter(System.out);
		for(int i = 1; i <= n; i++) {
			int sum2 = sum;
			if( (a[i] - a[i - 1]) >= 0 && ((a[i+1] - a[i]) >= 0) || (a[i] - a[i - 1]) <= 0 && ((a[i+1] - a[i]) <= 0) ) {
				out.println(sum2);
				continue;
			}
			sum2 -= Math.abs(a[i - 1] - a[i]);
			sum2 -= Math.abs(a[i] - a[i + 1]);
			sum2 += Math.abs(a[i - 1] - a[i+1]);
			out.println(sum2);
		}
		out.flush();
	}
}


Measured memory_bytes: 51312
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string s, ans = "";
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from functools import reduce

def gcd_base(x,y):
    while y!=0:
        x,y = y,x%y
    return x

def gcd(num):
    return reduce(gcd_base,num)

def lcm_base(x,y):
    return (x * y) // gcd_base(x,y)

def lcm(num):
    return reduce(lcm_base,num,1)

def calc_denom(l,numer):
    cnt = 0
    for x in l:
        cnt += numer//x
    return cnt

N = int(input())
l = list(map(int,input().split()))
numer = lcm(l)
denom = calc_denom(l,numer)
print(numer/denom)

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int x=a-b;
  if(a>=b and x<=c){
      cout<<c-x;
  }
  else if(x>c){
      cout<<0;
  }
   return 0;
}



Measured memory_bytes: 256
n = gets.to_i
hs = gets.split.map(&:to_i)

max = -Float::INFINITY
min = nil

hs.each.with_index do |h, i|
  if i == 0
    max = h
  else
    if max < h
      max = h
      min = nil
    else
      min = h
    end

    if min && (max - min) > 1
      puts "No"
      exit
    end
  end
end

puts "Yes"


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

int main() {
  string s, t;
  cin >> s >> t;
  int A = s.size();
  int B = t.size();
  vector<string> pos;
  for (int i = 0; i < A-B+1; i++) {
    string S = s;
    string ss = s.substr(i,B);
    bool b = true;
    for (int j = 0; j < B; j++) {
      if (S[i+j] != t[j] && S[i+j] != '?') b = false;
    }
    if (b) {
      for (int j = 0; j < A; j++) {
        if (S[j] == '?' && j >= i && j < i+B) S[j] = t[j-i];
        else if (S[j] == '?') S[j] = 'a';
      }
      pos.push_back(S);
    }
  }
  if (pos.size() == 0) cout << "UNRESTORABLE" << endl;
  else {
    sort(pos.begin(),pos.end());
    cout << pos[0] << endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge = [ [] for i in range(N) ]
rst = 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Measured memory_bytes: 29360
import queue
INF = 100000000

H, W = list(map(int,input().split()))
S = [list(input()) for i in range (H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(sx, sy):
    d = [[-1 for i in range(W)] for j in range(H)]
    d[sx][sy] = 0
    max_d = 0

    q = queue.Queue()
    q.put([sx, sy])

    while not q.empty():
        p = q.get()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0 <= nx) & (nx < H) & (0 <= ny) & (ny < W):
                if (S[nx][ny] != "#") & (d[nx][ny] == -1):
                    d[nx][ny] = d[p[0]][p[1]] + 1
                    q.put([nx, ny])
                    max_d = max(max_d, d[nx][ny])

    return max_d

res = 0
for sx in range(H):
    for sy in range(W):
        if S[sx][sy] == ".":
            res = max(res, bfs(sx, sy))

print(res)


Measured memory_bytes: 56276