akhauriyash/Code-Regression huggingface dataset:
program C176
    implicit none
    integer(8) :: N
    integer(8), allocatable :: A(:)
    integer(8) :: i, step

    read(5,*) N
    allocate(A(N))
    read(5,*) (A(i), i = 1, N)

    step = 0
    if (N /= 1) then
        do i = 2, N
            if (A(i-1)>A(i)) then 
                step = step + A(i-1) - A(i)
                A(i) = A(i-1)
            end if
        end do 


    end if

    write(6,*) step
    
end program C176

Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int n, m, h[100005], a, b, d, N, H, t2, o;
bool u[100005];
ll D, t;
vector<pii> v[100005];
pq<pair<ll, pii> > q;
int main(){
    scanf("%i%i%i",&n, &m, &o);
    fox1(l, n){
        scanf("%i", &h[l]);
    }
    fox(l, m){
        scanf("%i%i%i", &a, &b, &d);
        v[a].pb(mp(b, d));
        v[b].pb(mp(a, d));
    }
    q.push(mp(0, mp(o, 1)));
    while(!q.empty()){
        D=-q.top().x; H=q.top().y.x; N=q.top().y.y; q.pop();
        if (u[N]) continue;
        u[N]=1;
        //cout << N << ' ' << D << ' ' << H << endl;
        if (N==n){
            cout << D+h[N]-H << endl;
            return 0;
        }
        fox(l, v[N].size()){
            if (v[N][l].y>h[N]) continue;
            t=-D-v[N][l].y;  t2=H;
            if (t2-v[N][l].y>h[v[N][l].x]){
                t-=t2-v[N][l].y-h[v[N][l].x];
                t2=v[N][l].y+h[v[N][l].x];
            }
            if (t2<v[N][l].y){
                t-=v[N][l].y-t2;
                t2=v[N][l].y;
            }
            q.push(mp(t, mp(t2-v[N][l].y, v[N][l].x)));
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 22072
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
a.sort()
bc.sort(key=lambda x:x[1], reverse=True)
i = 0
j = 0
while i < n and j < m:
    if a[i] < bc[j][1]:
        a[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if  bc[j][0] == 0:
            j += 1
    else:
        break
print(sum(a))

Measured memory_bytes: 81480
N = int(raw_input())
p = list(map(int,raw_input().split()))
p_sort = sorted(p)

ans = 0
for i in range(0,N):
  if p[i] != p_sort[i]:
    ans = ans + 1
if ans == 2 or ans == 0:
  print "YES"
else:
  print "NO"

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

int main(){
    int n;
    int num[] = {105,135,165,189,195};
    int count = 0;
    cin >> n;
    for(int i=0;i<5;i++){
        if (num[i]<=n){
            count++;
        }
    }
    cout << count << "\n";
    return 0;
}

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

int main() {
  
  long long n, k;
  cin >> n >> k;
  
  if (n>k) {
    long long s=n%k;
    cout << min(s, k-s) << endl;
  }
  
  else cout << min(n, k-n) << endl;
}


Measured memory_bytes: 256
import math


N = int(input())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))

def CO(l):
    n = len(l)
    if n != 1:
        m = sorted(l)
        a = l[0]
        s = m.index(a)
        l.remove(a)
        return((s)*math.factorial(n-1)+CO(l))
    else:
        return 1

print(abs(CO(list1)-CO(list2)))


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>

int main() {
  size_t N;
  scanf("%zu", &N);

  intmax_t a[26]={};
  int b[26]={};
  for (size_t i=0; i<N; ++i) {
    char buf[16];
    scanf("%s", buf);
    char ch=buf[0];
    ++a[ch-'A'];
    b[ch-'A'] = 1;
  }

  if (b['M'-'A'] + b['A'-'A'] + b['R'-'A'] + b['C'-'A'] + b['H'-'A'] < 3)
    return !printf("0\n");

  intmax_t res=0;
  intmax_t *p=a-'A';
  res += p['M'] * p['A'] * p['R'];
  res += p['M'] * p['A'] * p['C'];
  res += p['M'] * p['A'] * p['H'];
  res += p['M'] * p['R'] * p['C'];
  res += p['M'] * p['R'] * p['H'];
  res += p['M'] * p['C'] * p['H'];
  res += p['A'] * p['R'] * p['C'];
  res += p['A'] * p['R'] * p['H'];
  res += p['A'] * p['C'] * p['H'];
  res += p['R'] * p['C'] * p['H'];
  printf("%jd\n", res);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

enum Animal
{
    S, // sheep
    W  // wolf
};

bool Solve(const std::string &s, std::vector<Animal> &arr)
{
    for (int i = 1; i < s.size() - 1; ++i)
    {
        if (arr[i] == S)
        {
            if (s[i] == 'o')
            {
                arr[i + 1] = arr[i - 1];
            }
            else
            {
                arr[i + 1] = static_cast<Animal>(1 - arr[i - 1]);
            }
        }
        else
        {
            if (s[i] == 'o')
            {
                arr[i + 1] = static_cast<Animal>(1 - arr[i - 1]);
            }
            else
            {
                arr[i + 1] = arr[i - 1];
            }
        }
    }

    const auto n = s.size();

    if (arr[0] == S)
    {
        if (s[0] == 'o' && arr[n - 1] != arr[1])
        {
            return false;
        }
        else if (s[0] == 'x' && arr[n - 1] == arr[1])
        {
            return false;
        }
    }else{
        if (s[0] == 'o' && arr[n - 1] == arr[1])
        {
            return false;
        }
        else if (s[0] == 'x' && arr[n - 1] != arr[1])
        {
            return false;
        }
    }

    const int i = n - 1;
    if (arr[i] == S)
    {
        if (s[i] == 'o')
        {
            return arr[0] == arr[i - 1];
        }
        else
        {
            return arr[0] != arr[i - 1];
        }
    }
    else
    {
        if (s[i] == 'o')
        {
            return arr[0] != arr[i - 1];
        }
        else
        {
            return arr[0] == arr[i - 1];
        }
    }
}

void Output(std::vector<Animal> &arr)
{
    for (const Animal a : arr)
    {
        if (a == S)
        {
            std::cout << 'S';
        }
        else
        {
            std::cout << 'W';
        }
    }
    std::cout << std::endl;
}

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

    std::vector<Animal> arr(n);
    // 先頭がSSを仮定
    arr[0] = arr[1] = S;
    if (Solve(s, arr))
    {
        Output(arr);
        return 0;
    }

    arr[0] = S;
    arr[1] = W;
    if (Solve(s, arr))
    {
        Output(arr);
        return 0;
    }

    arr[0] = W;
    arr[1] = S;
    if (Solve(s, arr))
    {
        Output(arr);
        return 0;
    }

    arr[0] = arr[1] = W;
    if (Solve(s, arr))
    {
        Output(arr);
        return 0;
    }

    std::cout << -1 << std::endl;
    return 0;
}


Measured memory_bytes: 3704
/*
6
4 6 8 12 44 32
*/
use std::io;
fn main() {
    let mut num = String::new();
    io::stdin().read_line(&mut num).unwrap();

//    let num: i32 = num.trim().parse().unwrap();

//    println!("{}", num);

    let mut aline = String::new();
    io::stdin().read_line(&mut aline).unwrap();
    let iter = aline.split_whitespace();

    let mut min_n = 100;
    for s in iter {
        let n :u32 = s.parse().unwrap();
        //println!("{}",n.trailing_zeros());
        min_n = std::cmp::min(n.trailing_zeros(), min_n);
        //println!("{}", min_n);
    }
    println!("{}", min_n);

}

Measured memory_bytes: 4352
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = "";
        
        if(a.length()>b.length()){
            for(int i =0;i<a.length();i++){
                c+=a.charAt(i);
                if(i==a.length()-1){
                    break;
                }
                c+=b.charAt(i);
            }

        }else{
            for(int i =0;i<a.length();i++){
                c+=a.charAt(i);
                c+=b.charAt(i);
            }

        }


        System.out.println(c);

    }
}






