akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++)
    {
        int min_dist = 40000000000000;
        int min_indx;
        for (int j = 0; j < m; j++)
        {
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dist < min_dist)
            {
                min_indx = j;
                min_dist = dist;
            }
        }
        cout << min_indx + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

c = Counter(a)
m1=0
m2=0
m3=0
for k,v in c.items():
  if v>1:
    if k>=m1:
      m2=m1
      m1=k
    elif m2<k:
      m2=k
  if v>3 and k>m3:
    m3=k
    
print(max(m1*m2,m3**2))
  


Measured memory_bytes: 22028
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 100100

//head

int n, m;
int a[N];
ll bit1[N], bit2[N];
ll ans;

void add(int i, int x, ll *bit) {
  while(i <= m) {
    bit[i] += x;
    i += i&-i;
  }
}
ll sum(int i, ll *bit) {
  ll res = 0;
  while(i) {
    res += bit[i];
    i &= i-1;
  }
  return res;
}
inline void place(int l, int r, int x) {
  add(l, x, bit1);
  add(r, -x, bit1);
  add(l, -x*(l-1), bit2);
  add(r, x*(l-1), bit2);
}
inline ll get(int i) {
  return sum(i, bit1)*i + sum(i, bit2);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  rep(i, n-1) {
    if(a[i] > a[i+1]) {
      ans += m;
      place(1, a[i+1]+1, 1);
      place(a[i]+1, m+1, 1);
      add(1, m-a[i]-1, bit2);
      add(a[i+1]+1, a[i]+1-m, bit2);
      add(a[i]+1, -1, bit2);
    }
    else {
      place(a[i]+1, a[i+1]+1, 1);
      add(a[i]+1, -1, bit2);
      add(a[i+1]+1, 1, bit2);
    }
    ans += a[i+1]-a[i];
    //rep(i, m) cout << get(i+1) << (i == m-1?'\n':' ');
  }
  ll ma = 0;
  rep(i, m) chmax(ma, get(i+1));
  //rep(i, m) cout << P(i+1, get(i+1)) << endl;
  cout << ans-ma << endl;
}

