akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,m,a,b,ok,h[1000],ch[1000],LL=1e9;
vector<ll> v1[1000],v2[1000],ans,rans;
int main(void){
    cin.tie(0);
ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--,b--;
        v1[a].push_back(b);
        v2[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        ok=0;
        for(int j=0;j<n;j++)h[j]=0;
        h[i]=1;
        queue<ll> que;
        for(auto x:v2[i]){
            h[x]=1;
            que.push(x);
        }
        while(!que.empty()){
            if(ok)break;
            ll q=que.front();
            //cout<<q<<"Q"<<endl;
            que.pop();
            for(auto x:v2[q]){
                if(x==i){
                    h[x]=1;
                    ok=1;
                    for(auto y:v1[x]){
                        if(y!=q)h[y]=0;
                    }
                    break;
                }
                if(h[x]==0){
                    h[x]=1;
                    que.push(x);
                }
                //else h[q]=0;
            }
        }
        
        if(ok){
            ll cnt=0;
            queue<ll> que;
            ans={};
            for(int j=0;j<n;j++)cnt+=h[j];
            if(cnt>=LL)continue;
            h[i]=0;
            //for(int k=0;k<n;k++)cout<<h[k];
            //cout<<endl;
            ans.push_back(i);
            que.push(i);
            ll good=-1;
            while(!que.empty()){
                ll q=que.front();
                que.pop();
                for(auto x:v1[q]){
                    if(h[x]==1){
                        que.push(x);
                        ans.push_back(x);
                        h[x]=0;
                        
                    }
                    good=x;
                }
            }
            //cout<<i<<ans.size()<<endl;
            if(ans.size()!=cnt&good!=i)continue;
            if(ans.size()<LL){
                rans=ans;
                LL=rans.size();
            }
        }
        
    }
    if(rans.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    cout<<rans.size()<<endl;
    for(auto x:rans){
        cout<<x+1<<endl;
    }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,b[109],a[109],sum=0;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++) scanf("%d",b+i);
	memset(a,0x3f,sizeof(a));
	for(int i=0;i<n-1;i++) {
		a[i]=min(a[i],b[i]);
		a[i+1]=min(a[i+1],b[i]);
	}
	for(int i=0;i<n;i++) sum+=a[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=200005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N,K,A[MAXN];
void solve(){
	int cur=1;
	FOR(i,1,K){
		cur=A[cur];
	}
	cout<<cur;
	exit(0);
}

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>K;
	FOR(i,1,N) cin>>A[i];
	
	if (K<=2*MAXN) solve();
	vector<int> vis;
	int cur=1;
	FOR(i,1,2*MAXN){
		//db(cur);
		cur=A[cur];
		vis.pb(cur);
	}
	
	//for (auto i:vis) cout<<i<<" ";
	
	vector<int> cyc;
	int tail = vis.back();
	vis.pop_back();
	while (vis.back() != tail){
		cyc.pb(vis.back());
		vis.pop_back();
	}
	cyc.pb(tail);
	reverse(all(cyc));
	K-=sz(vis);
	K=K%sz(cyc);
	cout<<cyc[K];
	//for (auto i:cyc) cout<<i<<" ";
}


Measured memory_bytes: 9932
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double eps=0.000000000000000001;
		while(sc.hasNext()){
			double n=sc.nextDouble();
			double m=sc.nextDouble();
			if(n<35.5-eps && m<71.0-eps){
				System.out.println("AAA");
			}
			else if(n<37.5-eps && m<77.0-eps){
				System.out.println("AA");
			}
			else if(n<40.0-eps && m<83.0-eps){
				System.out.println("A");
			}
			else if(n<43.0-eps && m<89.0-eps){
				System.out.println("B");
			}
			else if(n<50.0-eps && m<105.0-eps){
				System.out.println("C");
			}
			else if(n<55.0-eps && m<116.0-eps){
				System.out.println("D");
			}
			else if(n<70.0-eps && m<148.0-eps){
				System.out.println("E");
			}
			else{
				System.out.println("NA");
			}
		}
	}

}

Measured memory_bytes: 12000
gets.to_i.times{
	x1,y1,x2,y2,x3,y3 = gets.split.map(&:to_f)
	a,b,c,d,e,f = 2*(x1-x2), 2*(y1-y2), x1**2+y1**2-x2**2-y2**2, 2*(x1-x3), 2*(y1-y3), x1**2+y1**2-x3**2-y3**2
	x = (b*f-c*e)/(b*d-a*e)
	y = (c*d-a*f)/(b*d-a*e)
	puts "#{sprintf("%.3f %.3f %.3f",x,y,((x-x1)**2+(y-y1)**2)**0.5)}"
}