Measured memory_bytes: 22608
import sys
Ws = sys.stdin.readlines()
for w in Ws:
    b = bin(int(w))
    t = {0 : 1,
         1 : 2,
         2 : 4,
         3 : 8,
         4 : 16,
         5 : 32,
         6 : 64,
         7 : 128,
         8 : 256,
         9 : 512,
         10: 1024}
    print(* [t[digi] for digi in range(len(b)-2) if b[-1-digi] == '1'])

Measured memory_bytes: 7676
def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

while True:
    o= int(input())
    if o== 0: break
    c, o= 0, 1000-o
    for l in [500, 100, 50, 10, 5, 1]: change(l)
    print(c+o)

Measured memory_bytes: 7640
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    #include<string>
    #include<stdlib.h>
    using namespace std ;

    int gcd(int a, int b){
      if(a%b==0)return b;
      else return gcd(b,a%b);
    }
    int main(){
      int N,X,ans=1,m=0;
      cin>>N>>X;
      int L[1000];
      for(int i=0;i<N;i++){
        cin>>L[i];
        m=m+L[i];
        if(m<=X)ans++;
      }
      cout<<min(N+1,ans)<<endl;
      return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;


char map[100][100];

int main(){
	
	bool ans=true;
	
	int h,w;cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)cin>>map[i][j];
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(map[i][j]=='#'){
				bool b=true;
				if(map[i+1][j]=='#')b=false;
				if(map[i-1][j]=='#')b=false;
				if(map[i][j+1]=='#')b=false;
				if(map[i][j-1]=='#')b=false;
				if(b)ans=false;
			}
		}
	}
	
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	//system("pause");
	return 0;
}

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