Measured memory_bytes: 5548
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		for(int i = 0; i < n; ++i)
		{
			int m, e, j;
			cin >> m >> e >> j;
			if((m == 100 || e == 100 || j == 100) || (m + e >= 180) || (m + e + j >= 240))
			{
				cout << "A" << endl;
			}
			else if((m + e + j >= 210) || (m + e + j >= 150 && (e >= 80 || m >= 80)))
			{
				cout << "B" << endl;
			}
			else
			{
				cout << "C" << endl;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d", &a,&b);

    if (a>b) {
      printf("a > b\n");
    } else if (a<b) {
      printf("a < b\n");
    } else if (a=b) {
      printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(){

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=1;
  cin >> N;
  vector<int>num(N);
  
  for ( int i = 0; i < N; ++i)
    cin >> num.at(i);
  
  sort(num.begin(),num.end());
  
  for ( int j = 1; j < N; ++j){
    if (num.at(j) != num.at(j-1))
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

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

// バケット法でユニークな値の数を数える

int main() {
  int N;
  cin >> N;
  
  vector<int> A(110);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  vector<int> d(110);  // 1から100(+余剰)のフラッグを格納するためのダミー配列
  for (int i = 0; i < N; i++) d.at(A.at(i))++;  // dのA[i]番目を0以上にする(フラッグ立て)
  
  int count = 0;
  for (int i = 1; i <= 100; i++) {  // 制約より、値は1から100
    if (d.at(i)) count++;  // 0でない(true)ならカウント
  }
  
  cout << count << endl;
}

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

int main() {
  int n=0;
  cin>>n;
  vector<int> vec;
  rep(i,n){
    int c;
    cin>>c;
    vec.push_back(c);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sum=0;
  rep(i,n){
    if(i%2){
      sum-=vec.at(i);
    } else{
      sum+=vec.at(i);
    }
        
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 764
/*
Author : N_o_o_B
Created : January 14 2020 18:39:15 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n;
    cin >> n;
    map<string,int> m;
    vi a(n);
    fori(i,n){
        string s;int t;
        cin >> s >> a[i];
        m[s] = i;
    }
    string s;
    cin >> s;
    int ind = m[s];
    int ans = 0;
    for(int i=ind+1;i < n;i++){
        ans += a[i];
    }
    cout << ans << endl;

    time_taken();
    return 0;
}

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

using namespace std;

int main()
{
    int a,b,c,d; cin >> a >> b >> c >> d;
    if(abs( a- b) <=d && abs(b -c) <=d)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(abs(a-c) <=d)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        cout << "No" <<endl;
        return 0;
    }
    
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n; cin >> n;


	vector <double> x(n);

	string u;

	double sum = 0;

	for(int i = 0; i < n; i++){
		cin >> x[i] >> u;
		if(u == "BTC"){
			sum += x[i] * 380000;
		}else{
			sum += x[i];
		}
	}

	cout << fixed << setprecision(6);

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=500010;
int ma[maxn],ma2[maxn];
ll a[maxn];
int main()
{
   //freopen("text.in","r",stdin);
    int n,i,j,tmp;
    scanf("%d",&n);
    n=(1<<n);
    for (i=0;i<n;i++) {
        scanf("%lld",&a[i]);
    }
    memset(ma,-1,sizeof(ma));
    ma[0]=0;
    memset(ma2,-1,sizeof(ma2));
    for (i=1;i<n;i++) {
        for (j=0;j<=20;j++) {
            if ((1<<j)&i) {
                tmp=i^(1<<j);
                /*if (i==7) {
                    printf("now==%d %d %d\n",tmp,ma[tmp],ma2[tmp]);
                    printf("tmp==%d ma=%d ma2=%d\n",tmp,ma[i],ma2[i]);
                }*/
                if (a[ma[tmp]]>a[ma[i]]) {
                    ma2[i]=ma[i];
                    ma[i]=ma[tmp];
                    if (ma2[tmp]!=-1) {
                        if (a[ma2[tmp]]>a[ma2[i]]) ma2[i]=ma2[tmp];
                    }
                } else {
                    //printf("t==%d %d\n",ma[tmp],ma2[i]);
                    if (ma[tmp]!=ma[i]&&a[ma[tmp]]>a[ma2[i]]) {
                        ma2[i]=ma[tmp];
                    }else {
                        if (ma2[tmp]!=ma[i]&&a[ma2[tmp]]>a[ma2[i]]) {
                            ma2[i]=ma2[tmp];
                        }
                    }
                }
                /*if (i==7) {
                    printf("2==tmp==%d ma=%d ma2=%d\n",tmp,ma[i],ma2[i]);
                }*/
            }
        }
        if (a[i]>a[ma[i]]) {ma2[i]=ma[i]; ma[i]=i;}
        else {
            if (a[i]>a[ma2[i]]) ma2[i]=i;
        }
    }
    /*for (i=1;i<n;i++) {
        printf("i=%d %d %d\n",i,ma[i],ma2[i]);
    }*/
    ll ans=0;
    for (i=1;i<n;i++) {
        ans=max(a[ma[i]]+a[ma2[i]],ans);
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 10880
//PDF解説に倣って(DFSを諦めてBFS)
#include<bits/stdc++.h>
using namespace std;
int INF=1e9;

int main(){
  int n,m,u,v,s,t;
  cin>> n >> m;
  unordered_set<int> set;
  vector<unordered_set<int>> G(3*n);
  vector<int> D(3*n,INF);
  for (int i=0; i<m; i++){
    cin>> u >> v; u--; v--;
    G[u].insert(v+n);
    G[u+n].insert(v+2*n);
    G[u+2*n].insert(v); 
  }
  cin>> s >> t; s--; t--;
  
  D[s]=0;
  queue<int> Q; Q.push(s);
  while (!Q.empty()){
    u=Q.front(); Q.pop();
    for (auto i: G[u]){
      if (D[i]==INF){
        D[i]=D[u]+1;
        Q.push(i);
      }
    }
    if (u==t) break;
  }
  
  int ans= D[t]==INF ? -1:D[t]/3;
  cout<< ans <<endl;
}

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

using ll = long long;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> p(N+1); // 問題nをWAした回数を格納
  vector<bool> clear_checker(N+1,false); // 問題nをまだクリアしてないかどうか
  
  int ans=0,pena=0;
  int p_n=0; //提出した問題
  string S;

  for(int i=0;i<M;i++){
    cin >> p_n >> S;

    if(S=="AC"){
      if(!clear_checker[p_n]){
        clear_checker[p_n]=true;
        ans++;
        pena += p[p_n];
      }

      else{
        continue;
      }
    }

    else if(S=="WA"){
      p[p_n]++;
    }

  }

  cout << ans << " " << pena << endl;
}

Measured memory_bytes: 640
#include <iostream>
//#include <fstream>
#include <vector>
#include <cmath>

using namespace std;

bool is_integer( double x ){
    return floor(x)==x;
}

float distance(const vector<float>& vi, const vector<float>& vj, int D)
{
    float dist = 0;
    for (int i=0; i<D; ++i)
    {
        dist += pow(vi[i]-vj[i] ,2);
    }
    
    dist = pow(dist, 0.5);
    
    return dist;
}

int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int N, D;
    cin >> N >> D;
    
    vector<float> x(D);
    vector<vector<float>> mx(N);
    
    for (int n=0; n<N; ++n)
    {
        for (int d=0; d<D; ++d)
        {
            cin >> x[d];
        }
        mx[n] = x;
    }
    
    int cnt = 0;
    for (int i=0; i<N-1; ++i)
    {
        for (int j=i+1; j<N; ++j)
        {
            if ( is_integer(distance(mx[i],mx[j], D))) ++cnt;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 888
N,K=map(int,input().split())
mod=10**9+7
fact=[1]*(N+1)
finv=[1]*(N+1)
inv=[1]*(N+1)
inv[0]=0
for i in range(2,N+1):
    fact[i]=(fact[i-1]*i%mod)
    inv[i]=(-inv[mod%i]*(mod//i))%mod
    finv[i]=(finv[i-1]*inv[i])%mod

def com(N,K,mod):
    if (K<0) or (N<K):
        return 0
    return fact[N]*finv[K]*finv[N-K]%mod

for i in range(1,K+1):
    print((com(N-K+1,i,mod)*com(K-1,i-1,mod))%mod)

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> vs(n);
  for(int i = 0; i < n; i++)
  {
	cin >> vs[i];
  }
  sort(vs.begin(), vs.end());

  int minNonzero = -1;
  int sum = 0;
  for(auto v : vs)
  {
	if(v % 10 != 0 && minNonzero == -1)
	{
	  minNonzero = v;
	}
	sum += v;
  }

  if(sum % 10 == 0)
  {
	if(minNonzero == -1)
	{
	  cout << 0 << endl;
	}
	else
	{
	  cout << sum - minNonzero << endl;
	}
  }
  else
  {
	cout << sum << endl;
  }  
}


Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 15:43:19 2019
//
package main

import "fmt"

type train struct {
	c, s, f int
}

func main() {
	var N int
	fmt.Scan(&N)

	trains := make([]train, N-1)
	for i := range trains {
		fmt.Scan(&trains[i].c, &trains[i].s, &trains[i].f)
	}

	for i := 0; i < N; i++ {
		time := 0
		for j := i; j < len(trains); j++ {
			t := trains[j]
			if time > t.s {
				n := ((time - t.s) + t.f - 1) / t.f
				time = t.s + n*t.f
			} else {
				time = t.s
			}
			time += t.c
		}

		fmt.Println(time)
	}
}


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


int main(){
    int a, b;
    int c=0;
    string d;

    cin >> a >> b;

    while(a<=b){
        d = to_string(a);
        if(d[0]==d[4]){
            if(d[1]==d[3]){
                c++;
            }
        }
        a++;
    }

    cout << c << endl;

	return 0;
}


Measured memory_bytes: 384
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'south', 'east',
                               'west', 'north', 'bottom'], face_vals))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['south'], self.faces['bottom'], \
            self.faces['north'] = self.faces['south'], self.faces['bottom'], \
            self.faces['north'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['south'], self.faces['bottom'], \
            self.faces['north'] = self.faces['north'], self.faces['top'], \
            self.faces['south'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['east'], self.faces['bottom'], \
            self.faces['west'] = self.faces['west'], self.faces['top'], \
            self.faces['east'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['east'], self.faces['bottom'], \
            self.faces['west'] = self.faces['east'], self.faces['bottom'], \
            self.faces['west'], self.faces['top']


face_vals = input().split()

dice = Dice(face_vals)

for i in input():
    dice.roll(i)

print(dice.faces['top'])

Measured memory_bytes: 7616
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
//#include <bits/stdc++.h>
#define ll long long
#define wtcl return
using namespace std;

inline int read()
{
	ll s = 0, f = 1;
	char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	return s * f ;
}
int num[100005];
int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)
			num[i] = read();
		int k = -1;
		int ans = 0;
		for(int i=1;i<n;i++)
		{
			if(num[i]==i)
			{
				ans++;
				swap(num[i],num[i+1]);
			}
		}
		if(num[n]==n)
		ans++;
		cout<<ans<<endl;
	}
	wtcl 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String h;
    String d;
    
    if(a.equals("H")){
      if(b.equals("H")){
        b = "H";
      }else{
        b = "D";
      }
    }else{
      if(b.equals("H")){
        b = "D";
      }else{
        b = "H";
      }
    }
    
    System.out.println(b);
    
  }
}

Measured memory_bytes: 35720
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
    int h,w,n,hh=0,ww=0,nn=1,now=0;
    cin>>h>>w>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<vector<int>> ans(h,vector<int>(w));
    rep(i,h*w)
    {
        ans[hh][ww]=nn;
        a[nn-1]--;
        if(now==0)
        {
            if(ww+1==w)
            {
                hh++;
                now++;
            }
            else ww++;
        }
        else
        {
            if(ww==0)
            {
                hh++;
                now--;
            }
            else ww--;
        }
        if(a[nn-1]==0) nn++;
    }
    rep(i,h)
    {
        rep(j,w) cout<<ans[i][j]<<" ";
        cout<<endl;
    }
}

Measured memory_bytes: 3616
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n= scn.nextInt();
		String s = scn.next();
		int[] left=new int[n];
		int[] right=new int[n];
		int e = 0, w = 0;
		for(int i=0;i<n;i++){
			char ch = s.charAt(i);
			left[i]+=w;
			if(ch=='E'){
				e++;
			}else{
				w++;
			}
		}
		w=0;e=0;
		for(int i=n-1;i>=0;i--){
			char ch = s.charAt(i);
			right[i]+=e;
			if(ch=='E'){
				e++;
			}else{
				w++;
			}
		}
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n;i++){
			int sum = left[i] + right[i];
			min = Math.min(sum, min);
		}
		System.out.println(min);	
	}
}

