akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    // g++ -std=c++11 -o a.o a.cpp
    int n, a, b;
    cin >> n >> a >> b;
    if (a * n > b)
    {
        cout << b << endl;
    }
    else
    {
        cout << a * n << endl;
    }

}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;
vector<int> G[100000];
int dp[100000];

bool check(vector<int>& vec, int m, int B) {
	vector<int> tmp;
	for (int i = 0; i < vec.size(); i++) {
		if (i != m) tmp.push_back(vec[i]);
	}
	int N = tmp.size();
	for (int i = 0; i < N / 2; i++) {
		if (tmp[i] + tmp[N - i - 1] > B) return 0;
	}
	return 1;
}
int solve(int v, int p, int B) {
	if (dp[v] != -1) return dp[v];
	vector<int> child;
	for (int u : G[v]) {
		if (u == p) continue;
		int ret = solve(u, v, B) + 1;
		if (ret > B) {
			return dp[v] = 1 << 30;
		}
		child.push_back(ret);
	}
	if (child.size() == 0) {
		return dp[v] = 0;
	}
	sort(child.begin(), child.end());
	int N = child.size();
	if (N % 2 == 0) {
		bool ok = 1;
		for (int i = 0; i < N / 2; i++) {
			if (child[i] + child[N - i - 1] > B) {
				ok = 0;
				break;
			}
		}
		if (ok) return dp[v] = 0;
		child.pop_back();
		N--;
	}
	int l = -1, r = N - 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(child, m, B)) r = m;
		else l = m;
	}
	if (check(child, r, B)) {
		return dp[v] = child[r];
	}
	return dp[v] = 1 << 30;
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i + 1 < N; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int root = 0;
	int odd = 0;
	for (int i = 0; i < N; i++) {
		if (G[i].size() % 2) {
			odd++;
			root = i;
		}
	}
	int l = -1, r = N;
	while (r - l > 1) {
		int m = (l + r) / 2;
		memset(dp, -1, sizeof(dp));
		solve(root, -1, m);
		if (dp[root] <= m) r = m;
		else l = m;
	}
	cout << odd / 2 << " " << r << endl;
  
  	return 0;
}

Measured memory_bytes: 18560
//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
#define MOD 1000000007ll
using namespace std;
typedef long long ll;



#define MAX 250000