Measured memory_bytes: 8784
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine(ReadInt() < 1200 ? "ABC" : "ARC");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N, K;
    cin >> N >> K;
    vector<bool> snuke(N, false);

    rep(i,K) {
        int A, d;
        cin >> d;
        rep(j,d) {
            cin >> A;
            snuke[A - 1] = true;
        }
    }

    int count = 0;
    rep(i,N) if (!snuke[i]) count++;

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    int answer = 0;
    REP(i,s.length()){
       if(s[i]=='?')s[i]='D';
    }
    cout << s << endl;
    return 0;
}

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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(s.Replace("2017/", "2018/"));
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define endl "\n"
#define int long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define rep(n) for(int i=0;i<(n);i++)
#define rrep(n) for(int i=(n)-1;i>=0;i--)
#define mem(a,b) memset((a),(b),sizeof (a))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF long long(1e18)
#define MOD 1000000007


void solve(){
    int n;
    cin>>n;
    int a[n][3],dp[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(int i=0;i<3;i++) dp[0][i] = a[0][i];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            dp[i][j] = a[i][j];
            if(j==0) dp[i][j] += max(dp[i-1][1],dp[i-1][2]);
            if(j==1) dp[i][j] += max(dp[i-1][0],dp[i-1][2]);
            if(j==2) dp[i][j] += max(dp[i-1][1],dp[i-1][0]);
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    
}

int32_t main(){
    FAST
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}




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

#define REP(i, n) for(int i = 0; i < n; i++)
#define inf 1000000000
using namespace std;

void show(int n, vector<vector<int>> A)
{
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cout << A[i][j] << " ";
        }
        cout << endl;
    } 
}

int main()
{   
    int n, m;
    cin >> n >> m;

    vector<vector<int>> K(30, vector<int>(30));
    int a, b, c, d;
    string str;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            K[i][j] = inf;
        }
    }

    REP(i, m) {
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);

        K[a][b] = c;
        K[b][a] = d;
    }

    int s, g, V, P;
    scanf("%d,%d,%d,%d", &s, &g, &V, &P);

    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (K[i][j] > K[i][k] + K[k][j])
                    K[i][j] = K[i][k] + K[k][j];
            }
        }
    }

    cout << V - K[s][g] - K[g][s] - P << endl;
}


Measured memory_bytes: 3180
N,M=map(int,input().split())
stu=[list(map(int,input().split()))for i in range(N)]
zahyou=[list(map(int,input().split()))for i in range(M)]
ans=list()
for i in range(N):
    tmp=10**10
    tmp2=0
    for j in range(M):
        dist=abs(stu[i][1]-zahyou[j][1])+abs(stu[i][0]-zahyou[j][0])
        if dist <tmp:
            tmp=dist
            tmp2=j+1
    ans.append(tmp2)        
for i in ans:
    print(i)



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

using namespace std;