Measured memory_bytes: 29476
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007
#define PI acos(-1)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>

using namespace std;

// clang-format on

main {
  int n, m;
  cin >> n >> m;
  int a[m], b[m], c[m];
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }

  int dp[n];
  loop(i, 1, n) dp[i] = -1000000000000000000LL;
  dp[0] = 0;

  auto f = [&]() -> void {
    rep(i, n) rep(j, m) dp[b[j]] = max(dp[b[j]], c[j] + dp[a[j]]);
  };

  f();
  int p = dp[n - 1];
  f();
  int q = dp[n - 1];

  cout << (p == q ? to_string(p) : "inf") << endl;
  bye;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    using P = pair<int, int>;
    vector<P> x(N);
    vector<int> ans(N * N, -1);
    bool ok = true;
    for (int i = 0; i < N; i++) {
        int y;
        cin >> y;
        x[i]       = { y - 1, i + 1 };
        ans[y - 1] = i + 1;
    }
    sort(x.begin(), x.end());
    for (int i = 0; i < N; i++) {
        int left = x[i].second - 1;
        for (int j = 0; j < x[i].first and left > 0; j++) {
            if (ans[j] == -1) {
                ans[j] = x[i].second;
                left--;
            }
        }
        if (left > 0) {
            ok = false;
            break;
        }
    }
    reverse(x.begin(), x.end());
    for (int i = 0; i < N; i++) {
        int left = N - x[i].second;
        for (int j = N * N - 1; j > x[i].first and left > 0; j--) {
            if (ans[j] == -1) {
                ans[j] = x[i].second;
                left--;
            }
        }
        if (left > 0) {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "Yes" << endl;
        for (int i = 0; i < N * N; i++) {
            if (i != 0) {
                cout << " ";
            }
            cout << ans[i];
        }
        cout << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

ll x;

int main(){
	cin>>x;
	ll tmp=0,i=1;
	while(tmp<x){
		tmp+=i;
		i++;
	}
	cout<<i-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using graph = vector<vector<int>>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    if((b-a)%2==0){
        cout << (b-a)/2 <<"\n";
        return 0;
    }else{
        cout << min(n-b, a-1) + 1 + (b-a-1)/2 <<"\n";
        return 0;
    }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i,n)
    cin >> p[i];
  int count = 0;
  for (int i=1; i < n-1; i++)
  {
    if ((p[i-1] < p[i] && p[i] < p[i+1])
      || (p[i-1] > p[i] && p[i] > p[i+1])) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll h,w,n;
char t[40][40];

int check(){
	int ret=0;
	rep(i,0,h)rep(j,0,w-n+1)if(t[i][j]!='.'){
		int flag=1;
		rep(k,0,n)flag&=(t[i][j]&31)==(t[i][j+k]&31);
		if(flag){
			ret=1;
			rep(k,0,n)t[i][j+k]|=32;
		}
	}
	rep(i,0,h-n+1)rep(j,0,w)if(t[i][j]!='.'){
		int flag=1;
		rep(k,0,n)flag&=(t[i][j]&31)==(t[i+k][j]&31);
		if(flag){
			ret=1;
			rep(k,0,n)t[i+k][j]|=32;
		}
	}
	return ret;
}

void f(){
	do{
		rep(i,0,h)rep(j,0,w)if(t[i][j]&32)t[i][j]=' ';
		rep(j,0,w){
			int cnt=0;
			rep(i,0,h)if(t[i][j]!=' ')t[cnt++][j]=t[i][j];
			rep(i,cnt,h)t[i][j]='.';
		}
	}while(check());
	int flag=1;
	rep(i,0,h)rep(j,0,w)flag&=t[i][j]=='.';
	if(flag){
		puts("YES");
		exit(0);
	}
}

int main(){
	char s[40][40];
	scanf("%lld%lld%lld",&h,&w,&n);
	rep(i,0,h)scanf(" %s",s[h-1-i]);
	rep(i,0,h-1)rep(j,0,w-1){
		if(s[i][j]!=s[i][j+1]){
			memcpy(t,s,1600);
			char c=t[i][j];
			t[i][j]=t[i][j+1];
			t[i][j+1]=c;
			f();
		}
	}
	puts("NO");
}


Measured memory_bytes: 2108
n = int(input())
s = input()
w = []
r = []
for i,j in enumerate(s):
  if j == 'W':
    w.append(i)
  else:
    r.append(i)
if len(w) == 0 or len(r) == 0:
  print(0)
else:
  p = -1
  q = 0
  ans = 0
  mp = len(r)
  mq = len(w)
  while r[p] > w[q]:
    ans += 1
    p -= 1
    q += 1
    if q >= mq or -p > mp:
      break
  print(ans)

Measured memory_bytes: 17316
# include "cmath"
# include "queue"
# include "cstdio"
# include "cstring"
# include "iostream"
# include "algorithm"
# define Maxn 100005
# define fi first
# define se second
# define P pair<int,int>
# define rep(i,x,y) for(int i=x;i<=y;i++)
# define rep_d(i,x,y) for(int i=x;i>=y;i--)
# define rep_t(u) for(int i=head[u];i;i=f[i].next)
using namespace std;
typedef long long ll;
inline int read()
{
	int ok=1,k=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		ok=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		k=k*10+c-'0';
		c=getchar();
	}
	return ok*k;
}
char s[Maxn];
int main()
{
	int n=read();
	scanf("%s",s);
	s[n]='A';
	int ans=0;
	rep(i,1,n)
	{
		if(s[i]!=s[i-1])
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

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

const int MN = 5010;

int N;
pii S[MN];
int L[MN];
ll psum[MN];

bool cmp(pii a, pii b) {
    return a.first + a.second < b.first + b.second;
}

ll cc[MN][MN];
ll dp(int x, int k) {
    if(x == N) return k == 0? 0 : 1e18;
    ll &ret = cc[x][k];
    if(ret != -1) return ret;

    ret = 1e18;
    ret = min(ret, dp(x + 1, k) + S[x].second + 1LL * L[x] * (N - 1 - x - k));
    if(k) ret = min(ret, dp(x + 1, k - 1) + S[x].first + 1LL * L[x] * (k - 1));
    return ret;
}

void setting() {
    for(int i = 0; i < N; i++) {
        L[i] = S[i].first + S[i].second;
        psum[i] = L[i];
        if(i) psum[i] += psum[i - 1];
    }

    memset(cc, -1, sizeof(cc));
}

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

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &S[i].first, &S[i].second);
    }

    sort(S, S + N, cmp);

    ll ans = 1e18;

    setting();

    for(int i = 0; i <= N; i++) {
        ans = min(ans, dp(0, i));
    }

    if(N % 2) {
        pii s = S[0];
        ll x = s.first + s.second;
        for(int i = 1; i < N; i++) S[i - 1] = S[i];
        N--;

        setting();

        ans = min(ans, dp(0, N / 2) + x * N / 2);

        if(N) {
            swap(s, S[0]);
            x = s.first + s.second;

            setting();

            ans = min(ans, dp(0, N / 2) + x * N / 2);
        }
    }

    printf("%lld", ans);
}


Measured memory_bytes: 196608
#include <stdio.h>
#include <stdint.h>

int main(void)
{
    uint32_t A, B, X;
    scanf("%u %u %u", &A, &B, &X);
    if (A <= X && A+B >= X) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}



Measured memory_bytes: 128
# なぜかうまくいかない
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_right, bisect_left

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B, C = MAP()
l = [INT() for i in range(N)]

def dfs(cur, a, b, c):
    if cur == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 5148
#include <stdio.h>

#define MAX 100

int main(void) {
  int i, j, n;
  int minj, tmp, cnt = 0;
  int a[MAX];

  scanf("%d", &n);

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

  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j < n; j++) {
      if(a[j] < a[minj]) {
        minj = j;
      }
    }

    if (i != minj) {
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
      cnt++;
    }
  }

  printf("%d", a[0]);
  for (i = 1; i < n; i++)
    printf(" %d", a[i]);
  printf("\n%d\n", cnt);

  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long tint;