int main() {
	int N, K;
	ll box[MAX];
	box[0] = 0;
	FOR(MAX-1) {
		box[i + 1] = box[i] + (i+1);
	}
	cin >> N >> K;
	ll sum = 0;

	for (int i = K; i <= N; i++) {
		sum += box[N+1] -box[N+1-i]-box[i]+1;
		sum = sum % MOD;
	}
	sum++;
	sum = sum % MOD;
	cout << sum << endl;
}


Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=1e6+6,INF=1e8;
int a[N]; ll s[N];
int main(){
    int n; scanf("%d",&n); rep(i,0,n) scanf("%d",&a[i]);
    if (a[0]){
        if (n==0&&a[0]==1) cout<<1<<endl;
        else cout<<-1<<endl;
        return 0;
    }
    per(i,n,0) s[i]=s[i+1]+a[i];
    ll lst=1,ans=1;
    rep(i,1,n){
        if (a[i]>lst*2){ puts("-1"); return 0; }
        lst=min(lst*2-a[i],s[i+1]); ans+=lst+a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4916
#include<iostream>
#include<vector>
using namespace std;
int main(){
  while(1){ 
 int n,m;
  vector<int> p;
  cin>>n>>m;
  if(n==0)break;
  int k;
  for(int i=1;i<=n;i++)p.push_back(i);
  k=n-1;
  while(p.size()!=1){
    k=(k+m)%p.size();
    p.erase(p.begin()+k);
    k--;
  }
  cout<<p[0]<<endl;
}
  return 0;
}

Measured memory_bytes: 1228
#include<stdio.h>
#define N 100000

int  partition(int *,int,int);

int main(){
  int n,p=0,q,r,i;
  int A[N];

  scanf("%d",&n);
  r = n-1;

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  q = partition(A,p,r);

  for(i=0;i<q;i++){
    printf("%d",A[i]);
    printf(" ");
  }
  printf("[%d]",A[q]);
  printf(" ");
  for(i=q+1;i<=r;i++){
    printf("%d",A[i]);
    if(i < r){
      printf(" ");
    }
  }
  printf("\n");
  
  return 0;
}

int partition(int A[],int p,int r){
  int temp,temp2,i,j,x;
  x = A[r];
  i = p - 1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }

  temp2 = A[i+1];
  A[i+1] = A[r];
  A[r] = temp2;
  return i+1;
}
  



Measured memory_bytes: 2172
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
  int x,ans=999;
  string s;
  cin >> s;
  int N;
  N=s.size();
  for(int i=0;i<=N-3;i++){
    x=100*(s[i]-48)+10*(s[i+1]-48)+(s[i+2]-48);
    ans=min(ans,abs(x-753));
  }
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const ll mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    rep(i,n)std::cin >> a[i];
    std::vector<int> b(a);
    sort(all(a),greater<int>());
    int mm,m;
    m=a[0];mm=a[1];
    rep(i,n){
        if(b[i]!=m){
            std::cout << m << std::endl;
        }
        else{
            if(mm==b[i])std::cout << m << std::endl;
            else std::cout << mm << std::endl;
        }
    }
    
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
  ll n;
  scanf("%lld", &n);

  vector<pair<ll, ll>> pe = prime_factorize(n);

  int oper = 0; // operation回数
  int e;  // 指数
  int curr_e = 1;   // 現在の指数
  for(auto itr = pe.begin(); itr != pe.end(); ++itr) {
    curr_e = 1;
    for(e = itr->second; e >= curr_e; ++curr_e) {
      if (e <= curr_e * 2) {
        ++oper;
        break;
      }
      e -= curr_e;
      ++oper;
    }
  }

  printf("%d\n", oper);
  return 0;
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int> > B(4, vector<int>(13));
  for(int i = 0;i<N;i++){
      char c;
      int a;
      cin >> c >> a;
      if(c == 'S'){
          B[0][a-1]=a;
      }else if(c == 'H'){
          B[1][a-1]=a;
      }else if(c == 'C'){
          B[2][a-1]=a;
      }else if(c == 'D'){
          B[3][a-1]=a;
      }
  }
  for(int i =0;i<4;i++){
    for(int j = 0; j<13;j++){
      if(i == 0){
        if(B[i][j] == 0){
          cout << 'S' << ' ' << j+1 << endl;
        }
      }else if(i == 1){
        if(B[i][j] == 0){
          cout << 'H' << ' ' << j+1 << endl;
        }
      }else if(i == 2){
        if(B[i][j] == 0){
          cout << 'C' << ' ' << j+1 << endl;
        }
      }else if(i == 3){
        if(B[i][j] == 0){
          cout << 'D' << ' ' << j+1 << endl;
        }
      }
    }
  }
}


Measured memory_bytes: 3144
from sys import stdin, stdout	

def sol2():
	H, N = (int(x) for x in stdin.readline().split())
	dp = [float('inf') for _ in range(H+1)]
	dp[0] = 0
	for line in stdin:
		dmg, cost = [int(x) for x in line.split()]
		for i in range(len(dp)):
			new = min(H, i + dmg)
			dp[new] = min(dp[new], dp[i] + cost)
	stdout.write(str(dp[-1]))

if __name__ == "__main__":
	sol2()

Measured memory_bytes: 46556
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long a,b,num,max,fin=0;
    cin >> num >> max;
    set<long long> list;
    for (long long i=0; i<max; i++){
        cin >> a >> b;
        if (b==num) {if (list.count(a)>0) {cout<<"POSSIBLE"; fin++; break;} else{list.insert(a);}}
        if (a==1) {if (list.count(b)>0) {cout<<"POSSIBLE"; fin++; break;} else{list.insert(b);}}}
    if (fin==0) {cout << "IMPOSSIBLE";}}

Measured memory_bytes: 12820
S = input()
A,B,C,D = [S[i] for i in range(4)]
signal = ['+', '-']
flag = False
for op1 in signal:
    for op2 in signal:
        for op3 in signal:
            formula = '{}{}{}{}{}{}{}'.format(A,op1,B,op2,C,op3,D)
            if eval(formula) == 7:
                print(formula+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
    int N;
    int Y;
    cin >> N >> Y;
    int res10000 = -1;
    int res5000 = -1;
    int res1000 = -1;
    
    for(int a = 0; a <= N; ++a){
        for(int b = 0; b <= N; ++b){
            int total = 10000 * a + 5000 * b + 1000 * (N - a - b);
            if(total == Y && (N - a - b) >= 0){
                res10000 = a;
                res5000 = b;
                res1000 = N - a - b;
                cout << res10000 << " " << res5000 << " " << res1000;
                return 0;
            }
        }
    }
    
    cout << res10000 << " " << res5000 << " " << res1000;
    return 0;
}

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

int GreatestCommonDivisor(int x, int y){
    int GCM;
    while (y!=0){
        int x_next = y;
        int y_next = x % y;
        x = x_next;
        y = y_next;
    }
    GCM = x;
    return GCM;
}