using namespace std;

int main(){
    long long int N,time=0;
    cin >> N;
    vector<long long int> C(N-1),S(N-1),F(N-1),ans(N);
    for(int i=0;i<N-1;i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(int i=0;i<N-1;i++){
        long long int now=0;
        now += C[i] + S[i];
        for(int j=i+1;j<N-1;j++){
            if(now<S[j]){
                now = S[j] + C[j];
            }else if(now%F[j]!=0){
                now += (F[j]-now%F[j]) + C[j];
            }else{
                now += C[j];
            }
        }
        ans[i] = now;
    }

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

    cout << 0 << endl;
}

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <iterator>
#include <map>
#include <set>
#ifndef ONLINE_JUDGE
#include <prettyprint/prettyprint.hpp>
#endif

#define FOR(i, n) for(int i = 0; i < n; ++i)
#define TEST int T; std::cin >> T; while(T--)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	ifstream fin("in.txt");
	ofstream fout("out.txt");
	auto cinbuf = cin.rdbuf(fin.rdbuf());    // save and redirect
	auto coutbuf = cout.rdbuf(fout.rdbuf()); // save and redirect
#endif	
	int n;
	cin >> n;
	vi heights(n);
	vi values(n);
	for(auto& e : heights) {
		cin >> e;
	}
	for(auto& e : values) {
		cin >> e;
	}
	vull dp(n + 1);
	dp[0] = 0;

	// Iterative segtree.
	int size = (1 << (int)ceil(log2(n + 1)) + 1);
	int N = size / 2;
	vull tree(size);

	auto update = [&](int idx, ull x) {
		int i = N + idx;
		tree[i] = x;
		i /= 2;
		while(i != 0) {
			tree[i] = max(tree[2 * i], tree[2 * i + 1]);
			i /= 2;
		}
	};

	auto query = [&](int r) {
		int x = r + N;
		ull ans = 0;
		while(x > 0) {
			if(x % 2) {
				ans = max(ans, tree[--x]);
			}
			x /= 2;
		}
		return ans;
	};

	for (int i = 0; i < n; ++i) {
		ull best = query(heights[i]);
		update(heights[i], best + values[i]);
	}
	cout<< tree[1] << endl;
#ifndef ONLINE_JUDGE
	cin.rdbuf(cinbuf);    // restore
	cout.rdbuf(coutbuf); // restore
#endif	
}


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