const int INF = 1e6;
const long double PI = acos(-1);
 
int main() {
	int n; cin >> n;
	set<string> u;
	string a; cin >> a;
	char prev = a[a.size()-1];
	u.insert(a);
	forsn(i, 1, n){
		string s; cin >> s;
		if(u.find(s) != u.end() || s[0] != prev){
			cout << "No" << endl;
			return 0;
		}
		u.insert(s);
		prev = s[s.size()-1];
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#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).end()

using namespace std;

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == s[i + 1]) {
      cout << "Bad" << '\n';
      return 0;
    }
  }
  cout << "Good" << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=1,mod=1000000007,a=1;
  cin >> n;
  vector<long> x(n);
  for(long i=0;i<n;i++) cin >> x[i];
  for(long i=0;i<n;i++) {
    while(a!=n) {
      if(x[a-1]>=(a-i)*2-1&&x[a]>=(a-i)*2) a++;
      else break;
    }
    ans=ans*(a-i)%mod;
    a--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4028
a,b,c,d = map(int, input().split())

if b < c or d < a:
    print(0)
elif a <= c and c <= b and b <= d:
    print(b-c)
elif a <= c and d <= b:
    print(d-c)
elif c <= a and b <= d:
    print(b-a)
elif c <= a and a <= d and d <= b:
    print(d-a)


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> t(100002);
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        t[a] += 1;
        t[b+1] -= 1;
    }
    for(int i = 0; i <= n+1; ++i){
        t[i+1] += t[i];
    }
    for(int i = n + 1; i >= 0; --i){
        if(t[i] >= i){
            cout << i << "\n";
            return 0;
        }
    }
    cout << "0\n";
    return 0;
}