int main(){
    int x,y, ans;
    cin >> x >> y ;
    if (x>y) ans = GreatestCommonDivisor(x, y);
    if (y>x) ans = GreatestCommonDivisor(y, x);
    cout << ans << endl;
}


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

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

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll n = s.size();
    map<char,ll> mp;
    for(i = 0;i < n;++i){
        if(!mp.count(s.at(i))) mp[s.at(i)] = 0;
    }
    ll ans = 1e9;
    for(auto x:mp){
        char tmpchar = x.first;
        ll tmpn = n;
        ll tmpans = 0;
        string tmps = s;
        while(true){
            bool flag = true;
            rep(j,tmpn){
                if(tmps.at(j) != tmpchar){
                    flag = false;
                    break;
                }
            }
            if(flag){
                ans = min(ans,tmpans);
                break;
            }
            for(j = 0;j < tmpn-1;++j){
                if(tmps.at(j) == tmpchar || tmps.at(j+1) == tmpchar){
                    tmps.at(j) = tmpchar;
                }
            }
            --tmpn;
            ++tmpans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int t;
  cin>>t;
  
  while(t--){
    ll n,m,a,b;
    cin>>n>>m>>a>>b;
    
    cout<<floor_sum(n,m,a,b)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != s[s.size() - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, i;
    vector<int> a, a_sorted;
    cin >> n;
    for(i=0; i<n; i++){
        int input;
        cin >> input;
        a.push_back(input);
        a_sorted.push_back(input);
    }
    sort(a_sorted.begin(), a_sorted.end());
    for(i=0; i<n; i++){
        if(a[i] != a_sorted.back()){
            cout << a_sorted.back() << '\n';
        }
        else{
            cout << a_sorted.rbegin()[1] << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3436
import java.util.*;
import java.awt.Rectangle;

public class Main{
	private static char[] s;
	private static int pos;
	private static ArrayList<GUI> al;

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

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			al = new ArrayList<GUI>();
			s = sc.next().toCharArray();
			pos = 0;
			parse();

			for(int i=0;i<n;i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				int min = Integer.MAX_VALUE;
				int minIdx = -1;

				for(int j=0;j<al.size();j++){
					if(al.get(j).r.contains(x,y) && al.get(j).child < min){
						min = al.get(j).child;
						minIdx = j;
					}
				}

				System.out.println(minIdx==-1 ? "OUT OF MAIN PANEL 1" : (al.get(minIdx).name + " " + al.get(minIdx).child));
			}
		}
	}

	private static void parse(){
		String name = start();
		int[] v = value();
		int child = 0;
		while(s[pos] == '<' && s[pos+1] != '/'){
			parse();
			child++;
		}
		end();

		GUI gui = new GUI(name,v[0],v[1],v[2],v[3],child);
		al.add(gui);
	}

	private static String start(){
		String res = "";
		pos++;
		while(s[pos] != '>'){
			res += s[pos++];
		}
		pos++;
		return res;
	}

	private static int[] value(){
		String tmp = "";
		while(s[pos] != '<'){
			tmp += s[pos++];
		}
		String[] tt = tmp.split(",");
		int[] res = new int[4];

		for(int i=0;i<4;i++){
			res[i] = Integer.parseInt(tt[i]);
		}
		return res;
	}

	private static void end(){
		while(s[pos++] != '>');
	}
}

class GUI{
	String name;
	Rectangle r;
	int child;

	GUI(String name,int x1,int y1,int x2,int y2,int child){
		this.name = name;
		this.r = new Rectangle(x1,y1,x2-x1,y2-y1);
		this.r.setBounds(x1-1,y1-1,x2-x1+2,y2-y1+2);
		this.child = child;
	}
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
    int h, w;
    cin >> h >> w;
    char s[h+1][w+1];
    int cnt = 0;
    int visited[h+1][w+1];
    int a[] = {1,0,-1,0};
    int b[] = {0,1,0,-1};
    rep(i, h) {
        rep(j, w) {
            cin >> s[i][j];
            if(s[i][j] == '.')
                cnt++;
                visited[i][j] = -1;
        }
    }
queue<pair<int,int>> que;
visited[0][0] = 0;
que.push(make_pair(0,0));
while(!que.empty()){
  pair<int,int> now = que.front();
    //int ny=que.front().first,nx=que.front().second;
    que.pop();
  int ny=now.first,nx=now.second;

    rep(i,4){
        int y = ny+a[i],x = nx + b[i];
        if(y<0 || y>=h || x<0 || x>=w || visited[y][x] != -1) continue;
        if(s[y][x] == '#') continue;
        visited[y][x] = visited[ny][nx] + 1;
        que.push(make_pair(y,x));
    }
}
if(visited[h-1][w-1] == -1) cout<<-1<<endl;
else
cout<<cnt - visited[h-1][w-1] - 1<<endl;
    return 0;
}


Measured memory_bytes: 3576
import Foundation

let N = Int(readLine()!)!
let S = [Character](readLine()!)
var r=0,g=0,b=0,rg=0,gb=0,br=0,rgb=0
for i in 0..<N {
  if S[i] == "R" { r += 1; rg += g; br += b; rgb += gb }
  else if S[i] == "G" { g += 1; rg += r; gb += b; rgb += br }
  else if S[i] == "B" { b += 1; gb += g; br += r; rgb += rg }
}
outerLoop: for i in 0..<N-2 {
  innerLoop: for j in i+1..<N-1 {
    var k = 2 * j - i
    if k >= N { break innerLoop }
    var s = Set<Character>([S[i], S[j], S[k]])
    if s.count == 3 { rgb -= 1 }
  }
}
print(rgb)

Measured memory_bytes: 13404
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        que.push({a, b});
    }

    int ans = 0;
    priority_queue<int> candidate;
    for(int d=1; d<=m; d++){
        auto t = que.top();
        while(que.size() != 0 && t.first <= d){
            candidate.push(t.second);
            que.pop();
            t = que.top();
        }
        if(candidate.size() != 0){
            ans += candidate.top();
            candidate.pop();
        } 
    }

    cout << ans << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }
    else if((6 <= a) && (a <= 12)){
        cout << b/2 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}

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

int main(){
    int sum, N;
    cin >> sum >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());
    int ans = max((A[0] - 1) - (sum - A[0]), 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
s = []
for i in range(n):
    if i == 0:
        s.append(a[0])
    else:
        s.append(a[i]+s[-1])

count = 0
ans1 = 0
for i in range(n):
    if i%2 == 0:
        if s[i]+count > 0:
            continue
        else:
            ans1 += 1-(s[i]+count)
            count += 1-(s[i]+count)
    else:
        if s[i]+count < 0:
            continue
        else:
            ans1 += (s[i]+count) + 1
            count -= (s[i]+count) + 1
            
count1 = 0
ans2 = 0
for i in range(n):
    if i%2 == 1:
        if s[i]+count1 > 0:
            continue
        else:
            ans2 += 1-(s[i]+count1)
            count1 += 1-(s[i]+count1)
    else:
        if s[i]+count1 < 0:
            continue
        else:
            ans2 += (s[i]+count1) + 1
            count1 -= (s[i]+count1) + 1
            
print(min(ans1,ans2))
            

Measured memory_bytes: 63828
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
const int N = 1e+5;
int dp[N];
int n;
int helper(int i,vector<int> & v)
{
	if(i==n)
	{
		return 0;
	}
	if(i==n-1)
	{
		return abs(v[n-1] - v[n]); 
	}

	if(dp[i]!=-1)
	{
		return dp[i];
	}

	return dp[i] =  min(helper(i+1,v)+abs(v[i]-v[i+1]),helper(i+2,v)+abs(v[i]-v[i+2]));

}
int32_t main()
{
	cin>>n;
	memset(dp,-1,sizeof(dp));
	vector<int> v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}

	int ans = helper(1,v);
	cout<<ans<<endl;

	return 0;

}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	char C = getcha();
	int pn = 1;
	if (C == '-') { pn = -1; C = getcha(); }
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return pn * A;
}

int main() {
	int N = getint();
	int fu = 0;
	int saishou = 1e9;
	ll goukei = 0;
	rep(i, N) {
		int A = getint();
		if (A < 0) {
			fu++;
			A = -A;
		}
		goukei += A;
		saishou = min(saishou, A);
	}

	if (fu % 2) {
		goukei -= saishou * 2;
	}

	co(goukei);

	Would you please return 0;
}

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

int main() {
  string S;
  cin >> S;
  int count = 0;
  rep(i, S.size() / 2){
    if (S.at(i) != S.at(S.size() - i - 1)){
      count++;
    }
  }
  cout << count << endl;
}


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

std::vector<int> A;
int n;


int partition(){
    int y;
    y = -1;

    for(int i = 0; i < n-1; i++){
	if(A[i] <= A[n-1]){
	    std::swap(A[i], A[y+1]); 
	    y++;
	}
    }
    std::swap(A[y+1], A[n-1]);

    return y+1;
}

int main(void){
    std::cin >> n;
    A.resize(n);
    for(int i = 0; i < n; i++){
	std::cin >> A[i];
    }

    int base_index = partition();

    for(int i = 0; i < n; i++){
	if(i != 0){
	    std::cout << " ";
	}
	
	if(i == base_index){
	    std::cout << "[" << A[i] << "]";
	}else{
	    std::cout << A[i];
	}
    }
    std::cout << std::endl;

    return 0;

}



Measured memory_bytes: 3116
n = int(raw_input())
a = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())