int main()
{
	int n,i;
	cin>>n;
	int a[n];
	int b[n];
	for(i=0; i<n; i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
		
	
	sort(a,a+n);
	
	for(i=0; i<n; i++)
		if(b[i]!=a[n-1])
			cout<<a[n-1]<<endl;
		else
			cout<<a[n-2]<<endl;
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int A, B, C, X, ans=0, m=0;
    cin >> A >> B >> C >> X;
    for(int x=0; x<=A; x++){
        for(int y=0; y<=B; y++){
            m=(X-(500*x + 100*y))/50;
            if(C>=m && m>=0) ans++;
        }
    }
    cout << ans << endl;
    
}


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

int main(){
    int k,s;
    cin >> k >> s;
    
    ll cnt = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            if(s-x-y>=0 and s-x-y<=k) cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
map<ll,ll> mp;

void factor(ll n ){
	for(ll i=2;i*i<=n ; i++){
		while(n%i==0){
			mp[i]++;
			n=n/i;
		}
	}
	if(n!=1)mp[n]=1;
}

int main(){
	//mahakal(),fast;
	
	ll a , b ;
	cin>> a >> b ;
	ll g=__gcd(a,b);
	factor(g);
	ll ans = mp.size();
	cout<<ans+1<<endl;

	return 0;
}

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

const int N = 2e5+5;
int n, a[N], value[N];
long long dp[N];
//dp[i] -> the best subsequence if the last taken flower has height i

void max_self(long long& a, long long b) {
  a = std::max(a, b);
}

void update(int i, long long value) {
  for (; i <= n; i += i&-i)
    max_self(dp[i], value);
}

long long query(int i) {
  long long ans = 0;
  for (; i > 0; i -= i&-i)
    max_self(ans, dp[i]);
  return ans;
}

int32_t main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a+i);
  for (int i = 0; i < n; i++)
    scanf("%d", value+i);

  for (int i = 0; i < n; i++)
    update(a[i], query(a[i]-1) + value[i]);

  printf("%lld\n", query(n));
  return 0;
}


Measured memory_bytes: 3328
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 92233720368547758070
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

ll h,w,k,dp[8][101]={},b[7]={},c[8]={};
bool f,g;

int main(){
	cin>>h>>w>>k;
	if(w==1){
		cout<<1<<endl;
		return 0;
	}
	dp[0][0]=1;
	for(int i=0;i<(1<<(w-1));++i){
		int l=i;
		f=false;
		g=true;
		for(int j=0;j<w-1;++j){
			if(l%2){
				if(f){
					g=false;
					break;
				}
				f=true;
			}
			else
				f=false;
			l/=2;
		}
		if(g){
			l=i;
			f=false;
			for(int j=0;j<w-1;++j){
				if(l%2){
					++b[j];
					f=true;
				}
				else{
					if(!f){
						++c[j];
					}
					f=false;
				}
				l/=2;
			}
			if(!f)++c[w-1];
		}
	}
	for(int i=1;i<=h;++i){
		dp[0][i]=(dp[0][i-1]*c[0]%mod+dp[1][i-1]*b[0]%mod)%mod;
		dp[w-1][i]=(dp[w-1][i-1]*c[w-1]+dp[w-2][i-1]*b[w-2]%mod)%mod;
		for(int j=1;j<w-1;++j){
			dp[j][i]=(dp[j-1][i-1]*b[j-1]%mod+dp[j][i-1]*c[j]%mod+dp[j+1][i-1]*b[j]%mod)%mod;
		}
	}
	cout<<dp[k-1][h]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define wi while
#define vl vector<ll>
#define vi vector<int>
#define map map<char,ll>
#define endl "\n"
const int mxN = 3002;
ll dp[mxN][mxN];
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    for(int l=n-1;l>=0;--l)
    {
        for(int r=l;r<n;++r)
        {
            if(l==r)
            {
                dp[l][r] = a[l];
            }
            else
            {
                dp[l][r] = max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
            }
        }
    }

    cout<<dp[0][n-1]<<endl;








    return 0;

}