Measured memory_bytes: 3356
#include <iostream>
#include <math.h>
using namespace std;


int main(){
	int N;
	cin >> N;
	int array[100];
	for(int i=0;i<N;i++){
		cin >> array[i];
	}
	
	int answer = 10000000;
	for(int i = -100;i <= 100;i++){
		int ans=0;
		for(int j = 0;j < N;j++){
			ans += pow((array[j] - i),2);
		}
		answer = min(answer,ans);
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll k = n % 10;
  if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9)
    cout << "hon" << endl;
  else if(k == 3)
    cout << "bon" << endl;
  else
    cout << "pon" << endl;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]
aa=[0 for i in range(100000+10)]

for i in a:
    aa[i]=1
#print(aa)

d[0]=1
if aa[1] == 0:
    d[1]=1
else:
    d[1]=0
    
if aa[2] == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if aa[i] == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)



Measured memory_bytes: 49500
S=input();N=len(S)+1 # Sの添字: 0 ~ N-2
r=[-1 for i in range(N)];r[0]=0 # rの添字: 0 ~ N-1 , 初期値r[0]を代入
l=[-1 for i in range(N)];l[N-1]=0 # lの添字: 0 ~ N-1, 初期値l[N-1]を代入
for i in range(N-1): # この計算はN-1回行う。添字iは 0 ~ N-2
    if S[i]=='<':
        r[i+1]=r[i]+1
    else:
        r[i+1]=0