add_result = [0]*2001
for i in a:
	for j in range(2000, -1, -1):
		if add_result[j] == 1:
			add_result[i+j] = 1
			#print(i, j, i+j)	
	add_result[i] = 1
	#print i

for target in m:
	if add_result[target] == 1:
		print("yes")
	else:
		print("no")

Measured memory_bytes: 6500
#include<stdio.h>

int main(){
  int n,s[100001],q,t,i,left,right,mid,ans = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",s + i);

  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&t);
    left = 0;
    right = n;
    while(left < right){
      mid = ( left + right ) / 2;
      if(s[mid] == t){
	ans++;
	break;
      }
      else if(s[mid] < t) left = mid + 1;
      else right = mid;
    }
  }

  printf("%d\n",ans);
  
  return 0;
}



Measured memory_bytes: 2108
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        static int Comp(Tuple<int, int> t1, Tuple<int, int> t2)
        {
            if (t1.Item2 != t2.Item2)
            {
                return t1.Item2 > t2.Item2 ? 1 : -1;
            }
            else
            {
                return t1.Item1 > t2.Item1 ? 1 : -1;
            }
        }

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            var input = cin.SplitRead();
            int N = input[0];
            int M = input[1];
            List<Tuple<int, int>> ab = new List<Tuple<int, int>>();
            for(var i = 0; i < M; i++)
            {
                var p = cin.SplitRead();
                ab.Add(new Tuple<int, int>(p[0], p[1]));
            }
            ab.Sort(Comp);

            int prev = -1;
            long ans = 0;
            for(var i = 0; i < M; i++)
            {
                if (ab[i].Item1 > prev)
                {
                    ans++;
                    prev = ab[i].Item2 - 1;
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }
        
        
    }
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public long Modulo(long value, long mod)
        {
            long r = value % mod;

            if (r * mod < 0)
            {
                r += mod;
            }
            return r;
        }
    }

    

}


