akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    ll res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}

ll f[200001];
 
ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a; 
 while(b > 0)
    {
        if(b%2 == 1)
    {
        x=(x*y);
        if(x>MOD) x%=MOD;
    }
    y = (y*y);
    if(y>MOD) y%=MOD; 
    b /= 2;
    }
 return x;
}
 
/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}
 
ll C(ll n, ll r, ll MOD)
{
 
 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
 


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    map <string,int> m1;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        m1[s]++;
    }
    cout<<"AC x "<<m1["AC"]<<endl;
    cout<<"WA x "<<m1["WA"]<<endl;
    cout<<"TLE x "<<m1["TLE"]<<endl;
    cout<<"RE x "<<m1["RE"]<<endl;


    return 0;   
}


 
 


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    
    if(n % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < (n / 2); ++i){
        if(s[i] != s[n / 2 + i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int a[5],m;
char b[5];


int sc(char f)
{
	if(f=='1')return 1;
	if(f=='2')return 2;
	if(f=='3')return 3;
	if(f=='4')return 4;
	if(f=='5')return 5;
	if(f=='6')return 6;
	if(f=='7')return 7;
	if(f=='8')return 8;
	if(f=='9')return 9;
	if(f=='0')return 0;
}

int main()
{
  scanf("%s",b);
	for(int i=0;i<4;i++)
	{
	a[i+1]=sc(b[i]);	
	}
//	cout<<a[2]<<a[3];
	 if(a[1]+a[2]+a[3]+a[4]==7)
	{
		cout<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"+"<<a[4]<<"="<<7;
	}
	else if(a[1]+a[2]+a[3]-a[4]==7)
	{
		cout<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"-"<<a[4]<<"="<<7;
	}
	else if(a[1]+a[2]-a[3]+a[4]==7)
	{
		cout<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"+"<<a[4]<<"="<<7;
	}
	else if(a[1]+a[2]-a[3]-a[4]==7)
	{
		cout<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"-"<<a[4]<<"="<<7;
	}
	
	else if(a[1]-a[2]+a[3]+a[4]==7)
	{
		cout<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"+"<<a[4]<<"="<<7;
	}
	else if(a[1]-a[2]+a[3]-a[4]==7)
	{
		cout<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"-"<<a[4]<<"="<<7;
	}
	else if(a[1]-a[2]-a[3]+a[4]==7)
	{
		cout<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"+"<<a[4]<<"="<<7;
	}
	else if(a[1]-a[2]-a[3]-a[4]==7)
	{
		cout<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"-"<<a[4]<<"="<<7;
	}
	
	return 0;
}

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

using namespace std;

#define ll long long
#define gcd(a,b) __gcd(a,b)s
const int N=2e5+10;
const int inf=1e9;
const int mod=1e9+7;

int  main(int argc, char const *argv[])
{
	/*#ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);

	ll x;
	cin >> x;

	ll rem=x%500;

	ll ans=(x/500)*1000;

	ans+=(rem/5)*5;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define int long long

using namespace std;

int gcd(int a, int b) {
    while (b != 0) {
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

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

    int a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}
template < typename T, typename U >
ostream &operator<<(ostream &os, const pair< T, U > &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

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

struct edge {
	int from, to, d, c, i;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> T;
	while (T--) {
		cin >> N;
		vector< int > A(N);
		rep(i, N) cin >> A[i];
		string S;
		cin >> S;
		vector< int > es;
		int ans = 0;
		for (int i = N - 1; i >= 0; i--) {
			int v = A[i];
			sort(es.rbegin(), es.rend());
			for (auto e : es) {
				chmin(v, v ^ e);
			}
			if (S[i] == '0') {
				if (v != 0) {
					es.push_back(v);
				}
			} else {
				if (v) {
					ans = 1;
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
typedef long long ll;

int main() {
	ll X, Y, count = 1;
	cin >> X >> Y;
	while (1) {
		Y /= 2;
		if (X > Y)break;
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
def hoge():
    import sys
    input = lambda : sys.stdin.readline().rstrip()
    sys.setrecursionlimit(max(1000, 10**9))


    from collections import defaultdict
    n = int(input())
    ns = defaultdict(set)
    for _ in range(n-1):
        u,v = map(int, input().split())
        ns[u-1].add(v-1)
        ns[v-1].add(u-1)


    M = 10**9+7 # 出力の制限
    N = n # 必要なテーブルサイズ

    g1 = [None] * (N+1) # 元テーブル
    g2 = [None] * (N+1) #逆元テーブル
    inverse = [None] * (N+1) #逆元テーブル計算用テーブル
    g1[0] = g1[1] = g2[0] = g2[1] = 1
    inverse[0], inverse[1] = [0, 1] 

    for i in range( 2, N + 1 ):
        g1[i] = ( g1[i-1] * i ) % M 
        inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
        g2[i] = (g2[i-1] * inverse[i]) % M 


    ans = {}
    prevs = {}
    out = [None] * n
    def sub(i, j, prev):
        prevs[i,j] = prev
        if (i,j) in ans:
            return ans[i,j]
        if len(ns[j])==1 and i in ns[j]:
            ans[i,j] = (1, 1)
            return (1, 1)

        count = 1
        sum_size = 0
        for k in ns[j]:
            if k==i:
                continue
            val, size = sub(j, k, i)
            count = (count * val) % M
            count = (count * g2[size]) % M
            sum_size += size
        count = (count * g1[sum_size]) % M
        ans[i,j] = (count, sum_size+1)
        return (count, sum_size+1)

    def sub2(i, j):
        for k in ns[j]:
            if k==i:
                continue
            if (k, j) in ans:
                continue
            tmp_count, tmp_size = ans[j, k]
            total_count, total_size = ans[prevs[j, k], j]
            prev_count, prev_size = ans[j, i]
            new_size = total_size - tmp_size + prev_size
            new_count = (total_count * g2[total_size-1] * g1[new_size-1]) % M
            new_count = (new_count * prev_count * pow(tmp_count, M-2, M)) % M
            new_count = (new_count * g2[prev_size] * g1[tmp_size]) % M
            ans[k, j] = (new_count, new_size)
            val = tmp_count
            val = (val * new_count * g1[new_size+tmp_size-1] * g2[tmp_size-1] * g2[new_size]) % M
            out[k] = val
            sub2(j, k)
    #         print("total: ", total_count, total_size)
    #         print("tmp: ", tmp_count, tmp_size)
    #         print("prev: ", prev_count, prev_size)
    #         new_count = total_count / g1[total_size-1] * g1[new_size-1] * prev_count / tmp_count / g1[prev_size] * g1[tmp_size]
    #         print(new_count)
    #         print("")

    # 0を始点として木DP
    sub(-1, 0, None)

    ans[0, -1] = (1,0)

    # 逆向きを求める
    sub2(-1, 0)
    
    u = 0
    count = 1
    sum_size = 0
    for k in ns[u]:
        val, size = ans[u, k] # sub(u, k, None)
        count = (count * val) % M
        count = (count * g2[size]) % M
        sum_size += size
    count = (count * g1[sum_size]) % M
    out[0] = count
    print("\n".join(map(str, out)))
hoge()

Measured memory_bytes: 257520
import itertools
N,D=map(int,input().split())
X=[]
for _ in range(N):
    X.append(list(map(int,input().split())))

n=[i for i in range(N)]
comb=itertools.combinations(n,2)
conunter=0

for c in comb:
    XI=X[c[0]]
    XJ=X[c[1]]
    total=0
    for d in range(D):
        total+=(XI[d]-XJ[d])**2
    total=total**0.5
    if(total.is_integer()):
        conunter+=1


print(conunter)

Measured memory_bytes: 3188
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let K: usize = sc.get();
    let A: Vec<usize> = sc.vec(N);
    for i in K..N {
        if A[i-K] < A[i] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint x,y,ans=0;
	cin>>x>>y;
	if(abs(x)<abs(y)){
		if(x<0){
			x*=-1;
			ans++;
		}
	}else{
		if(0<x){
			x*=-1;
			ans++;
		}
	}
	lint dis=abs(abs(x)-abs(y));
	ans+=dis;
	x+=dis;
	if(x!=y){
		x*=-1;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int d,g,p[11],c[11],x=1<<29,t,i,j,s,n;
  scanf("%d%d",&d,&g);g/=100;
  for(i=1;i<=d;i++){scanf("%d%d",&p[i],&c[i]);c[i]/=100;}
  for(i=0;i<1<<d;i++){
    s=n=0;for(j=1;j<=d;j++)if((1<<(j-1))&i){n+=p[j];s+=j*p[j]+c[j];}
    if(s<g){
      for(j=d;j>0;j--)if(((1<<(j-1))&i)==0){
        if(j*(p[j]-1)>=g-s)n+=(g-s)/j+((g-s)%j!=0);
        else n=1<<29;
        j=0;
      }
    }
    x=n<x?n:x;
  }
  printf("%d",x);
}


Measured memory_bytes: 1660
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<ll> va,vb;
  rep(i,0,n+1){
    ll a;
    cin>>a;
    va.pb(a);
  }
  rep(i,0,n){
    ll a;
    cin>>a;
    vb.pb(a);
  }
  ll ans = 0;
  rep(i,0,n){
    ll a = min(va[i],vb[i]);
    va[i]-=a;
    vb[i]-=a;
    ll b = min(va[i+1],vb[i]);
    va[i+1]-=b;
    vb[i]-=b;
    ans += a+b;
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=LINF,a[ohara],b[ohara],c,d,cmp[ohara],cmpp,m,h,w,x,y,sum=0,pos,mi[2002][2002];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>x;
      pos=0;
      rep(i,n){
        cin>>a[i];
        pos+=a[i];
        b[i]=INF;
      }
      rrep(i,n,2*n){
        a[i]=a[i-n];
      }
  rep(mahou,n){
        rep(j,n){
          b[j]=min(b[j],a[j+n-mahou]);cnt+=b[j];
        }
        cnt+=mahou*x;
        ans=min(ans,cnt);
        cnt=0;
      }
      Cout(min(ans,pos));
   
      
      
      

       
return 0;
}



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

int main(){
	long long N;
	long long ans=0;
	cin >> N;
	vector<long long> a(N);
	vector<long long> b(N);
	for(auto &k:a)cin >> k;
	for(int i=0;i<N;i++)b[a[i]-1]=i;
	
	map<long long,long long> m;
	
	for(auto i=1;i<=N;i++){
		long long pos=b[i-1];
		long long l,r=pos;
		if(i==1ll){
			l=-1;
			r=N;
		}else{
			auto it=m.lower_bound(pos);
			if(it==m.end())r=N;
			else r=it->first;
			if(it==m.begin())l=-1;
			else l=(--it)->first;
		}
		ans+=(pos-l)*(r-pos)*i;
		m.insert(make_pair(pos,pos));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>

using namespace std;
#define LL long long
using VS = vector<string>;
using VI = vector<int>;
using VL = vector<LL>;
using VVI = vector<VI>;
using VVL = vector<VL>;
#define FOR(i,s,e) for(i = s; i < e; i++)
#define FORR(i,s,e) for(i = e-1; i >= s; i--)
const LL INF = (LL)1e16;
const LL MOD = (LL)1e9 + 7;

#define ma 7378791
bool d[ma+1];
int main(){
  LL m,n,z,i,j;
  while (1){
    cin >> m >> n;
    if (m == 0){
      return 0;
    }
    z = m;
    FOR(i,z,ma+1){
      d[i] = 1;
    }
    FOR(i,0,n){
      while(d[z] == 0)z++;
      for(j = z;j < ma+1;j+=z)d[j] = 0;
    }

    FOR(j,z,ma+1){
      if (d[j]){
        cout << j << endl;
        break;
      }
    }
  }
  return 0;
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  ll x,y;cin>>x>>y;
  int ans=abs(abs(x)-abs(y));
  if(x>0&&y>0&&x>y)ans+=2;
  if(x<0&&y<0&&x>y)ans+=2;
  if(x*y<0)ans+=1;
  if(x>0&&y==0||x==0&&y<0)ans+=1;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
IN = [int(_) for _ in input().split()]
A, B, C = sorted(IN)


ans = C - B
A += C - B

if (C - A) % 2 == 1:
    ans += (C - A + 1) // 2
    ans += 1
else:
    ans += (C - A)//2
print(ans)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.CumulativeSum
{
    class ABC_087_C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] array = new int[2, n];
            for(int i = 0; i < 2; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                {
                    array[i, j] = int.Parse(input[j]);
                }
            }

            int maxPoint = 0;
            for(int i = 0; i < n; i++)
            {
                int sum = 0;
                int y = 0;
                for(int j = 0; j < n; j++)
                {
                    if (j == i)
                    {
                        sum += array[y, j];
                        y++;
                        sum += array[y, j];
                    }
                    else
                    {
                        sum += array[y, j];
                    }
                }
                if (sum > maxPoint)
                {
                    maxPoint = sum;
                }
            }

            Console.WriteLine(maxPoint);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
using pii = pair <int, int>;
#define int ll
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = false;

int a, b, c;
int32_t main()
{
    cin >> a >> b >> c;
    int lf = 4*a*b;
    int rg = (c-a-b)*(c-a-b);
    if (c<a+b)
        cout << "No\n";
    else
        cout << (lf<rg?"Yes":"No")<<'\n';
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		long ans=0;
		int m=0;
		int[] a=sc.Ia;
		Uf uf=new Uf(s[0]);
		for(int i=0;i<s[1];i++){
			int[] q=sc.Ia;
			uf.Union(q[0],q[1]);
		}
		int[] rt=new int[s[0]];
		int[] h=new int[uf.all+1];
		int[] c=new int[uf.all+1];
		for(int i=0;i<s[0];i++){
			int q=uf.Root(i);
			if(rt[q]==0){
				m++;
				h[m]=a[i];
				rt[q]=m;
				c[m]=i;
			}
			else if(h[rt[q]]>a[i]){
				h[rt[q]]=a[i];
				c[rt[q]]=i;
			}
		}
		for(int i=1;i<=m;i++){
			a[c[i]]=int.MaxValue;
			ans+=h[i];
		}
		Array.Sort(a);
		m=(m-1)*2-m;
		for(int i=0;i<m;i++){
			if(a[i]==int.MaxValue){m=-1;break;}
			ans+=a[i];
		}
		if(uf.all==1){m=0;ans=0;}
		Console.WriteLine("{0}",m!=-1?ans.ToString():"Impossible");
	}
}
public class Uf{
	private int[] arr,hi;
	public int all;
	public Uf(int n){
		arr=new int[n];
		hi=new int[n];
		all=n;
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void Union(int a,int b){
		a=Root(a);
		b=Root(b);
		if(a!=b){
			if(hi[a]<hi[b]){
				int v=b;
				b=a;
				a=v;
			}
			arr[a]+=arr[b];
			hi[a]=Math.Max(hi[a],hi[b]+1);
			arr[b]=a;
			all--;
		}
	}
	public bool Same(int a,int b){return Root(a)==Root(b);}
	public int Total(int a){return -arr[Root(a)];}
	public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 30428
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		char[] str = scn.nextLine().toCharArray();
		int ans = 0;
		int buf = 0;
		for(int i = 0;i < str.length;i++) {
		    char ch = str[i];
		    if(ch == 'A' || ch == 'T' || ch == 'C' || ch == 'G') {
		    	buf++;
		    	ans = Math.max(buf, ans);
		    }else {
		    	buf = 0;
		    }
		}
		System.out.println(ans);
	}

}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    cout << (n+k-3)/(k-1) << endl;
    return 0;
}

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

int main() {
    ll n;
    cin >> n;

    ll t = sqrt(n);

    for (ll i = t; i >= 0; i--) {
        if (n % i == 0) {
            cout << i-1+(n/i)-1 << endl;
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 3644
# 素因数分解
def prime_factorization(N):
    tmp = N
    ans = []
    for i in range(2, int(N ** 0.5) + 1):
        count = 0
        while tmp % i == 0:
            tmp //= i
            count += 1
        if count != 0:
            ans.append([i, count])
    if tmp != 1:
        ans.append([tmp, 1])
    if ans == []:
        ans.append([N, 1])
    return ans

N = int(input())
prime_N = prime_factorization(N)
if len(prime_N) == 1 and prime_N[0][1] == 1:
    print(N - 1)
    exit()
start = int(N ** 0.5) + 1
ans_a = 0
ans_b = 0
for a in range(start, 1, -1):
    b = N // a
    if N == a * b:
        ans_a = a
        ans_b = b
        break

print(ans_a + ans_b - 2)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0045
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if (N < 3)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(N / 3);
            }


        }
    }
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int H,W,K;

const int MOD = 1e9+7;

vector<int> change;
vector<vector<int>> next_w;

void rec(int w){
    if(w == W-1){
        vector<int> n(W,0);
        REP(i,W) n[i] = i;
        REP(i,W-1) if(change[i]==1) swap(n[i],n[i+1]);
        REP(i,W){
            next_w[n[i]][i]++;
        }
        return;
    }
    
    
    change[w] = 0;
    rec(w+1);

    change[w] = 1;
    if(w+2 < W) change[w+1]=0, rec(w+2);
    if(w+2 == W) rec(w+1); 
}

int main() {
    cin >> H >> W >> K;

    next_w.assign(W, vector<int>(W,0));
    change.assign(W-1,0);

    rec(0);

    vector<vector<ll>> ans(H+1, vector<ll>(W,0));
    ans[0][0] = 1;

    REP(i,H){
        REP(j,W){
            if(j-1>=0){
                ans[i+1][j-1] += ans[i][j] * next_w[j][j-1];
                ans[i+1][j-1] %= MOD;
            }
            ans[i+1][j] += ans[i][j] * next_w[j][j];
            ans[i+1][j] %= MOD;
            if(j+1<=W-1){
                ans[i+1][j+1] += ans[i][j] * next_w[j][j+1];
                ans[i+1][j+1] %= MOD;
            }
        }
    }

    cout << ans[H][K-1] << endl;

    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;

const int maxn = 1e6+5;
vector<ll> v;
queue<ll> q;
int main()
{
   for(ll i = 1; i <= 9; i++) {
      q.push(i);
   }
   while(!q.empty()){
     ll a = q.front(); q.pop();
     if(a >= 4294967296) continue;
     v.pb(a);
     ll b = a;  ll c = a%10;
     if(c == 0) {
        q.push(b*10);
        q.push(b*10+1);
     }
     else if(c == 9) {
        q.push(b*10+9);
        q.push(b*10+8);
     }
     else {
        q.push(b*10+c);
        q.push(b*10+c-1);
        q.push(b*10+c+1);
     }
   }
   sort(v.begin(), v.end());
   int k; cin >> k;
   cout << v[k-1] << endl;
}


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#define ff first
#define ss second
#define M 1000000007
typedef long long int ll;
using namespace std;
ll n;
ll t;
vector <vector <ll>> a;
//ll power(ll a,ll b){
//    ll ans = 1;
//    while(b>0){
//        if(b%2!=0){
//            ans = ((ans)*(a));
//        }
//        a = ((a)*(a));
//        b=b/2;
//    }
//    return ans;
//}
vector <vector <ll>> dp;
ll solve(ll k,ll m){
    if(k<0){
        return (m==t);
    }
    if(dp[k][m]!=-1){
        return dp[k][m];
    }
    ll ans = 0;
    for(ll i=0;i<n;i++){
        if(a[k][i] && ((m&1<<i)==0)){
            ans+= solve(k-1,m|(1<<i));
            ans = ans%M;
        }
    }
    return dp[k][m]=ans%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    a.assign(n,vector <ll> (n,0));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    t = (1<<n)-1;
    dp.assign(n,vector <ll> (t+1,-1));
    cout<<solve(n-1,0)<<endl;
    return 0;
}


Measured memory_bytes: 360832
class Combination:
    def __init__(self, n_max, mod=10 ** 9 + 7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max + 1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod - 2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def nCr(self, n, r):
        if not 0 <= r <= n:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

def resolve():
    # 各集合Sのmax(S) - min(S)の合計を求める
    # 各A[i]が最大値になる回数、最小値になる回数を求め、それを計算する
    MOD = 10**9+7
    N, K = map(int, input().split())
    A = sorted(map(int, input().split()))

    Comb = Combination(N)
    ans = 0
    for i in range(N):
        # 最大値になる組み合わせは、A[j]: 0 < j < iからK - 1個を選ぶ組み合わせ
        ans += Comb.nCr(i, K-1) * A[i] % MOD
        ans %= MOD
        # 最小値になる組み合わせは、A[j]: i < j < nからK-1個を選ぶ組み合わせ
        ans -= Comb.nCr(N-i-1, K - 1) * A[i]% MOD
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 20836
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int n;
	cin>> n;
	if (n / 10 == 9 || n % 10 == 9)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

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

using namespace std;

int main()
{
    int k , x;
    cin >> k >> x;
    int n = (2*k)-1;
    int temp = x;
    vector <int> vec;
    for(int i = 0; i < (n/2)+1; ++i){
        vec.push_back(temp);
        temp--;
    }

    for(int i = 0; i < (n/2); ++i){
        vec.push_back(x+1);
        x++;
    }

    sort(vec.begin() , vec.end());

    for(int i = 0; i < (int)vec.size(); ++i){
        cout << vec[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m,l;
    cin >> n >> m >> l;
    
    //初期化
    long long A[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    
    long long B[m][l];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            cin >> B[i][j];
        }
    }
    
    long long ans[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            ans[i][j] = 0;
        }
    }
    
    //メイン処理
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < m; k++){
                ans[i][j] += A[i][k]*B[k][j];
            }
        }
    }
    
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            if(j == l-1){
                cout << ans[i][j];
            }else{
                cout << ans[i][j] << " ";
            }
        }
        cout << endl;
    }
    
}



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

int main() {
  int a, b, c, d;
  string r;
  cin >> a >> b >> c >> d;
  
  if (a+b > c+d) r = "Left";
  if (a+b < c+d) r = "Right";
  if (a+b == c+d) r = "Balanced";
  cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool u[11];
int a[10],x,y;
bool ck() {
  if(a[0]&&a[1]&&a[2]&&(a[0]+a[1]+a[2])%x!=y) return 0;
  if(a[3]&&a[4]&&a[5]&&(a[3]+a[4]+a[5])%x!=y) return 0;
  if(a[6]&&a[7]&&a[8]&&(a[6]+a[7]+a[8])%x!=y) return 0;
  if(a[0]&&a[3]&&a[6]&&(a[0]+a[3]+a[6])%x!=y) return 0;
  if(a[1]&&a[4]&&a[7]&&(a[1]+a[4]+a[7])%x!=y) return 0;
  if(a[2]&&a[5]&&a[8]&&(a[2]+a[5]+a[8])%x!=y) return 0;
  if(a[0]&&a[4]&&a[8]&&(a[0]+a[4]+a[8])%x!=y) return 0;
  if(a[2]&&a[4]&&a[6]&&(a[2]+a[4]+a[6])%x!=y) return 0;
  return 1;
}
 
int dfs(int k) {
  if(!ck()) return 0;
  if(k==9) return 1;
  int ans=0;
  if(a[k]) ans+=dfs(k+1);
  else {
    for(int i=1; i<=10; i++) {
      if(u[i]) continue;
      a[k]=i;u[i]=1;
      ans+=dfs(k+1);
      a[k]=0;u[i]=0;
    }
  }
  return ans;
}
 
int main() {
  while(1) {
    memset(u,0,sizeof(u));
    for(int i=0; i<10; i++) {
      cin >> a[i];
      u[a[i]]=1;
    }
    if(a[0]==-1) break;
    x=a[9];
    int ans=0;
    if(!x) {
      for(int i=1; i<11; i++) {
        if(u[i]) continue;
        x=i;
        u[i]=1;
        for(int j=0; j<x; j++) {y=j;ans+=dfs(0);}
        u[i]=0;
      }
    } else {
      for(int j=0; j<x; j++) {y=j;ans+=dfs(0);}
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

int depth(int);
int sibling(int);
int degree(int);
int hight(int);
void print();

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[1000001];
int num=0;
int i,j,n,id,c1,c2,r,l;
int ids[100001];
int k;

int main(){

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].parent=NIL;
    T[i].left=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    ids[i]=id;
    T[id].left=l;
    T[id].right=r;
    T[l].parent=id;
    T[r].parent=id;
  }

  for(i=0;i<n;i++){
    num=0;
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].parent,sibling(i),degree(i),depth(i),height(i));
    if(T[i].parent==NIL){
      printf("root");
      printf("\n");
    }
    else if( T[i].left>=0 || T[i].right>=0){
      printf("internal node");
      printf("\n");
    }
    else if(T[i].left==NIL) printf("leaf\n");
  }

  return 0;
}

int depth(int t){
  int p=T[t].parent;
  if(p==NIL) return num;
  num++;
  depth(p);
}

int sibling(int t){
  int i;
  for(i=0;i<n;i++){
    if(T[t].parent == T[i].parent && t != i){
      return i;
    }
  }
  return -1;
}

int height(int t){
  int lefth=0,righth=0;
  if(T[t].left != NIL){
    lefth = height(T[t].left) + 1;
  }
  if(T[t].right != NIL){
    righth = height(T[t].right) + 1;
  }
  if(lefth > righth)  return lefth;
  else return righth;
}

int degree(int t){

  int n=0,s;
  if(T[t].left>=0) {
    n++;
    if(T[t].right>=0){
      n++;
    }
    return n;
  }

  if(T[t].right>=0){
    n++;
    return n;
  }
  return n;
}

Measured memory_bytes: 624
import sys
# N,M = [int(n) for n in input().split()]
N = int(input())
S = list(input())
st = set(S)
# for s in S:
#     st.add(s)
kind = len(st)
maxi = 0
# print(kind)
for i in range(1,len(S)-1):
    # print(i)
    l = set(S[:i])
    r = set(S[i:])
    tmp = len(l&r)
    # print(tmp)
    maxi = max(tmp,maxi)

print(maxi)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=200000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
int a[200010];
int dp[200010][3];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>a[i];
    if(n%2==0){
        rep(i,n){
            rep(j,2){
                dp[i][j]=-INF;
            }
        }
        dp[0][0]=a[0];
        dp[1][1]=a[1];
        dp[2][0]=a[0]+a[2];
        for(int i=3;i<n;i++){
            rep(j,2){
                if(j>=0){
                    chmax(dp[i][j],dp[i-2][j]+a[i]);
                }
                if(j>=1){
                    chmax(dp[i][j],dp[i-3][j-1]+a[i]);
                }
            }
        }
        int ans=-INF;
        rep(j,2){
            chmax(ans,dp[n-1][j]);
            chmax(ans,dp[n-2][j]);
        }
        cout<<ans<<endl;
    }
    else{
        rep(i,n){
            rep(j,3){
                dp[i][j]=-INF;
            }
        }
        if(n==3){
            cout<<max({a[0],a[1],a[2]})<<endl;
            return 0;
        }
        dp[0][0]=a[0];
        dp[1][1]=a[1];
        dp[2][2]=a[2];
        dp[2][0]=a[0]+a[2];
        dp[3][1]=max(a[0]+a[3],a[1]+a[3]);
        for(int i=4;i<n;i++){
            rep(j,3){
                if(j>=0){
                    chmax(dp[i][j],dp[i-2][j]+a[i]);
                }
                if(j>=1){
                    chmax(dp[i][j],dp[i-3][j-1]+a[i]);
                }
                if(j>=2){
                    chmax(dp[i][j],dp[i-4][j-2]+a[i]);
                }
            }
        }
        int ans=-INF;
        rep(j,3){
            chmax(ans,dp[n-1][j]);
        }
        cout<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 9908
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
stack<int> st;
int solve(string);

int solve(string str) {
    int b = st.top(); st.pop();
    int a = st.top(); st.pop();

    if (str == "+") return a+b;
    else if (str == "-") return a-b;
    else if (str == "*") return a*b;
    else if (str == "/") return a/b;
}

int main() {
    string str;
    while (cin >> str) {
        if (str=="+" || str=="-" || str=="*" || str=="/")
            st.push(solve(str));
        else st.push(atoi(str.c_str()));
        if (getchar()=='\n') {
            cout << st.top() << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3148
// AOJ 1217: Family Tree
// 2017.10.15

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define HASHSIZ 2003
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table

int insert(char *s, int w, int id)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

int lookup(char *s, int w)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	return -1;
}

typedef struct { char nm[21]; int p; } T;
T t[1002]; int sz;

char buf[101], *p;
int n;

int parse(int w, int par)
{
	int l, k, nd, w2;

	p = buf; l = 0; while (isspace(*p)) p++, l++;
	while (1) {
		p = buf, w2 = 0; while (isspace(*p)) p++, w2++;
		if (w2 == l) {
			k = strlen(p) - 1; p[k] = 0;
			nd = sz++;
			strcpy(t[nd].nm, p); t[nd].p = par; insert(t[nd].nm, k, nd);
		} else if (w2 < l) return 1;
		if (n == 0) return 0;
		fgets(p=buf, 100, stdin), n--;
		w2 = 0; while (isspace(*p)) p++, w2++;
		if (w2 == l) continue;
		if (w2 < l) return 1;
		if (!parse(l, nd)) return 0;
	}
	return 0;
}

int seek(int par, int chi)
{
	if (t[chi].p == par) return 1;
	if (t[chi].p == 0) return 0;
	return seek(par, t[chi].p);
}

char *next(char *p, int skipsps)
{
	while (isspace(*p)) p++;
	if (!skipsps) while (isalpha(*p)) p++;
	while (isspace(*p)) p++;
	return p;
}

int main()
{
	int m, a, b, ans;
	char *q, rel, *msg[] = { "False", "True" };

	while (fgets(p=buf, 100, stdin) && *buf != '0') {
		memset(hash, 0, sizeof(hash));
		n = atoi(p); while (*p >= '0') p++; m = atoi(p);

		sz = 1; fgets(buf, 100, stdin); n--;
		parse(0, 0);

		while (m-- > 0) {
			fgets(buf, 100, stdin); p = next(buf, 1);
			q = p; while (isalpha(*p)) p++; *p = 0;
			a = lookup(q, p-q); p++;
			p = next(p, 0); p = next(p, 0);  // skip is a/an
			rel = *p++;
			p = next(p, 0); p = next(p, 0);  // skip rel.. of 
			q = p; while (isalpha(*p)) p++; *p = 0;
			b = lookup(q, p-q);

			if      (rel == 'c') ans = (t[a].p == b);
			else if (rel == 'p') ans = (t[b].p == a);
			else if (rel == 's') ans = (t[a].p == t[b].p);
			else if (rel == 'd') ans = seek(b, a);
			else                 ans = seek(a, b);
			puts(msg[ans]);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1664
//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
using namespace std;

#define maxn 1000007
#define DP_maxn 16
#define INF 1000000000
#define mod 998244353
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12
#define f_read freopen("std.in","r",stdin);
#define f_witten freopen("std.out","w",stdout);

typedef long long ll;

struct Edge{
    int from,to;
    Edge(int u,int v):from(u),to(v){}
};

/*-------------------------------template End--------------------------------*/

ll s;
ll X1,X2,Y1,Y2,X3,Y3;

void getans(){
    X2 ++;
    Y2 = 1;
    Y3 = X2;
    X3 = X2 * Y3 - s;
    if(X3 > INF) {
        Y2 = 1;
        Y3 = X2 - 1;
        X3 = X2 * Y3 - s;
    }
}

int main() {
    cin>>s;
    X1 = 0,Y1 = 0;
    X2 = sqrt(s);
    if(X2 * X2 == s)  {
        cout<<0<<" "<<0<<" "<<0<<" "<<X2<<" "<<X2<<" "<<0<<endl;
        return 0;
    }
    getans();
    cout<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<" "<<X3<<" "<<Y3<<endl;
    return 0;
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int x,y;
  cin >> x >> y;

  for(int i = 0; i <= x; i++){
    int j = x - i;

    if(2 * i + 4 * j == y && j >= 0 && j <= x){
      cout << "Yes" << endl;
      return 0;
    } 
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3644
#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 sz(x) (int)(x).size()
#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 newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
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;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  ll t1,t2,a1,a2,b1,b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  ll v1 = a1-b1;
  ll v2 = a2-b2;
  if(t1*v1+t2*v2 == 0) {
    cout << "infinity" << endl;
    return 0;
  }
  if(v1 < 0) {
    v1 *= -1;
    v2 *= -1;
  }
  if(t1*v1+t2*v2>0) {
    cout << 0 << endl;
    return 0;
  }
  ll h = v1*t1;
  ll d = -1 * (t1*v1+t2*v2);
  if(h%d != 0) {
    cout << 2*(h/d)+1 << endl;
  } else {
    cout << 2*(h/d) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
A = list(map(int, input().split()))

tot = A[0] + k - A[-1]
length = tot
for i in range(1, n):
    now = A[i] - A[i-1]
    tot += now
    length = max(length, now)

ans = tot - length
print(ans)

Measured memory_bytes: 26444
n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 8996