for i in range(N-2,-1,-1): # この計算はN-1回行う。添字iは N-2 ~ 0
    if S[i]=='>':
        l[i]=l[i+1]+1
    else:
        l[i]=0

ans=sum([max(r[i],l[i]) for i in range(N)])
print(ans)

Measured memory_bytes: 89580
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
	int n,m,x,item;
	vector<bool> prime(1000001,true);
	prime[0]=prime[1]=false;
	/*ツづ督づゥツつ「*/
	for(int i=2;i<=1000;i++)if(prime[i])for(int j=i+i;j<=1000000;j+=i)prime[j]=0;
	
	while(cin >> n >> x && n && x){
		vector<bool> able(x+1,false);
		able[0]=true;
		
		for(int i=0;i<n;i++){
			cin >> item;
			for(int j=0;j+item<=x;j++){
				able[j+item] = able[j+item] | able[j];
			}
		}
		for(int i=x;i>=0;i--){
			if(able[i] && prime[i]){
				cout << i << endl;
				break;
			}
			if(!i)cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1148
#include <stdio.h>
int main()
{
    int n;
    while (scanf("%d", &n) != EOF) {
        int a, b, c, d;
        int count = 0;
        for (a = 0; a <= 9; a++)
        	for (b = 0; b <= 9; b++)
        		for (c = 0; c <= 9; c++)
        			for (d = 0; d <= 9; d++)
        if (a + b + c + d == n){
        	count++;}
    printf("%d\n", count);
    }
    return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<list>
#include<cmath>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int a, b;
int gcd(int a, int b) {
	int c = a % b;
	if (c == 0)return b;
	return gcd(b, c);
}
int lcm(int a, int b) {
	int g = gcd(a, b);
	return a * b / g;
}
signed main(){
	int a, b;
	cin >> a >> b;
	int ans = lcm(a, b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x = sorted(x)
y = sorted(y)

if(y[0] - x[len(x)-1] >= 1):
    if(x[len(x)-1]-X > 0 and y[0] <= Y):
        print("No War")
    else:
        print("War")
else:
    print("War")

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

using namespace std;

int main(void)
{
    u_int n, m;
    cin >> n >> m;
    u_int coins[n+1];

    for (u_int i = 0; i < n + 1; i++)
        coins[i] = 0;
    
    for (u_int i = 0; i < m; i++) {
        u_int c;
        cin >> c;
        if (c <= n) {
            coins[c] = 1;
            for (u_int j = 1; j + c <= n; j++) {
                if (coins[j] && (!coins[c + j] || coins[c] + coins[j] < coins[c + j]))
                    coins[c + j] = coins[c] + coins[j];
            }
        }
    }

    cout << coins[n] << endl;

    return 0;
}

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

using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int Max_Num=300010;

int main(){
	int N;
	cin >> N;
	LL A[Max_Num];
	rep(i,N) cin >> A[i];
	LL ans=0;
	rep(bit,61){
		int one=0;
		rep(i,N){
			if(1LL<<bit&A[i]) one++;
		}
		LL m=1;
		rep(i,bit){
			m*=2;
			m%=mod;
		}
		ans+=m*one%mod*(N-one);
      	ans%=mod;
	}
	cout << ans << endl;

  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;


int main()
{		
	
    
    IOS
    ll n;
    cin>>n;
    ll a[n],dp[n+1];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }

    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1];
  


}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,t,c,d,i,ans=1000000;
	bool q=false;
	cin>>n>>t;
	for (i=0;i<n;i++){
		cin>>c>>d;
		if (d<=t&&ans>c){
			ans=c;
			q=true;
		}
	}
	if (q==false){
		cout<<"TLE";
	}
	else {
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        if(i){
            if(a[i]>=m){
                m=a[i];
                ans++;
            }
        }
        else{
            ans++;
            m=a[i];
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    char T[98 + 1];
    char H[98 + 1];
    int n,tc,hc,i,j;
 
    scanf("%d",&n);
 
    tc = hc = 0;
 
    for (i = 0; i < n; i++)
    {
        scanf("%98s",T);
        scanf("%98s",H);
 
        j = 0;
 
        while (T[j] != '\0' && H[j] != '\0' && T[j] == H[j]) j++;
 
        if (T[j] == '\0' && H[j] == '\0')
        {
            tc++; hc++;
        }
        else
        {
            if ((T[j] - H[j]) > 0) tc += 3;
            else hc += 3;
        }
    }
 
    printf("%d %d\n",tc,hc);
 
    return 0;
}



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

using namespace std;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if((a-b)>=0){
        cout<<"delicious"<<endl;
    }else if((a-b+x)>=0){
        cout<<"safe"<<endl;
    }else{
        cout<<"dangerous"<<endl;
    }
}

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


// Qの数が多いから累積和を取るべき!!
vector<int> cnt_ac(string s){
    int cnt = 0;
    int size = s.size();

    vector<int> accum(size+1, 0);

    for(int i=0; i<size-1; ++i) {
        if(s[i]=='A' && s[i+1]=='C'){
            accum[i+2] = accum[i+1] + 1;
        }
        else accum[i+2] = accum[i+1];
    }
    return accum;
}


int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<int> accum = cnt_ac(S);

    for(int i=0; i<Q; ++i) {
        int l, r;
        cin >> l >> r;
        cout << accum[r]-accum[l] << endl;
    }

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

int n,arr[N],m;


string s[50];


int dp[50][50];

int dfs(int i,int j)
{
	int ans = 0;
	queue<pair<pi,int>>Q;
	Q.push({{i,j},0});
	int visited[50][50] = {0};

	while(Q.size())
	{
		auto cur = Q.front();
		Q.pop();
		int a = cur.X.X , b = cur.X.Y , d = cur.Y;
		//cout<<a<<" "<<b<<" "<<d;nl;
		if(a>n or b>m or a<1 or b<1)continue;
		if(s[a][b] == '#' or visited[a][b])continue;
		ans = max(ans,d);
		visited[a][b] = 1;
		Q.push({{a+1,b},d+1});
		Q.push({{a,b+1},d+1});
		Q.push({{a,b-1},d+1});
		Q.push({{a-1,b},d+1});
	}	
	return ans;
}

void solve()
{
    cin>>n>>m;
    forn(i,1,n)

    {
    	cin>>s[i];
    	s[i] = "#" + s[i];
	}
//
	//cout<<dfs(3,1);
	//die;
    int ans = 0;
    forn(i,1,n)forn(j,1,m)
    {
    	st(dp,-1);
    	ans = max(ans,dfs(i,j));

    	//cout<<i<<" "<<j<<" "<<dfs(i,j)<<"\n";
    }

    cout<<ans;
    
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

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

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

using namespace std;

int main() {
    int N;
    cin >> N;
    string str = to_string(N);
    int count = 0;
    while(true){
        if(str.size()==1){
            count+=N;
            break;
        }
        if(str.size()%2==1){
            count+=N-pow(10,str.size()-1)+1;
        }
        N=pow(10,str.size()-1)-1;
        str = to_string(N);
    }
    cout << count << endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int lcs(string X, string Y) {
  X = ' ' + X;
  Y = ' ' + Y;
  int memo[1010][1010];
  int maxl = 0;

  // 初期化 境界条件を考える必要がなくなる
  for (int i = 0; i < X.size(); i++) memo[i][0] = 0;
  for (int j = 0; j < Y.size(); j++) memo[0][j] = 0;

  for (int i = 1; i < X.size(); i++) {
    for (int j = 1; j < Y.size(); j++) {
      if (X[i] == Y[j]) {
        //cout << "count up!" << endl;
        memo[i][j] = memo[i-1][j-1] + 1;
      } else {
        memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
      }
      maxl = max(maxl, memo[i][j]);
    }
  }
  return maxl;
}

int main() {
  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    string X, Y; cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
}



Measured memory_bytes: 7100
import sys
def input():
    return sys.stdin.readline().strip()

n, m = map(int, input().split())
l, d = [[] for _ in range(n)], [[] for _ in range(n)]
for _ in range(m):
    i, j, k = map(int, input().split())
    i -= 1
    j -= 1
    l[i].append(j)
    l[j].append(i)
    d[i].append(k)
    d[j].append(-k)

# DFS
seen = ['yet' for _ in range(n)]
todo = []
for i in range(n):
    if seen[i] != 'yet':
        continue
    seen[i] = 0
    todo.append(i)
    while todo != []:
        j = todo.pop(-1)
        for k in range(len(l[j])):
            if seen[l[j][k]] != 'yet':
                if seen[j] + d[j][k] != seen[l[j][k]]:
                    print('No')
                    exit()
                continue
            seen[l[j][k]] = seen[j] + d[j][k]
            todo.append(l[j][k])
print('Yes')

Measured memory_bytes: 56120
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
N_MOVE = 4
EMPTY = 0
ROCK = 1
START = 2
GOAL = 3
 
INF = 100000
 
def in_field(field, x, y):
    return y >=0 and y < len(field) and x >= 0 and x< len(field[0])
 
 
def move_to_rock(field, x, y, direction):
    while(True):
        x += dx[direction]
        y += dy[direction]
        if not in_field(field, x, y):
            return None
        elif field[y][x] == ROCK:
            x -= dx[direction]
            y -= dy[direction]
            break
        elif field[y][x] == GOAL:
            break
    return x, y
 
 
def dfs(depth, field, x, y):
    if depth > 10:
        return None
 
    cost = INF
    for r in range(N_MOVE):
        if cost <= depth:
            return cost
        nx, ny = x + dx[r], y + dy[r]
        if not in_field(field, nx, ny):
            continue
        if field[ny][nx] == ROCK:
            continue
        next_pos = move_to_rock(field, x, y, r)
        if next_pos is None:
            continue
        nx, ny = next_pos
        if field[ny][nx] == GOAL:
            return depth
        rock_pos_x, rock_pos_y = nx+dx[r], ny+dy[r]
        assert field[rock_pos_y][rock_pos_x] == ROCK
        field[rock_pos_y][rock_pos_x] = EMPTY
        result = dfs(depth+1, field, nx, ny)
        if result is not None:
            cost = min(cost, result)
        field[rock_pos_y][rock_pos_x] = ROCK
    return cost
 
 
def find_start_pos(field):
    h = len(field)
    w = len(field[0])
    for y in range(h):
        for x in range(w):
            if field[y][x] == START:
                return x, y
    return None  # ?
 
 
def solve():
    w, h = map(int, input().split())
    if w == 0 or h == 0:
        return None
    field = []
    for y in range(h):
        field.append(list(map(int, input().split())))
    x, y = find_start_pos(field)
    res = dfs(1, field, x, y)
    return res
 
 
if __name__ == '__main__':
    while(True):
        answer = solve()
        if answer is None:
            break
        elif answer == INF:
            print(-1)
        else:
            print(answer)


Measured memory_bytes: 5624