Measured memory_bytes: 23480
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		string b = Console.ReadLine();

		string ans = "0";
		if (b == "A") { ans = "T"; }
		if (b == "T") { ans = "A";}
		if (b == "C") { ans = "G";}
		if (b == "G") { ans = "C"; }
		Console.WriteLine(ans);
	}
	
}




Measured memory_bytes: 13140
q = int(input())

def f(A,B,x):
    return x*B//(x+A) + 1
def F(A,B):
    st = 1
    ed = B-A-1
    gap = B-A
    maxst = 1
    while st<ed:
        bar = (st+ed)//2
        if f(A,B,bar) + bar <=gap:
            maxst = max(maxst,bar)
            st = bar + 1
        else:
            ed = bar - 1
    if f(A,B,st) + st<=gap:
        maxst = max(maxst,st)
    if f(A,B,maxst)+maxst > gap:
        return -1
    return maxst  
def solveAB(A,B):
    res = 0
    res += (A-1)*2
    st = F(A,B)
    #print(st)
    if st == -1:
        if B-A <2:
            return res
        else:
            return res+1
    if f(A,B,st)+st == B-A and (st-1)*2+1 == B-A-1:
        #print("odd and full")
        res += (st-1)*2+1
    elif f(A,B,st)+st < B-A and st*2 == B-A-1:
        #print("even and full")
        res += st*2
    elif f(A,B,st)+st < B-A and st*2 < B-A-1: 
        #print("even not full")
        res += st*2 + 1
    elif f(A,B,st)+st == B-A and (st-1)*2+1 <B-A-1:
        #print("odd not full")
        res += (st-1)*2+1+1
    return res 
     

for _ in range(q):
    a,b = map(int,input().split())
    A = min(a,b)
    B = max(a,b)
    print(solveAB(A,B))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back



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

    int N;
    cin >> N;
    vector<int> P(N), Q(N), v(N);
    rep(i, N) cin>>P[i];
    rep(i, N) cin>>Q[i];
    rep(i, N) v[i]=i+1;

    int p_num, q_num, n=0;
    do{
        if(v==P) p_num=n;
        if(v==Q) q_num=n;
        n++;
    }while(next_permutation(all(v)));

    cout << abs(p_num - q_num) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int a,b,c;
string s;