Measured memory_bytes: 49784
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}void _p() {cout << "]\n";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=========================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   
    cin>>x>>y;
    if(x==1 || y==1){cout<<1;return;}
    
    
    
    cout<< (x*y+1)/2  <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main(void)
{
  int n, tmp;
  std::map<int, int> v[2];
  std::cin >> n;
  for(int i = 0; i != n; i++){
    std::cin >> tmp;
    v[i % 2][tmp]++;
  }
  auto itr1 = v[0].begin(), itr2 = v[1].begin();
  for(int i = 0; i != 2; i++){
    int max = 0;
    for(auto it = v[i].begin(); it != v[i].end(); it++){
      if(it->second > max){
        if(i == 0) itr1 = it;
        else itr2 = it;
        max = it->second;
      }
    }
  }
  if(itr1->first != itr2->first){
    std::cout << n - itr1->second - itr2->second << std::endl;
  }else{
    int m1 = itr1->second, m2 = itr2->second;
    for(int i = 0; i != 2; i++) v[i][itr1->first] = 0;
      for(int i = 0; i != 2; i++){
        int max = 0;
        for(auto it = v[i].begin(); it != v[i].end(); it++){
          if(it->second > max){
            if(i == 0) itr1 = it;
            else itr2 = it;
            max = it->second;
          }
        }
      }
    std::cout << n - std::max(m1 + itr2->second, m2 + itr1->second) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 4992
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int main() {
    int N;cin >> N;
    if(N == 1) {
        cout << "Hello World" << endl;
    }
    else{
        int a,b;cin >> a >> b;cout << a+b << endl;
    }

    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const double PI=3.1415926535897932384626433;
typedef long long ll;
//#define DEBUG

#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

const int INF=1e9+7;

template<typename T>
void floyd_warshal(vector<vector<T>> &d, int n) {
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cini(n);
    cinas(s, n);

    vvi tree(n, vi(n));
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
            if(s[i][j]=='1') {
                tree[i][j]=tree[j][i]=1;
            } else {
                tree[i][j]=tree[j][i]=INF;
            }

#ifdef DEBUG
    cout<<"parsed tree"<<endl;
#endif

    vi level(n);

    function<bool(int,int)> dfs=[&](int node, int parent) {
#ifdef DEBUG
    cout<<"bfs node="<<node<<" parent="<<parent<<" level[node]="<<level[node];
    if(parent>=0)
        cout<<" level[parent]="<<level[parent];
    cout<<endl;
#endif
        if(level[node]>0) {
            int loopsz=abs(level[node]-level[parent])+1;
#ifdef DEBUG
    cout<<"loopsz="<<loopsz<<endl;
#endif
            if(loopsz&1)
                return false;    // loop of odd size are not ok
            else
                return true;
        }

        if(parent>=0)
            level[node]=level[parent]+1;
        else
            level[node]=1;
#ifdef DEBUG
    cout<<"level[node]="<<level[node]<<endl;
#endif

        for(int i=0; i<n; i++) {
            if(tree[node][i]==1 && (i!=parent))
                if(!dfs(i, node))
                    return false;
        }

        return true;
    };
    bool ok=dfs(0, -1);

    if(!ok) {
        cout<<-1<<endl;
        return 0;
    }

    floyd_warshal(tree, n);
    int ans=0;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            ans=max(ans, tree[i][j]);
#ifdef DEBUG
            cout<<tree[i][j]<<" ";
#endif
        }
#ifdef DEBUG
        cout<<endl;
#endif
    }

    cout<<ans+1<<endl;
}



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



int main() {
  ll N; cin >> N;
  ll A[N];
  rep(i,N){
    cin >> A[i];
  }
  ll step = 0;
  ll sum = 0;
  for(ll i = 1; i < N; i++){
  step = A[i - 1] - A[i];
    if (step > 0) {
      A[i] += step;
      sum += step;
    } 
  }

  cout << sum << endl;

	return 0;
}



Measured memory_bytes: 5092
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, K;
double p[200000];
double sum[200000];
signed main(){
	cin >> N >> K;
	rep(i, N){
		double t;
		cin >> t;
		p[i] = (t+1.0) / 2.0;
		//cout << p[i] << endl;
	}
	rep(i, N){
		sum[i] = (i != 0 ? sum[i-1] : 0) + p[i];
	}
	double M = 0;
	rep(i, N-K+1){
		M = max(M, sum[i+K-1]-(i!=0 ? sum[i-1] : 0));
		//cout << sum[i+K-1]-(i!=0 ? sum[i-1] : 0) << endl;
	}
	cout << fixed << setprecision(32) << M << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <bitset>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e15;
constexpr const ll MOD = 1000000007;
constexpr int nx[4] = {1,0,-1,0};
constexpr int ny[4] = {0,1,0,-1};
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i,1<<3){
        ll a = s[0]-'0';
        string ans = "";
        ans += s[0];
        rep(j,3){
            if (i&(1<<j)){
                a += s[1+j]-'0';
                ans += '+';
            }
            else{
                a -= s[1+j]-'0';
                ans += '-';
            }
            ans += s[1+j];
        }
        if (a == 7){
            ans += "=7";
            PRINT(ans);
            return 0;
        }
    }
}


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

int main() {
    int n;
    double d;
    scanf("%d %lf", &n, &d);
    int sum= 0;
    for (int i= 0;i< n;i++) {
        long long x, y;
        scanf("%lld %lld", &x, &y);
        double dis= sqrt(x* x+ y* y);
        if (dis <= d) sum++;
    }
    cout << sum << endl;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
 int n,k;
 string s;
 cin>>n>>k;
 cin>>s;

 s.at(k-1)=s.at(k-1)+32;
 cout<<s<<endl;

return 0;}


Measured memory_bytes: 256
import math

N=int(input())
A=list(map(int,input().split()))

a=max(A)
def era(n):
  prime=[]
  furui=list(range(2,n+1))
  while furui[0]<math.sqrt(n):
    prime.append(furui[0])
    furui=[i for i in furui if i%furui[0]!=0]
  return prime+furui

b=A[0]
for i in range(1,N):
  b=math.gcd(b,A[i])

if b!=1:
  print("not coprime")
  exit()

furui=era(10**6+7)
minfac=list(range(10**6+7))
for i in furui:
  for j in range(i,(10**6+7)//i):
    if minfac[i*j]==i*j:
      minfac[i*j]=i
      
dummy=[False]*(10**6+7)
for i in range(N):
  k=A[i]
  while k!=1:
    if dummy[minfac[k]]==True:
      print("setwise coprime")
      exit()
    else:
      dummy[minfac[k]]=True
      f=minfac[k]
      while k%f==0:
        k//=f
print("pairwise coprime")

Measured memory_bytes: 250856
#include<cstdio>
#include<algorithm>
#define maxn 200005
using namespace std;
int n,l,r,a[maxn];
bool check(int x)
{
	for(int i=0;i<n-1;i++)
	{
		bool x1=0,x2=0;
		if(a[n-i]>=x&&a[n-i-1]>=x) x1=true;
		if(a[n+i]>=x&&a[n+i+1]>=x) x1=true;
		if(a[n-i]<x&&a[n-i-1]<x) x2=true;
		if(a[n+i]<x&&a[n+i+1]<x) x2=true;
		if(x1) return true;
		if(x2) return false;
	}
	return a[1]>=x;
}
int BS()
{
	int l=1,r=n*2+1;
	while(l+1<r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) l=mid;
		else r=mid;
	}
	return l;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*2-1;i++) scanf("%d",&a[i]);
	printf("%d\n",BS());
}