int n, d[50], ans = 0;

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> d[i];
	for(int i = 0; i < n - 1; ++i){
		for(int j = i + 1; j < n; ++j){
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
}

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

int main(){
  int x,y;
  set<int> g;
  
  g.insert(4);
  g.insert(6);
  g.insert(9);
  g.insert(11);
  
  cin >> x >> y;
  if(x == 2 || y == 2){
    cout << "No" << endl;
    return 0;
  }
  if(g.find(x) == g.end() && g.find(y) != g.end()){
    cout << "No" << endl;
    return 0;
  }

  if(g.find(y) == g.end() && g.find(x) != g.end()){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef vector <string> vs;

string right(string &text, int n){
	int length = text.size();
	string tmp;
	tmp = text.substr(length-n, n);
	text = text.substr(0, length-n);
	return tmp;
}

long str2lng(string text){
	stringstream ss;
	ss<<text;
	long tmp;
	ss>>tmp;
	return tmp;
}

string lng2str(long n){
	stringstream ss;
	ss<<n;
	string text;
	ss>>text;
	return text;
}

vi longstr2num(string text){
	vi buf;
	while (!text.empty()){
		if (text.size()>=8)
			buf.push_back(str2lng(right(text, 8)));
		else{
			buf.push_back(str2lng(text));
			text="";
		}
	}
	return buf;
}

int main(void){
	int n;
	cin>>n;
	for (int i=0; i<n; i++){
		string s1, s2;
		cin>>s1>>s2;
		vi tmp, tmp1 = longstr2num(s1), tmp2 = longstr2num(s2);
		int size1 = tmp1.size(), size2 = tmp2.size(), size=max(size1, size2);
		long s, c = 0;
		for (int j=0; j<size; j++){
			s = c;
			if (j<size1) s += tmp1[j];
			if (j<size2) s += tmp2[j];
			
			tmp.push_back(s%100000000);
			c = s / 100000000;
		}
		if (c != 0)	tmp.push_back(c);

		stringstream buf;
		for (int j=tmp.size()-1; j>=0; j--)
			if (j != tmp.size()-1)
				buf<<setfill('0')<<setw(8)<<tmp[j];
			else
				buf<<tmp[j];
		string str;
		buf>>str;
		if (str.size()>80) cout<<"overflow"<<endl;
		else cout<<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#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 UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	int mxbit = 0, tmp = n;
	while(tmp > 0) {
		tmp /= 2;
		mxbit++;
	}
	int m = 0;
	vector<pint> edge;
	REP(i, mxbit) {
		bitset<10> bi1(0); bi1[i] = 1;
		REP(j, n) {
			if(j + 1 == bi1.to_ulong()) continue;
			bitset<10> bi2(j + 1);
			if(bi2[i]) {
				edge.pb({(int)bi1.to_ulong(), j + 1});
				m++;
			}
		}
	}
	cout << m << endl;
	REP(i, m) {
		cout << edge[i].first << " " << edge[i].second << endl;
	}
	REP(game, k) {
		bitset<10> ans(0);
		bool ok = false;
		REP(i, mxbit) {
			bitset<10> q(0); q[i] = 1;
			cout << q.to_ulong() << endl;
			string res = "";
			cin >> res;
			if(res == "Yes") {
				ok = true;
				break;
			} else if(res == "Near") {
				ans[i] = 1;
			} else {
				ans[i] = 0;
			}
		}
		if(!ok) {
			cout << ans.to_ulong() << endl;
			string res = "";
			cin >> res;
		}
	}
}
/* --------------------------------------- */



Measured memory_bytes: 3360
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int ans=0;
    int ma=0;
    for(auto x:s)
    {
        if(x=='R')
        {
            ans++;
        }
        else
        {
            ans=0;
        }
        ma=max(ans,ma);
        
    }    
    cout<<ma;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int N, P; cin >> N >> P;
    string s; cin >> s;
    int ans = 0;
    if(P == 2){
        for(int i = N - 1; i >= 0; i--){
            if((s[i] - '0') % 2 == 0) ans += i + 1;
        }
    }
    else if(P == 5){
        for(int i = N - 1; i >= 0; i--){
            if((s[i] - '0') % 5 == 0) ans += i + 1;
        }
    }
    else{
        vector<int> num(P, 0);
        num[0]++;
        int now = s[N - 1] - '0';
        int fac = 1;
        int cur = (now * fac) % P;
        num[cur]++;
        for(int i = N - 2; i >= 0; i--){
            now = s[i] - '0';
            fac = (fac * 10) % P;
            cur += (now * fac);
            cur %= P;
            num[cur]++;
        }
        for(int i = 0; i < P; i++) ans += num[i] * (num[i] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
 
public class Main {
    static final long MOD=1000000007;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] input=new int[n];
        int[] output=new int[n];
        for(int i=0;i<n;i++){
            input[i]=sc.nextInt();
        }
        if(n%2==1){
            output[n/2]=input[0];
            for(int i=1;i<n/2+1;i++){
                output[n/2-i]=input[i*2-1];
                output[n/2+i]=input[i*2];
            }
            for(int i=n;i>0;i--){
                System.out.print(output[i-1]+" ");
            }
        }else{
            output[n/2]=input[0];
            for(int i=1;i<n/2;i++){
                output[n/2-i]=input[i*2-1];
                output[n/2+i]=input[i*2];
            }
            output[0]=input[n-1];
            for(int i=0;i<n;i++){
                System.out.print(output[i]+" ");
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 96996
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
As = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for A in As:
    if sum(a * b for a, b in zip(A, B)) + C > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
a = input();
cnt = 0;
if(a == a[::-1]):
	cnt+=1
n = len(a)
if(a[:(n-1)//2] == a[:(n-1)//2:-1]):
    cnt+=1
if(a[(n+3)//2-1::][::-1] == a[(n+3)//2-1:]):
    cnt+=1
if(cnt == 3):
    print("Yes")
else:
   	print("No")


Measured memory_bytes: 3064
//C - Bugged: 
//Assunto:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int n, ans = 0;
int dp[105][10005];
void solve(int idx, int soma, vector<int> &points) {
    if(idx >= n) {
        if(soma % 10 != 0) ans = max(ans, soma);
        return;
    }
    if(dp[idx][soma] > 0) return;
    solve(idx+1, soma, points);
    solve(idx+1, soma+points[idx], points);
    dp[idx][soma] = 1;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    memset(dp, 0, sizeof(dp));
    cin >> n;
    vector<int> points(n);
    loop(i, 0, n) cin >> points[i];
    solve(0, 0, points);
    cout << ans << "\n";
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#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()
#define rall(a) (a).rbegin,(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	vector<vector<int>> ans(h, vector<int>(w));
	//yoko
	rep(i, h) {
		int res = 0;
		int a = 0;
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == '.') {
				if (res == 0) a = j;
				res++;
			}
			else {
				if (res == 0) continue;
				if (res == 1) {
					res = 0;
					continue;
				}
				for (int k = a; k < j; ++k) {
					ans[i][k] += res - 1;
				}
				res = 0;
			}
		}
		if (res == 1) continue;
		if (res > 0) {
			for (int j = a; j < w; ++j) {
				ans[i][j] += res - 1;
			}
		}
	}
	//tate
	rep(i, w) {
		int res = 0;
		int a = 0;
		for (int j = 0; j < h; ++j) {
			if (s[j][i] == '.') {
				if (res == 0) a = j;
				res++;
			}
			else {
				if (res == 0) continue;
				if (res == 1) {
					res = 0;
					continue;
				}
				for (int k = a; k < j; ++k) {
					ans[k][i] += res - 1;
				}
				res = 0;
			}
		}
		if (res == 1) continue;
		if (res > 0) {
			for (int j = a; j < h; ++j) {
				ans[j][i] += res - 1;
			}
		}
	}
	int j_ans = 0;
	rep(i, h)rep(j, w) j_ans = max(j_ans, ans[i][j]);

	dunk(j_ans + 1);

	return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void reads(string &s){
	char ch=getchar();s="";
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';s+=ch,ch=getchar());
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
void outputno(){
	puts("-1");exit(0);
}
string s;
vector<int>v[26];
int cnt[200004],n;
bool vis[200004];
void upd(int id,int x){
	while (id<=n)
		cnt[id]+=x,id+=(id&-id);
}
int ans(int id){
	int res=0;
	while (id)res+=cnt[id],id-=(id&-id);
	return res;
}
ll res;
int main(){
	reads(s),n=s.size(),s="$"+s;
	for (int i=1;i<=n;i++){
		s[i]-='a';
		v[s[i]].push_back(i); 
	}
	bool ok=0;
	for (int i=0;i<26;i++) if (v[i].size()%2==1){
		if (ok) outputno();
		else ok=1;
	}
	for (int i=1;i<=n;i++) upd(i,1);
	for (int i=1;i<=n;i++){
		if (vis[i]) continue; 
		int a=v[s[i]][v[s[i]].size()-1];
		if (i!=a) res+=ans(n)-ans(a);
		else res+=(ans(n)-ans(a))/2;
		upd(i,-1),upd(a,-1),vis[i]=vis[a]=1,v[s[i]].pop_back();
	}
	write(res);
}

Measured memory_bytes: 2620
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[4005][4005];
char a[4005],b[4005];
int main()
{
	while(scanf("%s",a)!=EOF)
	{

		scanf("%s",b);
		memset(dp,0,sizeof(0));
		
		int aa=strlen(a); int bb=strlen(b);
		int ret=0;
		for(int i=1;i<=aa;i++)
		{
			for(int j=1;j<=bb;j++)
			{
				if(a[i-1]==b[j-1]){dp[i][j]=dp[i-1][j-1]+1;}
				else dp[i][j]=0;
				ret=max(ret,dp[i][j]);
			}
			
		}
		printf("%d\n",ret);
	}
	
}

Measured memory_bytes: 63732
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	m := nextInt()
	ans := 0
	ans += min(n, m/2)
	m -= ans * 2
	ans += m / 4
	fmt.Println(ans)
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

#define __FILE(x)\
	freopen(#x".in" ,"r" ,stdin);\
	freopen(#x".out" ,"w" ,stdout)
const int MX = 200000 + 232;
int read(){
	char k = getchar(); int x = 0;
	while(k < '0' || k > '9') k = getchar();
	while(k >= '0' && k <= '9')
		x = x * 10 + k - '0' ,k = getchar();
	return x;
}

int a[MX] ,b[MX] ,n;

int check(int lim){
	int flg = 1;
	for(int i = 1 ; i < 2 * n ; i += 2){
		flg = flg && a[i] >= lim;
	}
	// 为 10101....10101
	if(flg) return flg;

	if(a[n] >= lim){
		// 一旦有两个连续的就可以传上去
		for(int i = 0 ; i < n ; i += 2){
			if(a[n + i] >= lim && a[n - i] >= lim){
				if(a[n + i + 1] >= lim || a[n - i - 1] >= lim){
					return 1;
				}
			}
			else break;
		}
	}
	if(a[n + 1] >= lim && a[n - 1] >= lim){
		for(int i = 0 ; n + 2 + i < 2 * n ; i += 2){
			if(a[n + 1 + i] >= lim && a[n - 1 - i] >= lim){
				if(a[n + 2 + i] >= lim || a[n - 2 - i] >= lim){
					return 1;
				}
			}
			else break;
		}
	}
	return false;
}

int main(){
	n = read();
	for(int i = 1 ; i < 2 * n ; ++i)
		a[i] = b[i] = read();
	if(n == 1){
		printf("%d\n" ,a[1]);
		return 0;
	}
	std::sort(b + 1 ,b + 2 * n);
	b[0] = -114514 ,b[2 * n] = 2147483647;
	int l = 1 ,r = 2 * n ,mid;
	while(l <= r){
		mid = (l + r) >> 1;
		if(check(b[mid])){
			l = mid + 1;
			//fprintf(stderr ,"%d is ok.\n" ,b[mid]);
		}
		else{
			r = mid - 1;
			//fprintf(stderr ,"%d is not ok.\n" ,b[mid]);
		}
	}printf("%d\n" ,b[l - 1]);
	return 0;
}

Measured memory_bytes: 3160
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

const yes = "Yes"
const no = "No"

func solve(s string) bool {
	if s[0]  == s[1] && s[2] == s[3] && s[0] != s[2] {
		return true
	}
	if s[0]  == s[2] && s[1] == s[3] && s[0] != s[1] {
		return true
	}
	if s[0]  == s[3] && s[1] == s[2] && s[0] != s[1] {
		return true
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	s := next()
	if solve(s) {
		fmt.Fprintln(out, yes)
	} else {
		fmt.Fprintln(out, no)
	}
}

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

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int n;
    int a[4][3][10] = { 0 };

    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) {
        int b, f, r, v;

        scanf("%d %d %d %d\n", &b, &f, &r, &v);
        a[b - 1][f - 1][r - 1] += v;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                printf(" %d", a[i][j][k]);
            }
            printf("\n");
        }
        if (i != 3) {
            printf("####################\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    int n;
    scanf("%d", &n);
    int cnt[200001] = {};
    for(int i = 0; i < n - 1; i++){
        int a;
        scanf("%d", &a);
        cnt[a]++;
    }
    for(int i = 1; i <= n; i++){
        printf("%d\n", cnt[i]);
    }
}

Measured memory_bytes: 4612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[] oranges = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            oranges[i] = sc.nextInt();
        }
        long[] dp = new long[n + 1];
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            long min = Long.MAX_VALUE;
            long max = 0;
            for (int j = 1; j <= m && i - j>= 0; j++) {
                min = Math.min(min, oranges[i - j + 1]);
                max = Math.max(max, oranges[i - j + 1]);
                dp[i] = Math.min(dp[i], (max - min) * j + k + dp[i - j]);
            }
        }
        System.out.println(dp[n]);
    }
}



Measured memory_bytes: 52636
#include<bits/stdc++.h>
using namespace std;
#define int long
const int inf=1e7;
struct dat{
  int at,cost,from;
  dat(){at=cost=from=-1;}
  dat(int a,int b,int c):at(a),cost(b),from(c){}
};
struct edge{
  int a,b,cost;
  edge(){a=b=cost=-1;}
  edge(int x,int y,int z):a(x),b(y),cost(z){}
};
signed main(){
  int n,m;
  cin>>n>>m;
  vector<edge> e(m);
  vector<vector<int>> G(n,vector<int>(n,inf));
  vector<vector<bool>> H(n,vector<bool>(n,false));
  vector<vector<int>> F(n,vector<int>(n,inf));
  for(int i=0;i<m;++i){
    int a,b,c;
    cin>>a>>b>>c;
    --a;--b;
    G[a][b]=G[b][a]=c;
    e.emplace_back(a,b,c);
  }
  auto f=[](dat a,dat b){return a.cost>b.cost;};
  for(int src=0;src<n;++src){
    priority_queue<dat,vector<dat>,decltype(f)> que(f);
    vector<bool> vis(n,false);
    que.push(dat(src,0,-1));
    while(!que.empty()){
      dat q=que.top();que.pop();
      if(vis[q.at])continue;
      vis[q.at]=true;
      F[src][q.at]=F[q.at][src]=min(q.cost,F[src][q.at]);
      if(q.from!=-1){
        cerr<<q.from<<" --"<<G[q.from][q.at]<<"-> "<<q.at<<" ("<<src<<"->"<<q.at<<":"<<q.cost<<")\n";
        H[q.at][q.from]=H[q.from][q.at]=true;
      }
      for(int i=0;i<n;++i){
        if(vis[i])continue;
        if(G[q.at][i]<inf)que.push(dat(i,G[q.at][i]+q.cost,q.at));
      }
    }
  }
  int r=0,rr=0;
  for(int i=0;i<n-1;++i)for(int j=i+1;j<n;++j)if(H[i][j])++r;
  else if(G[i][j]<inf) cerr<<"["<<i<<" - "<<j<<"]\n";
  for(int i=0;i<n-1;++i)for(int j=i+1;j<n;++j)if(G[i][j]<inf&&F[i][j]<G[i][j])++rr;
  cerr<<"rr:"<<rr<<endl;
  cout<<m-r;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define crap ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846264338327950288419716939937510
#define pb(a) push_back(a)
#define pf(a) push_front(a)

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	crap;
	string s1,s2;
	cin >> s1 >> s2;
	ll count = 0;
	ll i,j,k ;
	f(i,0,s1.size())
		if(s1[i]!=s2[i])
			count++;
	cout << count endl ;
	return 0;
}

Measured memory_bytes: 3796
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;

inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}

vector<int> dividers(int n, bool sorted = true) {
	auto divs = vector<int>();
	int root = sqrt(n);
	for (size_t i = 1; i <= root; i++) {
		if (n%i == 0) {
			divs.push_back(i);
			//平方数対策.
			if (n / i != i)divs.push_back(n / i);
		}
	}
	if (sorted)sort(divs.begin(), divs.end());
	return divs;
}

int count_bits(int a,int b) {
	auto res = a & b;
	auto count= 0;
	for (size_t i = 0; i < 32; i++) {
		if ((res >> i) % 2 == 1)++count;
	}
	return count;
}

int main() {
	int N; cin >> N;
	auto table = vector<int>(N);
	auto gain = vector<array<int, 11>>(N);
	int state;
	for (size_t i = 0; i < N; i++) {
		for (size_t j = 0; j < 10; j++) {
			cin >> state;
			table[i] = table[i] * 2 + state;
		}
	}
	for (size_t i = 0; i < N; i++) {
		for (size_t j = 0; j < 11; j++) {
			cin >> gain[i][j];
		}
	}
	long long answer;
	long long sum = 0;	for (size_t j = 0; j < N; j++) sum += gain[j][count_bits(1, table[j])];
	answer = sum;
	for (size_t joshino = 2; joshino <= 0b1111111111; joshino++) {
		sum = 0;
		for (size_t j = 0; j < N; j++) sum += gain[j][count_bits(joshino, table[j])];
		answer = max(answer, sum);
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
int main()
{
    IOS
    int n; cin>>n;
    int count = 0;
    if(n%2 == 0)
    {
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(i+j == (n+1)) continue;
              //  cout<<i<<" "<<j<<endl;
                count++;
            }
        }
    }
    else{
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(i+j == (n)) continue;
             //   cout<<i<<" "<<j<<endl;
                count++;
            }
        }
    }
    cout<<count<<endl;
    if(n%2 == 0)
    {
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(i+j == (n+1)) continue;
                cout<<i<<" "<<j<<endl;
            //    count++;
            }
        }
    }
    else{
        for(int i=1;i<n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(i+j == (n)) continue;
                cout<<i<<" "<<j<<endl;
           //     count++;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
def solve(a, op, b):
    if op == '+':
        return a + b
    elif op == '-':
        return a - b
    elif op == '*':
        return a * b
    elif op == '/':
        return a // b
    return None
 
if __name__ == '__main__':
    while True:
        a, op, b = input().split()
        if op == '?': break
        print(solve(int(a), op, int(b)))

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

constexpr int MAXN = 1e5 + 1;
int days[MAXN][3];
int happiness[MAXN][3];
// happiness[i][j]: happiness in first i days, not choosing j on the ith day

int main(void)
{
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> days[i][0] >> days[i][1] >> days[i][2];

  for (int i = 0; i < N; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++)
        if (j != k)
          happiness[i + 1][j] =
              max(happiness[i + 1][j], happiness[i][k] + days[i][k]);

  int ans = max({happiness[N][0], happiness[N][1], happiness[N][2]});
  cout << ans << "\n";
}

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

#define MAX 50

using namespace std;

int m_fibo(int n){
    static int ans[MAX];
    if(n == 0 || n == 1) ans[n] = 1;
    if(ans[n] > 0) return ans[n];
    return ans[n] = m_fibo(n-1)+m_fibo(n-2);
}

int main(){
    int n; cin >> n;
    cout << m_fibo(n) << endl;
}



Measured memory_bytes: 3080
import scala.collection.immutable.Queue
import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, Q = sc.nextInt()

    // 操作jのたびに, その頂点自体にカウントを足しておいて, 最後に頂点から辿る時に, カウントを全て合算すればいい
    val G = Array.fill(N+1)(new ArrayBuffer[Int]())
    for (_ <- 0 until (N - 1)) {
      val a, b = sc.nextInt()
      G(a).append(b)
      G(b).append(a)
    }
    val P = Array.fill(Q, 2)(sc.nextInt())
    val C = new Array[Int](N+1)
    P.foreach { case Array(p, x) => C(p) += x }

    def solve(V: Int, G: Array[ArrayBuffer[Int]], C: Array[Int]): Array[Int] = {
      val visit = new Array[Boolean](V+1)
      def bfs(queue: Queue[Int]): Unit =
        if (queue.nonEmpty) {
          val u = queue.head
          val vertexes = G(u).filter(v => !visit(v))
          vertexes.foreach(v => {
            visit(u) = true
            C(v) += C(u)
          })
          bfs(vertexes.foldLeft(queue.tail)((queue, v) => queue.enqueue(v)))
        }
      bfs(Queue(1))
      C
    }

    val r = solve(N, G, C).tail.mkString(" ")
    println(r)
  }

}


Measured memory_bytes: 124764
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


Measured memory_bytes: 2604
/*** keep hungry and calm CoolGuang!***/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<iostream>
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pp;
const ll INF=1e16;
const int maxn=2e6+6;
const int mod=1000000007;
const double eps=1e-3;
inline bool read(ll &num)
{char in;bool IsN=false;
in=getchar();if(in==EOF) return false;while(in!='-'&&(in<'0'||in>'9')) in=getchar();if(in=='-'){ IsN=true;num=0;}else num=in-'0';while(in=getchar(),in>='0'&&in<='9'){num*=10,num+=in-'0';}if(IsN) num=-num;return true;}
ll n,m,p;
struct dsu{int pre[maxn];void inint(){for(int i=1;i<=n;i++) pre[i]=i;}int Find(int x){return x==pre[x]?x:pre[x]=Find(pre[x]);}void Merge(int x,int y){int dx=Find(x),dy=Find(y);if(dx!=dy) pre[dx]=dy;}};
ll num[maxn];
int a[maxn];
int main()
{
    scanf("%d%d%d",&a[1],&a[2],&a[3]);
    swap(a[1],a[2]);
    swap(a[1],a[3]);
    for(int i=1;i<=3;i++) printf("%d ",a[i]);
    return 0;
}
/***
6
0 0 0 0 0 0
0 2 3 1
0 3 4 1
0 1 5 1
1 0 1 0
1 0 2 0
1 0 4 0
***/


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(true) {
            if(n <= 1000) {
                System.out.println(1000 - n);
                return;
            } else {
                n -= 1000;
            }
        }
    }
}

Measured memory_bytes: 35844
//测试......
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[10005],b[10005];
ll sum1,sum2;
ll delta,qwq;
int main() {
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i],sum1+=a[i];
	for(int i=1; i<=n; i++) cin>>b[i],sum2+=b[i];
	if(sum1>sum2) {
		cout<<"No";
		return 0;
	}
	delta=sum2-sum1;
	for(int i=1; i<=n; i++)
		if(b[i]>a[i])
			qwq+=(b[i]+1-a[i])/2;
	if(qwq>delta) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[9] = { 400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 10000 };
int b[9];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        int j = 0;
        while (x >= a[j])
            ++j;
        b[j]++;
    }
    int sol = 0;
    for (int i = 0; i < 8; ++i)
        if (b[i])
            sol++;
    cout << max(1, sol) << ' ' << sol + b[8];
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

dp = [10**9]*N
dp[0] = 0
dp[1] = abs(h[1]-h[0])

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

print(dp[N-1])

Measured memory_bytes: 13908
# include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,m,v=0;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		v=v+a[i];
	}
	if(v>n)cout<<"-1";
	else cout<<n-v;
}

Measured memory_bytes: 3672
#include<stdio.h>
#include<stdlib.h>

#define S 100000
#define MSIZE 100

typedef struct LINK{
	int *friend;
	int i;	//number of friends.
	int group;
}Link;

Link l[S];
int d[S];
int queue[S];
int n;

void makeGroup(int s){
	int i,j,k,f;
	int qs=0, qe=0;
	queue[qe++] = s;
	while( qs < qe ){
		k = queue[qs++];
		for( i = 0; i < l[k].i; i++ ){
			f = l[k].friend[i];
			if( l[f].group == -1 ){
				queue[qe++] = f;
				l[f].group = l[k].group;
			}
		}
	}
	return;
}

void init(){
	int m, i, j;
	int x, y;
	scanf("%d %d", &n, &m);
	for( i = 0; i < n; i++ ){
		l[i].friend = (int*)malloc(MSIZE*sizeof(int));
		l[i].group = -1;
	}
	for( i = 0; i < m; i++ ){
		scanf("%d %d", &x, &y);
		if( l[x].i > 0 && l[x].i % MSIZE == 0 ){
			l[x].friend = (int*)realloc(l[x].friend, (l[x].i+MSIZE)*sizeof(int));
		}
		if( l[y].i > 0 && l[y].i % MSIZE == 0 ){
			l[y].friend = (int*)realloc(l[y].friend, (l[y].i+MSIZE)*sizeof(int));
		}
		l[x].friend[l[x].i] = y;
		l[y].friend[l[y].i] = x;
		l[x].i++;
		l[y].i++;
	}
	//make group.
	int temp = 0;
	for( i = 0; i < n; i++ ){
		if( l[i].group != -1 ){ continue; }
		l[i].group = temp++;
		makeGroup(i);
	}
	return;
}

void isFriend(){
	int s, t;
	scanf("%d %d", &s, &t);
	printf("%s\n", (l[s].group==l[t].group?"yes":"no"));
	return;
}

int main(){
	int i, q;
	init();
	scanf("%d", &q);
	for( i = 0; i < q; i++ ){ isFriend(); }
	return 0;
}

Measured memory_bytes: 43164
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

c=Counter(a)

q=0
for v in c.values():
  if v>=2:
    q+=v-1

ans=len(c.keys())
if q%2==0:
  print(ans)
else:
  print(ans-1)

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

int main(){
  int m,d;
  int res = 0;
  cin >> m >> d;
  if (d < 22){
    res = 0;
  }else{
    int a = d % 10;
    int b = d / 10;
    for (int i = 2; i <= b; i++){
      if (i == b){
        for (int j = 2; j <= a; j++){
          if (i*j <= m){
            res += 1;
          }
        }
      }else{
        for (int j = 2; j <= 9; j++){
          if (i*j <= m){
            res += 1;
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b; cin >> a >> b;
    if(a<= 5) dunk(0);
    else if (a <= 12) dunk(b/2);
    else dunk(b);
}

Measured memory_bytes: 256
import sys
from pprint import pprint

k, s = map(int, sys.stdin.readline().strip().split(" "))

ans = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            ans += 1
            # print(x, y, s - x - y)
print(ans)

Measured memory_bytes: 40940
#include<bits/stdc++.h>
using namespace std;
int a[222];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<2*n;i++)
		cin>>a[i];
	sort(a,a+2*n);
	int ans=0;
	for(int i=0;i<2*n;i+=2)
		ans+=a[i];
	cout<<ans<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n, b[101], sum = 0;
    cin >> n;
    b[0] = b[n] = INF;
    for (int i = 1; i < n; ++i) {
        cin >> b[i];
    }
    for (int i = 1; i <= n; ++i) {
        sum += min(b[i - 1], b[i]);
    }
    cout << sum << endl;

    return 0;
}

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

long long a[100000];

int main()
{
	int n;
	scanf("%ld",&n);
	a[0]=2; a[1]=1;
	for(int i = 2; i <= n; i++){
		a[i]=a[i-1]+a[i-2];
	}
	printf("%lld",a[n]);
}


Measured memory_bytes: 128
//package Practice_Problems;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		int arr[]=fs.readArray(n);
		fs.sort(arr);
		System.out.println((arr[n/2]-arr[n/2-1]));
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st  = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 47524
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[110000], res;
string str;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 1; i < n; i++) {
        if (a[i] - a[i - 1] < 0) {
            str.push_back('b');
        } if (a[i] - a[i - 1] > 0) {
            str.push_back('a');
        }
    }
    for (ll i = 1; i < str.length(); i++) {
        if (str[i - 1] != str[i]) {
            res++, i++;
        }
    }
    cout << res + 1 << endl;
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;


public class Main {
    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        
        String[] InputNum = br.readLine().split(" ");
        int moneyAmount = Integer.parseInt(InputNum[0]);
        int moneyPrice = Integer.parseInt(InputNum[1]);
        
        br.close();
        
        for(int i = 0; i <= moneyAmount; i ++){
            for(int x = 0; x <= moneyAmount - i; x ++){
                if((moneyPrice -(i*10000 + x*5000))/1000 == (moneyAmount-(i + x))){
                    writer.println(i + " " + x + " " + (moneyAmount - (i + x)));
                    writer.close();
                    return;
                }
            }
        }
        writer.println("-1 -1 -1");
        
        writer.close();
    }
}

Measured memory_bytes: 22996
b1,b2,b3=0,0,0
check=0
for i in range(3):
    c1,c2,c3=map(int,input().split())
    if i==0:
        b1,b2,b3=c1,c2,c3
    if i==1:
        if not((c1-b1)==(c2-b2)==(c3-b3)):
            check=1
    if i==2:
        if not((c1-b1)==(c2-b2)==(c3-b3)):
            check=1
print("Yes" if check==0 else "No")

Measured memory_bytes: 3192