int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='a')
			a++;
		else if(s[i]=='b')
			b++;
		else 
			c++;
	}
	if(abs(a-b)>=2||abs(b-c)>=2||abs(c-a)>=2){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
package main

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

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	_, s := nextInt(), nextStr()
	left, right := 0, 0
	for _, r := range s {
		switch {
		case r == '(':
			right++
		case r == ')' && right > 0:
			right--
		case r == ')' && right == 0:
			left++
		}
	}
	for i := 0; i < left; i++ {
		fmt.Print("(")
	}
	fmt.Print(s)
	for i := 0; i < right; i++ {
		fmt.Print(")")
	}
	fmt.Println("")
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define int long long
using namespace std;
const int maxn = 200000;
const int oo = 1000000007;
int n;
vector<int> s;
int pre[maxn+1];
int prevNum[maxn+1];
int dp[maxn+1];

int caldp(int x)
{
	if (dp[x]!=-1) return dp[x];
	
	if (x==0)
		dp[x] = 1;
	else
	{
		dp[x] = 0;
		dp[x] = caldp(x-1);
		if (pre[x]!=-1) dp[x]=(dp[x]+caldp(pre[x]))%oo;
	}
	
	return dp[x];
}

main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	cin >> n;
	
	s.push_back(0);
	for (int i=1; i<=n; i++)
	{
		int x;
		cin >> x;
		if (x!=*s.rbegin())
			s.push_back(x);
	}
	
	n=s.size()-1;
	
	memset(prevNum,-1,sizeof(prevNum));
	for (int i=1; i<=n; i++)
	{
		cin >> s[i];
		pre[i]=prevNum[s[i]];
		prevNum[s[i]]=i;
	}
	
	memset(dp,-1,sizeof(dp));
	cout << caldp(n);
	return 0;
}



Measured memory_bytes: 12912
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long ans;
      	long count;
      	ans=count=0;
      	while(n != 0){
          n/=2;
          ans += Math.pow(2, count);
          count++;
        }
      	System.out.println(ans);
	}
}


Measured memory_bytes: 35672
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long long n,k,ans;
	cin>>n>>k;
	n%=k;
	ans=n;
	n=abs(n-k);
	if(n<ans){
		ans=n;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))


n = int(input())
cnt = 0
for a in range(1, n):
    u = (n-1) // a
    cnt += u
print(cnt)

# for c in range(1, n):
#     tar = n-c
#     for a in range(1, int(tar**0.5)+1):
#         if tar % a == 0:
#             b = tar // a
#             if b > 0 and a != b:
#                 cnt += 2
#             elif b > 0:
#                 cnt += 1
#
# print(cnt)




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

#define    ll     long long int

int main( )
{
    int n, i, j, k, mx = -1;
    map<int, int> mp;
    vector<int> v;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        mp[j]++;
        if (mp[j] == 2) {
            v.push_back(j);
            mp[j] = 0;
        }
    }
    sort(v.begin(), v.end());
    k = (int) v.size();
    if (k < 2) {
        cout << "0\n";
    }
    else {
        cout << ( (ll) v[k - 1] * v[k - 2]) << '\n';
    }
    return 0;
}


Measured memory_bytes: 4992
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