Measured memory_bytes: 896
#include "cstring"
#include "iostream"

using namespace std;

int main()
{
	int A, B, C, X, Y,a,b;
	cin >> A >> B >> C >> X >> Y;
	int min,max,money=0;
	int t;
	int moneymin=0;
	if (X > Y)
		max = X;
	else
		max = Y;

	for (t = 0; t < max+1; t++) {
		money = 0;

		money += t * 2 * C;
		if((X-t)>0)
		money += A * (X - t);
		if((Y-t)>0)
		money += B * (Y - t);

		if (t == 0)
			moneymin = money;

		if (money < moneymin)
			moneymin = money;

	}

	cout << moneymin;

	return 0;
}

Measured memory_bytes: 256
object Main extends App {

  Stream.continually(readLine)
    .takeWhile(_ != null)
    .map(_.toInt)
    .map(area(x => x * x))
    .foreach(println)

  def area(f: Long => Long)(d: Int): Long = {
    Range(0, 600, d).map(dd => d * f(dd.toLong)).sum
  }
}



Measured memory_bytes: 44368
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int n;
map<int, int> memo;

int main() {
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        memo[a]++;
        if(memo[a] == 2) memo.erase(a);
    }
    cout << memo.size() << endl;
    
    return 0;
}

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

from operator import mul
from functools import reduce
from collections import Counter

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(readline())
s = ["".join(sorted(list(readline().decode().rstrip()))) for _ in range(n)]

c = Counter(s)

l = [cmb(v,2) for k, v in c.items() if v >=2]
print(sum(l))