signed main(){
  int A,B,C,D;
  string IN;
  cin>>IN;
  int seiriken[4];
  for(int i=0;i<4;i++){
    seiriken[i]=IN[i]-'0';
  }
  int ans=7;
  string result="";
  for(int i=0;i<(1<<3);i++){
    int total=seiriken[0];
    for(int j=0;j<3;j++){
      if(i&(1<<j)){
        total+=seiriken[j+1];
      }else{
        total-=seiriken[j+1];
      }
    }
    if(ans==total){
      result=to_string(seiriken[0]);
      for(int j=0;j<3;j++){
        if(i&(1<<j)){
          result+="+"+to_string(seiriken[j+1]);
        }else{
          result+="-"+to_string(seiriken[j+1]);

        }
      }
      break;
    }
  }
  result+='='+to_string(ans);
  cout<<result;

  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005;
ll a[N],x[N],y[N];
void update1(int l,int r,ll val)//[l,r)
{
  x[l]+=val; x[r]-=val;
}
void update2(int l,int r)//[l,r)
{
  y[l]--; y[r]++;
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,m;
  cin>>n>>m;
  rep(i,1,n+1) cin>>a[i];
  rep(i,1,n)
    {
      if(a[i]<a[i+1])
	{
	  //for x<=a[i] && x>a[i+1]
	  update1(1,a[i]+1,a[i+1]-a[i]);
	  update1(a[i+1]+1,m+1,a[i+1]-a[i]);
	  //for x lies ( a[i],a[i+1] ]
	  update1(a[i]+1,a[i+1]+1,1+a[i+1]);
	  update2(a[i]+1,a[i+1]+1);
	}
      else
	{
	  //for x<=a[i+1]
	  update1(1,a[i+1]+1,1+a[i+1]);
	  update2(1,a[i+1]+1);
	  //for x>a[i+1] && x<=a[i]
	  update1(a[i+1]+1,a[i]+1,a[i+1]-a[i]+m);
	  //for x>a[i]
	  update1(a[i]+1,m+1,1+a[i+1]+m);
	  update2(a[i]+1,m+1);
	}
    }
  rep(i,1,m+1) x[i]+=x[i-1],y[i]+=y[i-1];
  ll ans=LLONG_MAX;
  rep(i,1,m+1) ans=min(ans,x[i]+y[i]*i);
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] points = new int[n][2];
        double sum = 0.0;
        for (int i = 0; i < n; i++) {
            points[i] = new int[] {sc.nextInt(), sc.nextInt()};
            for (int j = 0; j < i; j++)
                sum += Math.sqrt(Math.pow(points[i][0] - points[j][0], 2) + Math.pow(points[i][1] - points[j][1], 2));
        }
        System.out.println(sum * 2 / n);
    }
}


Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int K = in.nextInt();
			String S = in.next();
			for(int i = 0; i < N; i++) {
				if(i == K - 1) {
					if(S.charAt(i) == 'A') {
						out.print('a');
					}if(S.charAt(i) == 'B') {
						out.print('b');
					}if(S.charAt(i) == 'C') {
						out.print('c');
					}
				} else {
					out.print(S.charAt(i));
				}
			}
			out.println("");
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;	

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 21332
module subprogs
  implicit none
  contains
  subroutine bubble_sort(n,L)
    integer,intent(in) :: n
    integer,intent(inout) :: L(n)
    integer :: i,j 
    integer :: t
    do i = 1,n-1
       do j = i + 1,n
          if (L(i) .gt.L(j)) then
             t = L(i)
             L(i) = L(j)
             L(j) = t
!             print*,L
          end if
       end do
     end do
  end subroutine bubble_sort
end module subprogs




program Triangles
  use subprogs
  implicit none 
  integer :: n
  integer,allocatable :: L(:)
  integer :: res
  integer ::i,j,k

  read(*,*)n
  allocate(L(n))
  read(*,*) L
  call bubble_sort(n,L)
!  print*,'L',L
  res = 0
  do i = 1,n-2
     k = i + 2
     do j = i+1,n-1
!           print*,'before loop k', k
           do while((L(k+1) .lt. L(i) + L(j)) .and. (k < n))
              k = k + 1
           end do
           if (L(k) .lt. L(i)+L(j))then
           res = res + k -j
           end if
!           print*,'i,j,k,res',i,j,k,res
           if (j+1 == k)then 
              k = k + 1
           end if
     end do
  end do
           
  write(*,*) res


end program Triangles


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005;
typedef long long ll;
const ll INF=1e15;
ll d[N];
int n,m,T;
ll a[N];
int q[N];
int s,t;
int main()
{
    //freopen("computer.in","r",stdin);
    //freopen("computer.out","w",stdout);
    scanf("%d%d%d",&n,&m,&T);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        d[i]=INF;
    }
    if(n<=1000){
        for(int i=1;i<=n;i++)
            for(int j=0;j<i;j++){
                ll f=max(a[i]-a[j+1],T-(a[i]-a[j+1]));
                d[i]=min(d[i],d[j]+a[i]-a[j]+f+max(a[i]-a[j+1],T-f));
            }
        ll ans=d[n]+m-a[n];
        printf("%lld\n",ans);
    }
    else{
        s=1,t=1;
        ll z=INF;
        for(int i=1;i<=n;i++){
            while(s<=t&&2*(a[i]-a[q[s]+1])>T){
                z=min(z,d[q[s]]-a[q[s]]-2*a[q[s]+1]);
                s++;
            }
            d[i]=min(d[i],a[i]+z+2*a[i]);
            //d[i]=min(d[i],d[q[s]]+a[i]-a[q[s]]+2*(a[i]-a[q[s]+1]));
            d[i]=min(d[i],d[q[s]]+a[i]-a[q[s]]+T);
            while(s<=t&&d[q[s]]-a[q[s]]>=d[i]-a[i])
                t--;
            q[++t]=i;
        }
        ll ans=d[n]+m-a[n];
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int primes[200];
int prime[1000000];
int pr[100000];
int el[314514],wl[314514];
int er[314514],wr[314514];
int a[114514];
int b[214514],c[214514];
int n2[41];
int nis[41]; 
int nia[41];
int mody[41];
signed main(){
	ic(n) ic(x) ic(y)
	int ni=1;
	rep(0,i,41){
		n2[i]=ni;
		ni*=2;
	}
	int nn=n;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	ni=2;
	rep(0,i,41){
		nia[i]=ni;
		ni=(ni*ni)%mod;
	}
	ni=2;
	rep(0,i,41){
		if(nis[i]==1){
			ni=(ni*nia[i])%mod;
		}
	}
	int ans1=ni-1;
	
	int bunsi=1,bunbo=1;
	rep(0,i,x)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,x)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	int ans2=bunsi;	
	
	bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	int ans3=bunsi;
	
	c(((mod+mod+ans1-ans2-ans3))%mod)
}	

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int array[N];
  for (int i=0; i<N; i++) {
    cin >> array[i];
  }
  int max = 0;
  int result = 0;
  for (int j=0; j<N; j++) {
    if (max < array[j]) {
      max = array[j];
    }
    result += array[j];
  }
  cout << result-max/2 << endl;
}

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