Measured memory_bytes: 20000
import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    val C = sc.nextInt()
    val B = IntArray(M){0}
    var ans = 0

    for (i in 0 until M) {
        B[i] = sc.nextInt()
    }

    for (i in 0 until N) {
        var score = C
        for (i in 0 until M) {
            val A = sc.nextInt()
            score += A*B[i]
        }
        if (score > 0) ans++
    }

    println(ans)
}

Measured memory_bytes: 31268
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<unordered_map>
typedef unsigned long long ull;
typedef signed long long sll;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF
#define BIG_PRIME 1000000007

struct Block{
  sll w;
  sll s;
  sll v;
  Block(sll W,sll S,sll V)
  {
    w=W;
    s=S;
    v=V;
  }
  bool operator<(const Block &rhs)const{
    return min(s,rhs.s-w)>min(rhs.s,s-rhs.w);
  }
};

int main()
{
  vector<Block> blocks;
  vector<sll> dp(20001,0);
  sll i,j,N,w,s,v;
  cin >> N;
  for(i=0;i<N;++i)
  {
    cin >> w >> s >> v;
    blocks.push_back(Block(w,s,v));
  }
  sort(blocks.begin(),blocks.end());
  
  for(i=0;i<N;++i)
  {
    for(j=0;j<=blocks[i].s;++j)
    {
      dp[blocks[i].s-j+blocks[i].w]=max(dp[blocks[i].s-j+blocks[i].w],dp[blocks[i].s-j]+blocks[i].v);
    }
  }
  sll value = 0;
  for(i=0;i<=20000;++i)
  {
    value = max(value,dp[i]);
  }
  
  cout << value;

  return 0;
}


Measured memory_bytes: 512
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - XOR Matching
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 17;
const int MBITS = 1 << MAX_M;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

/* subroutines */

/* main */

int main() {
  int m, k;
  scanf("%d%d", &m, &k);
  int mbits = 1 << m;

  if (k >= mbits) puts("-1");
  else if (m == 0) puts("0 0");
  else if (m == 1) {
    if (k == 0) puts("0 0 1 1");
    else puts("-1");
  }
  else {
    for (int i = 0, cont = 0; i < mbits; i++)
      if (i != k) {
	if (cont) putchar(' ');
	printf("%d", i);
	cont = 1;
      }
    printf(" %d", k);

    for (int i = mbits - 1; i >= 0; i--)
      if (i != k)
	printf(" %d", i);
    printf(" %d\n", k);
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pb push_back
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	ll a;
	cin>>a;
	int h=1;
	while(h!=0){
		h=1;
		for(int i=2; i<sqrt(a); i++){
			if(a%i==0){
				h=2;
				break;
			}
		}
		if(h==1){
			cout<<a;
			h=0;
		}
		a++;
	}
}

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

int main() {
    int H,N,A,s=0;
    cin >> H >> N;

    rep(i,N) {
        cin >> A;
        s += A;
    }

    if(s >= H)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();

		if (n % 4 == 0 || n % 7 == 0) {
			System.out.println("Yes");
			return;
		}

		for (int i = 4; i <= 100; i += 4) {
			for (int j = 7; j <= 100; j += 7) {
				if (i + j == n) {
					System.out.println("Yes");
					return;
				}
			}
		}

		System.out.println("No");

	}
}


Measured memory_bytes: 25172
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
const long long MOD = 1000000007;

int H, W, N;
int sr, sc;
std::string S, T;

bool solve() {
    int tmp = sc;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'L') {
            tmp--;
            if (tmp == 0) {
                //std::cout << "check1" << std::endl;
                return false;
            }
        }
        if (T[i] == 'R' && tmp != W) {
            tmp++;
        }
    }

    tmp = sc;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            tmp++;
            if (tmp == W + 1) {
                //std::cout << "check2" << std::endl;
                return false;
            }
        }
        if (T[i] == 'L' && tmp != 1) {
            tmp--;
        }
    }

    tmp = sr;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'U') {
            tmp--;
            if (tmp == 0) {
                //std::cout << "check3" << std::endl;
                return false;
            }
        }
        if (T[i] == 'D' && tmp != H) {
            tmp++;
        }
    }

    tmp = sr;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') {
            tmp++;
            if (tmp == H + 1) {
                //std::cout << "check4" << std::endl;
                return false;
            }
        }
        if (T[i] == 'U' && tmp != 1) {
            tmp--;
        }
    }
    return true;
    
}