using namespace std;

#define MAX 1000000

int p[MAX];

void fanc(void){
	int num = 0;
	for(int ix = 2;ix < MAX;++ix){
		if(p[ix] == 0){
			p[ix] = ++num;
			for(int jx = 2;jx*ix<MAX;++jx)
				p[jx*ix] = -1;
		}else
			p[ix] = num;
	}
}

int main()
{
	int n;
	fanc();
	while(cin >> n)
		cout <<p[n]<<endl;

	return 0;
}

Measured memory_bytes: 5064
local mma = math.max
local n, k = io.read("*n", "*n")
local score_gu, score_cho, score_pa = io.read("*n", "*n", "*n", "*l")
local s = io.read()
-- 1, 2, 3 gu chi pa
local t = {}
for i = 1, #s do
  local tmp = s:sub(i, i)
  if tmp == "r" then
    t[i] = 1
  elseif tmp == "s" then
    t[i] = 2
  else
    t[i] = 3
  end
end
local retscore = 0
for ikrem = 0, k - 1 do
  local prv_g, prv_c, prv_p = 0, 0, 0
  local cur = 1 + ikrem
  while cur <= n do
    local nxt_g, nxt_c, nxt_p = 0, 0, 0
    if t[cur] == 1 then
      nxt_g = mma(prv_c, prv_p)
      nxt_c = mma(prv_g, prv_p)
      nxt_p = score_pa + mma(prv_g, prv_c)
    elseif t[cur] == 2 then
      nxt_g = score_gu + mma(prv_c, prv_p)
      nxt_c = mma(prv_g, prv_p)
      nxt_p = mma(prv_g, prv_c)
    else
        nxt_g = mma(prv_c, prv_p)
        nxt_c = score_cho + mma(prv_g, prv_p)
        nxt_p = mma(prv_g, prv_c)
    end
    prv_g, prv_c, prv_p = nxt_g, nxt_c, nxt_p
    cur = cur + k
  end
  retscore = retscore + mma(prv_g, mma(prv_c, prv_p))
end
print(retscore)


Measured memory_bytes: 1632
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007LL
#define REP(i, n) for(int i=0;i<(n);++i)
typedef long long ll;

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

	int n; char c[2][53];
	cin >> n;
	REP(i, 2) REP(j, n) cin >> c[i][j];
	c[0][n] = c[1][n] = '#';
	bool yoko; ll ans = 1;
	REP(i, n){
		cerr << i << endl;
		if(i == 0 and c[0][i] == c[0][i+1]){
			ans *= 6; yoko = 1; i++;
			continue;
		} else if(i == 0 and c[0][i] != c[0][i+1]){
			ans *= 3; yoko = 0; continue;
		}

		if(c[0][i] == c[0][i+1]) {
			if(yoko) ans *= 3;
			else ans *= 2;
			ans %= MOD;
			yoko = 1;
			i++;
		} else {
			if(!yoko){
				cerr << "ho" << endl;
				ans *= 2; ans %= MOD;
			}
			yoko = 0;
		}
		cerr << "genzai: " << ans << endl;
	}
	cout << ans % MOD << endl;

	return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int plus = a + b;
    int minus = a - b;
    int multi = a * b;
    if(plus >= minus){
        if(plus >= multi){
            cout << plus;
        }else{
            cout << multi;
        }
    }else{
        if(minus >= multi){
            cout << minus;
        }else{
            cout << multi;
        }
    }
    return 0;
}


Measured memory_bytes: 256