int main(int argc, char **argv) {
    std::cin >> H >> W >> N;
    std::cin >> sr >> sc;
    std::cin >> S;
    std::cin >> T;

    if (solve()) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}



Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int a;
  int cnt[9] = {};
  cin >> n;
  int wild = 0;
  
  REP(i,n){
    cin >> a;
    cnt[min(a,3200)/400]++;
  }
  int sm = 0;
  REP(i,8){
      if(cnt[i]){
        sm++;
      }
  }
  cout << max(sm,1) << endl;
  cout << sm+cnt[8] << endl;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e15;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

ll dp[3005][3005];

int main(){
  int n; cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  
  rep(i,n) dp[i][i]=0;
  
  for(int len=1; len<=n; ++len){
    for(int i=0; i+len<=n; i++){
      int j=i+len; // 半開区間[i,j)の右端
      if((n-len)%2==0) dp[i][j]=max(dp[i+1][j]+a[i], dp[i][j-1]+a[j-1]);
      else dp[i][j]=min(dp[i+1][j]-a[i], dp[i][j-1]-a[j-1]);
    }
  }
  cout<<dp[0][n]<<endl;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
 
 
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) cout << 1 << endl;
    else if (a == b || b == c || c == a)  cout << 2 << endl;
    else cout << 3 << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
void swap(int &p, int &q) {
  int hold = p;
  p = q;
  q = hold;
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  swap(A, B);
  swap(A, C);

  cout << A << " " << B << " " << C << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<ll>;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, c = 0, m = 0, p, x;
  cin >> n >> p;
  for (int i = 1; i < n; i++) {
    cin >> x;
    if (x <= p) c++;
    else m = max(m, c), c = 0;
    p = x;
  }
  cout << max(m, c) << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int W,H,x,y,r;
    int temp;
    
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if(x-r<0){
        printf("No\n");
    }else if(x+r>W){
        printf("No\n");
    }else if(y-r<0){
        printf("No\n");
    }else if(y+r>H){
        printf("No\n");
    }else{
        printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 2100
def probC():
    N = input()
    A = list(map(int, input().split()))

    sum_tail = sum(A)

    total = 0
    for idx, i in enumerate(A):
        sum_tail -= A[idx]
        if idx + 1 == len(A):
            break
        total += i * sum_tail
    print(total % (10**9 + 7))


def main():
    probC()


if __name__ == '__main__':
    main()


Measured memory_bytes: 31504
fun main(args: Array<String>) {
    val (s,t) = readLine()!!.split(" ")
    val (a,b) = readLine()!!.split(" ").map { it.toInt() }
    val u = readLine()!!
    println(if (u == s) (a-1).toString() + " " + b else a.toString() + " " + (b - 1))
}

Measured memory_bytes: 37748
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

use num;

fn main() {
    input! {
       a: usize,
       b:Chars,
    }

    let mut c = vec![];
    for i in 0..b.len() {
        if b[i] != '.' {
            c.push(b[i]);
        }
    }
    let c2 = c.joinToString("");
    let c3: usize = c2.parse().unwrap();

    let mut ans = (a * c3) / 100;

    echo!(ans);
}


Measured memory_bytes: 2196
// Frog 1
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define times(t) int t; cin >> t; while(t--)
#define mod 1000000007
#define pb push_back
#define mp make_pair

void solve() {
	int n; cin >> n;
	vector<int> arr(n);
	for(auto &x : arr) cin >> x;
	vector<int> dp(n, 0);
	dp[1] = abs(arr[1] - arr[0]);
	if(n <= 1) cout << dp[n] << endl;
	for(int i=2; i<n; i++) {
		dp[i] = min(abs(arr[i-1]-arr[i])+dp[i-1], abs(arr[i-2]-arr[i])+dp[i-2]);
	}
	// for(auto i : dp) cout << i << ' ';
	// cout << endl;
	cout << dp[n-1] << endl;
	return;
}

int main() {
	IOS;
	// #ifndef ONLINE_JUDGE
	// freopen("C:/Gen code/CompProg/input.txt", "r", stdin);
	// freopen("C:/Gen code/CompProg/output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}

Measured memory_bytes: 3996