akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 0) {
            System.out.println(0);
            return;
        }

        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }


        int[][] dp = new int[n+1][3];
        int ax = 0, bx = 1, cx = 2;

        for (int i = 1; i <= n; i++) {
            dp[i][ax] = a[i-1] + Math.max(dp[i - 1][bx], dp[i - 1][cx]);
            dp[i][bx] = b[i-1] + Math.max(dp[i - 1][ax], dp[i - 1][cx]);
            dp[i][cx] = c[i-1] + Math.max(dp[i - 1][ax], dp[i - 1][bx]);
        }

        int max = Math.max(dp[n][ax], dp[n][bx]);
        max = Math.max(max, dp[n][cx]);
        System.out.println(max);
    }
}



Measured memory_bytes: 95264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <sstream>
#include <utility>
#include <stack>
#include <queue>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
using ll = long long;

const int MOD = 1000000007;

template <class T>
T GCD(T a, T b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

template <class T>
T LCM(T a, T b)
{
    return (a * b) / GCD(a, b);
}

void ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

////////////////////////////////////////////////////////////////////

int main(){
    int n;
    int profit = 0;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    vector<int> c(n);
    rep(i, n) cin >> c[i];
    vector<int> ni(n);
    rep(i, n) {
        ni[i] = v[i] - c[i];
        if (ni[i] > 0) {
            profit += ni[i];
        }
    }
    cout << profit << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
 
typedef long long ll;
 
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }
 
template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// dp[i][j][k] 上からi桁目、まで見て0でない桁がj個ある。k=0のときNより大きくなる可能性があり、k=1のときはNより小さいことが確定している。
ll dp[102][5][2];

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

  string s; 
  cin >> s;
  int k;
  cin >> k;

  int n = s.size();
  dp[0][0][0] = 1; 
  repr(i, n+1, 1) rep(j, k+1) rep(l, 2) {
    for (int d = 0; d < 10; ++d) {
      if (l == 0 && d > s[i-1] - '0') {
        continue;
      } 

      dp[i][j + (d > 0)][l | (d < s[i-1] - '0')] += dp[i-1][j][l];
    }
  }

  cout << dp[n][k][0] + dp[n][k][1] << endl;
}

Measured memory_bytes: 256
N = int(input())
M = N*(N-1)//2-N//2
print(M)
if N%2 ==0:
  rem = N+1
else:
  rem = N
#print(rem)
for i in range(N):
  i +=1 #1index
  for j in range(i,N):
    j +=1 #1index
    temp = [i,j]
    if i+j != rem:
      print(*temp)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

void upd(ll i, ll n, ll ft[], ll val)
{
    if(i<0)
        return;
    if(i>=n)
        return;
    i++;
    while(i<=n)
    {
        ft[i]+=val;
        i+=(i&(-i));
    }
}

ll sum(ll i, ll ft[])
{
    if(i<0)
        return 0;
    i++;
    ll ans = 0;
    while(i>0)
    {
        ans+=ft[i];
        i-=(i&(-i));
    }
    return ans;
}

int main()
{
   FAST/**/
  
   srand(time(0));
   
   ll n,k;
   cin>>n>>k;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   
   ll ft[2*n+5];
   memset(ft,0,sizeof(ft));
   
   rep(n)
   {
       ll l = i+1-arr[i];
       ll r = i+1+arr[i]+1;
       upd(max(l,0ll),2*n+4,ft,1);
       upd(r,2*n+4,ft,-1);
   }
   
   while(k--)
   {
       ll arr1[n];
       rep(n)
            arr1[i] = sum(i+1,ft);
       
       memset(ft,0,sizeof(ft));
   
       rep(n)
       {
           ll l = i+1-arr1[i];
           ll r = i+1+arr1[i]+1;
           upd(max(l,0ll),2*n+4,ft,1);
           upd(r,2*n+4,ft,-1);
       }   
       bool pos = 0;
       rep(n)
            if(arr1[i]!=arr[i])
                pos = 1;
       if(!pos)
            break;
       rep(n)
            arr[i] = arr1[i];
      //cout<<"hehe\n";
   }
   rep(n)
        cout<<arr[i]<<" ";
   
   return 0;        
}  
  
   

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

int main(){
	ios::sync_with_stdio(false);
	int N; cin>>N;
	vector<int> B(N-1),A(N);
	rep(i,N-1) cin>>B[i];

	for(int i=0; i<N; i++){
		int a=1e9,b=1e9;
		if(i-1>=0) a=B[i-1];
		if(i<N-1) b=B[i];
		A[i] = min(a,b); 
	}

	int sum=0;
	for(int x:A){
		// cerr << x << " ";
		sum += x;
	}
	cout << sum << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int r, g;
	cin >> r >> g;
	int ans = g * 2 - r;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e3+6;
const int mod = 1e9+7;
const ll inf = 1e18;
int a[N];
void solve(){
    string s;
    cin>>s;
    for(auto x:s){
        if(x==',')cout<<" ";
        else cout<<x;
    }
    cout<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int x;
	cin>>x;
	if(x>=30)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	
	
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x.at(i) >> y.at(i);
    }
    
    map<pair<int, int>, int> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i == j) continue;

            m[pair<int, int>(x.at(i) - x.at(j), y.at(i) - y.at(j))]++;
        }
    }
    
    int maximum = 0;
    for (auto i = m.begin(); i != m.end(); i++) maximum = max(maximum, i -> second);
 
    cout << n - maximum << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	rep(i, n + 1) {
		if (i == 0)continue;
		if (i % 3 == 0) {
			cout << " " << i;
		}
		else {
			int x = i;
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; 
    ll a;
    cin >> n >> m;

    priority_queue<ll> que;
    for(int i=0;i<n;++i){
        cin >> a;
        que.push(a);
    }

    for(int i=0;i<m;++i){
        a = que.top();
        que.pop();
        que.push(a/2);
    }

    ll ans = 0;
    while(!que.empty()) {
        ans += que.top(); que.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf1 INT_MAX
#define inf2 LLONG_MAX
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sbit __builtin_popcount
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define rit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define fill(a,b) memset(a,b,sizeof(a))
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define infile ifstream fin; fin.open("input.txt")
#define outfile ofstream fout; fout.open("output.txt")
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<ll,int>
#define pll pair<ll,ll>
#define p_queue priority_queue< plii,vector< plii >,greater< plii > > 
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%lld",&x)
#define sst(x) scanf("%s",x)
#define pl(x) printf("%lld\n",x)
#define pi(x) printf("%d\n",x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
ll dp[105][10005][2];
string s; int d;

inline ll binex(ll a,ll b)
{
    ll ans=1,temp=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b=b>>1;
    }
    return ans;
}

inline ll solve(int idx,int mod1,int flag)
{
    if(dp[mod1][idx][flag]!=-1) return dp[mod1][idx][flag];
    if(idx==sz(s)){
        if(mod1==0) return 1;
        else return 0;
    }
    ll temp=0;
    if(flag==1){
        rep(i,0,s[idx]-'0') temp+=solve(idx+1,(((mod1-i+5*d)%d)+d)%d,0);
        temp+=solve(idx+1,(((mod1-(s[idx]-'0')+d)%d)+d)%d,1);
    }
    
    else{
        rep(i,0,10) temp+=solve(idx+1,(((mod1-i+d)%d)+d)%d,0);
    }
        //cerr<<idx<<" "<<mod1<<" "<<flag<<" "<<temp<<endl;
    return dp[mod1][idx][flag]=temp%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s>>d;
    fill(dp,-1); cout<<(solve(0,0,1)-1+mod)%mod<<endl;
}

Measured memory_bytes: 20864
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let (W, a, b): (i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if b >= a + W {
        b - (a + W)
    } else if b + W >= a {
        0
    } else {
        a - (b + W)
    };

    println!("{}", ans);
}


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

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=9;++i){
        for(int j=i;j<=9;++j){
            if(n==i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# ABC165 C
from itertools import combinations as com

N,M,Q=map(int,input().split())
query=[tuple(map(int,input().split())) for _ in [0]*Q]

res=0
for p in com(list(range(N+M-1)),M-1):
    m=1
    A=[]
    for i in range(N+M-1):
        if i in p:
            m+=1
        else:
            A.append(m)
    tmpres=0
    for a,b,c,d in query:
        if A[b-1]-A[a-1]==c:
            tmpres+=d
#     print(p,A,tmpres)
    res=max(tmpres,res)
print(res)

Measured memory_bytes: 73540
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//負の数始まり
ll minuss(ll n, vector<ll> a){
  ll x = 0;
  ll sum = 0; //手前までの合計
  ll counter = 0; //操作回数
  while(x < n){
    if(x % 2 == 0 && sum + a.at(x) >= 0){
      ll olda = a.at(x);
      a.at(x) = -1 - sum;
      counter += abs(a.at(x) - olda);
    }
    if(x % 2 == 1 && sum + a.at(x) <= 0){
      ll olda = a.at(x);
      a.at(x) = 1 - sum;
      counter += abs(a.at(x) - olda);
    }
    sum += a.at(x);
    x++;
  }
  return counter;
}

ll pluss(ll n, vector<ll> a){
  ll x = 0;
  ll sum = 0; //手前までの合計
  ll counter = 0; //操作回数
  while(x < n){
    if(x % 2 == 0 && sum + a.at(x) <= 0){
      ll olda = a.at(x);
      a.at(x) = 1 - sum;
      counter += abs(a.at(x) - olda);
    }
    if(x % 2 == 1 && sum + a.at(x) >= 0){
      ll olda = a.at(x);
      a.at(x) = -1 - sum;
      counter += abs(a.at(x) - olda);
    }
    sum += a.at(x);
    x++;
  }
  return counter;
}

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  cout << min(minuss(n,a), pluss(n,a)) << endl;
}


Measured memory_bytes: 2560
// 桁DP典型 と思ったら753以外出てこない、だった
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	stack := []int{0}
	ans := 0
	for len(stack) > 0 {
		var pop int
		stack, pop = stack[:len(stack)-1], stack[len(stack)-1]
		for _, a := range []int{3, 5, 7} {
			nex := pop*10 + a
			if nex > N {
				continue
			}
			if check(nex) {
				ans++
			}
			stack = append(stack, nex)
		}
	}
	fmt.Println(ans)
}

func check(n int) bool {
	flag3, flag5, flag7 := false, false, false
	for n > 0 {
		switch n % 10 {
		case 3:
			flag3 = true
		case 5:
			flag5 = true
		case 7:
			flag7 = true
		}
		n /= 10
	}
	if flag3 && flag5 && flag7 {
		return true
	}
	return false
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

vector<vector<pair<int, int>>> edge(100001, vector<pair<int, int>>(0));
VI color(100001);
void dfs(int v, int p, int c) {
	int nc = 1;
	for (int i = 0; i < edge[v].size(); i++) {
		if (edge[v][i].first != p) {
			if (nc == c) nc++;
			color[edge[v][i].second] = nc;
			dfs(edge[v][i].first, v, nc);
			nc++;
		}
	}
}

int main() {
	int n; cin >> n;
	int a, b; VI ec(n);
	REP(i, n - 1) {
		cin >> a >> b;
		edge[a].push_back({ b,i });
		edge[b].push_back({ a,i });
	}
	dfs(1, 0, 0);
	int maxc = 0; REP(i, n)maxc = max(maxc, color[i]);
	cout << maxc << endl;
	REP(i, n - 1)cout << color[i] << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

int main(){
	int n,x;
	cin>>n>>x;
	int l[n],d[n+1];
	for (int i = 0; i < n; ++i){
		cin>>l[i];
	}
	d[0]=0;
	int ans=1;
	for (int i = 1; i <= n; ++i){
		d[i]=d[i-1]+l[i-1];
	
		if(d[i]<=x)ans++;
	}

	cout<<ans<<endl;

}


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

typedef long long ll;

#define debug(args...)do{cerr<< #args << " : ";shaon(args);}while(0)
void shaon () { cerr << endl; }
template <typename T, typename ... north>
void shaon(T arg, const north &... rest){cerr << arg << ' ';shaon(rest...);}

const ll N=1e5+5;
ll dp[N], n, a[N];


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

    for(ll i=1; i<=n; i++){
        scanf("%lld",&a[i]);
    }

    dp[2]=abs(a[1]-a[2]);

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

    printf("%lld",dp[n]);

    return 0;
}


















Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
b=[]
bb=b.append
for i in range(n,0,-1):
    if i>n//2:
        bb(a[i-1])
    else:
        cnt=0
        j=3
        while(True):
            if i*j>n:
                break
            if b[n-i*j]==1:
                cnt+=1
            j+=2
        bb((cnt+a[i-1]+a[i*2-1])%2)
b=list(reversed(b))
print(sum(b))
if sum(b)>0:
    c=[]
    cc=c.append
    for i,j in enumerate(b):
        if j==1:
            cc(str(i+1))
    print(" ".join(c))

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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}

int main(){
  int64_t A,B;
  cin>>A>>B;
  int64_t lcm=A*B/gcd(A,B);

  cout<<lcm<<endl;

}

Measured memory_bytes: 256
#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb
#include<bits/stdc++.h>
#define mp				make_pair
#define rep(i,n)		for(int i = 0; i < n; i++)
#define foreach(i,c)	for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF			0x7fffffff
#define INF				0x3f3f3f3f
#define LINF			3223372036854775807
#define END(s)			{cout<<s; return 0;}
#define CON(s)			{cout<<s; continue;}
#define BRE(s)			{cout<<s; break;}
#define pb				push_back
//#define int				long long
#define All(a)			a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)			(int)a.size()
#define F				first
#define S				second
//#define usingFiles
using namespace std;

const int rp = 666666;
const bool debug = 1;

int a[200200];
int cnt0[100100];
int cnt1[100100];

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int n, mx = 0;
	cin >> n;
	rep(i, n){
		cin >> a[i];
		if(i % 2) cnt0[a[i]]++;
		else cnt1[a[i]]++;
		mx = max(mx, a[i]);
	}
	vector<pair<int, int> > v0;
	rep(i, mx + 1){
		if(cnt0[i]){
			v0.pb(mp(cnt0[i], i));
		}
	}
	sort(v0.begin(), v0.end());
	reverse(v0.begin(), v0.end());

	vector<pair<int, int> > v1;
	rep(i, mx + 1){
		if(cnt1[i]){
			v1.pb(mp(cnt1[i], i));
		}
	}
	sort(v1.begin(), v1.end());
	reverse(v1.begin(), v1.end());
	
	int val;
//	cout << v0.size() << " " << v1.size() << endl;;
	if(v0[0].S == v1[0].S){
		if(v0.size() > 1 && v1.size() > 1) val = n - max(v0[1].F + v1[0].F, v0[0].F + v1[1].F);
		if(v0.size() == 1 && v1.size() == 1) val = n / 2;
		if(v0.size() == 1 && v1.size() > 1) val = n - (v0[0].F + v1[1].F);
		if(v0.size() > 1 && v1.size() == 1) val = n - (v0[1].F + v1[0].F);
	} else val = n - (v0[0].F + v1[0].F);
	cout << val << endl;
	return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


signed main(){
	int n[3];
	rep(i, 0, 3) cin >> n[i];
	
	sort(RNG(n, 0, 3), greater<int>());

	cout << n[0]*10+n[1]+n[2] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

int main() {
    ll K;

    cin>>K;
    ll odd = K/2;
    ll even = K - odd;
    cout << odd * even << endl;
}


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

int main()
{
  int N;
  cin >> N;
  vector<long long int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  int two = 0, four = 0;
  for (int i = 0; i < N; i++)
  {
    if (a[i] % 2 == 0 && a[i] % 4 != 0)
      two++;
    else if (a[i] % 4 == 0)
      four++;
  }
  int odd = N - two - four;
  if (two + four == N)
    cout << "Yes" << endl;
  else
  {
    if (four >= N / 2)
      cout << "Yes" << endl;
    else if (four >= (N + (2 - 1)) / 2 - two / 2)
      cout << "Yes" << endl;
    else if (four >= (N + (2 - 1)) / 2 - (two + (2 - 1)) / 2 && N % 2 != 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


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

ll calcCombination(ll n, ll r){
    ll result = 1;
    for (ll i = 1; i <= r; i++) {
      result = result * (n + 1 - i) / i;
    }
    return result;
}

int main() {
  int N;
  cin >> N;

  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }

  // 累積和の作成
  vector<ll> s(N + 1, 0);
  for (int i = 0; i < N; i++) {
    s.at(i + 1) = s.at(i) + a.at(i);
  }

#ifndef ONLINE_JUDGE
  for (int i = 0; i < N + 1; i++) {
    cout << i << ": " << s.at(i) << endl;
  }
#endif

#ifndef ONLINE_JUDGE
  cout << "# debug" << endl;
#endif
  // 累積和の集計
  map<ll, ll> mp;
  for (int i = 0; i < N + 1; i++) {
    ll sum = s.at(i);
    mp[sum]++;
  }

  ll ans = 0;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    // 累積和の中で、特定の値の発生回数
    ll n = i->second;
    ll num_of_combinations = calcCombination(n, 2);
    ans += num_of_combinations;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18588
use std::io;

fn main() {
    let s = {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };
    let mut b: char = 'a';
    for i in s.as_str().chars() {
        if b == i {
            println!("Bad");
            return
        }
        b = i;
    }
    println!("Good");
}


Measured memory_bytes: 4352
#include <stdio.h>

#define MAX 100000

int getDepth(int);

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

struct tree array[MAX];

int main(){

  int n, i, j, id, degree, child, left, right;

  scanf("%d", &n);

  for( i=0; i<n; i++){
    array[i].parent = array[i].left = array[i].right = -1;
  }

  for( i=0; i<n; i++){
    scanf("%d%d", &id, &degree);
    for( j=0; j<degree; j++){
      scanf("%d", &child);
      if( j == 0 ){
	array[id].left = child;
      }
      else array[left].right = child;
      left = child;
      array[child].parent = id;
    }
  }

  for( i=0; i<n; i++){
    printf("node %d: parent = %d, depth = %d, ", i, array[i].parent, getDepth(i));
    if( array[i].parent == -1 ) printf("root, ");
    else if( array[i].left == -1 ) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    child = array[i].left;
    while(child != -1){
      if( child == array[i].left ){
	printf("%d", child);
      }
      else printf(", %d", child);
      child = array[child].right;
    }
    printf("]\n");
  }

  return 0;
}

int getDepth(int u){
  int d=0;

  while( array[u].parent != -1 ){
    u = array[u].parent;
    d++;
  }

  return d;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int C[N], A[N][M];
    for(int i = 0; i < N; ++i){
        cin >> C[i];
        for(int j = 0; j < M; ++j){
            cin >> A[i][j];
        }
    }

    int INF = 10000000;
    int sum[M], sm, tmp=0, ans=INF;
    
    for(int i = 0; i < pow(2,N); ++i){//12を使う使わない全探索
        //cout << tmp << ":";
        //init
        for(int j = 0; j < M; ++j) sum[j] = 0;
        
        //calc
        for(int i = 0; i < N; ++i){
            if(tmp % ((int)pow(2,i+1)) >= (int)pow(2,i)){
                //cout << i << ",";
                sm += C[i];
                for(int j = 0; j < M; ++j) sum[j] += A[i][j];
            }
        }
        //cout << ">"<< sm;
        //for(int j = 0; j < M; ++j) cout << sum[j] << ",";
        //OK?
        bool ok = true;
        for(int j = 0; j < M; ++j){
            if(sum[j] < X) ok = false;
        }
        if(ok) ans = min(ans, sm);
        //cout << ":" << ans << endl;
        //bits
        tmp++;
        sm = 0;
    }
    if(ans == INF) ans = -1;

    cout << ans << endl;
}


Measured memory_bytes: 3968
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

n, k = map(int, input().split())
a = np.array(readline().split(), dtype=np.int64)
for i in range(k, n):
    if a[i] > a[i-k]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 52808
#include <iostream>
#include <cassert>
#include <vector>

template <class T> inline void chadd(T &a, const T &b) {
  a += b;
}

int main()
{
  // Input
  int numCoin;
  std::cin >> numCoin;
  assert(1 <= numCoin and numCoin <= 2999);
  assert(numCoin % 2 == 1);
  std::vector<double> probability(1 + numCoin);
  for (int i = 1; i <= numCoin; ++i) {
    std::cin >> probability[i];
    assert(0 < probability[i] and probability[i] < 1);
  }

  // Initialization
  std::vector<std::vector<double>> dp(1 + numCoin);
  for (int i = 0; i <= numCoin; ++i)
    dp[i].assign(1 + numCoin, 0);

  // Initial condition
  dp[0][0] = 1;

  // DP main
  for (int i = 0; i < numCoin; ++i) {
    for (int j = 0; j <= i; ++j) {
      chadd(dp[i + 1][j + 1], dp[i][j] * probability[i + 1]);
      chadd(dp[i + 1][j], dp[i][j] * (1 - probability[i + 1]));
    }
  }

  // Output
  double res = 0;
  for (int j = numCoin / 2 + 1; j <= numCoin; ++j)
    res += dp[numCoin][j];
  // std::cout << res << std::endl;
  printf("%.12f\n", res);

  return 0;
}


Measured memory_bytes: 70656
n=int(input())
a=[]
b=[]
l=[]
ans=0
for i in range(n):
    x,y=map(int,input().split())
    a+=[x]
    b+=[y]
    l+=[(x,y,i)]
l.sort(key=lambda x:x[0]+x[1])
for x in l[-1::-2]:
    ans+=a[x[2]]+b[x[2]]
print(ans-sum(b))

Measured memory_bytes: 78424
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,p[30000];
ll r[300000];
int main(){
	cin >> n;
	REP(i,n){
		cin >> p[i];
		r[p[i] - 1] = i;
	}

	REP(i,n) {
		cout << 20001 * (i + 1) + r[i] << " ";
	}
	cout << endl;
	REP(i,n) {
		cout << 20001* (n - i) << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


int main()
{
	int A, B,C,X;
	cin >>X;
	bool res= false;
	for (int a = 0; a <= 30; a++)
	{
		for (int b = 0; b <= 20; b++)
		{
			
				int total = 4 * a + 7 *b;
				if (total == X)
				{
					res=true;
					break;
				}
		}
	}
	
	if (res == true)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	


}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  string A, B, C;
  cin >> N >> A >> B >> C;
  ll count = 0;
  REP(i, N) {
    if (A[i] == B[i]) {
      if (A[i] != C[i])
        count++;
    } else if (A[i] == C[i]) {
      if (A[i] != B[i])
        count++;
    } else if (B[i] == C[i]) {
      if (A[i] != B[i])
        count++;
    } else {
      count += 2;
    }
  }
  cout << count << endl;
  return 0;
}


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

int dp[100010];

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

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = a + b + c + max(a, max(b, c)) * (pow(2, k) - 1);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll h,n;
	vector<ll>arr(10001,INT_MAX);
	cin>>h>>n;
	map<ll,ll>m;
	for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        if(m.find(a)!=m.end())
        {
            m[a]=min(m[a],b);
            continue;
        }
        m[a]=b;
    }
    for(ll i=1;i<=10000;i++)
    {
        if(m.find(i)!=m.end())
            arr[i]=m[i];
        for(ll j=1;j<=i/2;j++)
        {
            arr[i]=min(arr[i],arr[j]+arr[i-j]);
        }
    }
    for(ll i=10000-1;i>=1;i--)
    {
        arr[i]=min(arr[i],arr[i+1]);
    }
    cout<<arr[h];
}


Measured memory_bytes: 384
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n,tmp=0;
	cin >> n;
	vector<ll> a(n);
	for(ll i=0;i<n;i++){
		cin >> a[i];
		tmp= (a[i]^tmp);
	}
	for(ll i=0;i<n;i++){
		cout << (tmp^a[i]) << " ";
	}
	
}

Measured memory_bytes: 4744
#include <cstdio>
#include <algorithm>
const int maxn = 1e5+7;
int n;
int d[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&d[i]);
    std::sort(d+1,d+1+n);
    int mid = n/2;
    while(mid+1 <= n && d[mid] == d[mid+1])
        mid++;
    if(mid * 2 == n)
    {
        printf("%d\n", d[mid+1]-d[mid]);
    }else
    {
        printf("%d\n", 0);
    }
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
   int N,M,i,L[100000],R[100000],maxL=0,minR=120000;
    scanf("%d %d",&N,&M);
    for(i=0;i<M;i++){
    scanf("%d %d",&L[i],&R[i]);
    if(L[i]>maxL)
    maxL=L[i];
    if(R[i]<minR)
    minR=R[i];
    }
    if(minR>=maxL)
    printf("%d",minR-maxL+1);
    else
    printf("0");
   
    return(0);
}


Measured memory_bytes: 896
def fmt(ac,wa,tle,re)
  puts "AC x #{ac}\nWA x #{wa}\nTLE x #{tle}\nRE x #{re}"
end
N = gets.to_i
s = []
N.times do
  s.push(gets.chomp)
end
a=b=c=d=0
s.each do |val|
  case val
    when "AC"
      a += 1
    when "WA"
      b += 1
    when "TLE"
      c += 1
    when "RE"
      d += 1
  end
end
fmt(a,b,c,d)

Measured memory_bytes: 20732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll count = 0;
    for (int i = n - 1; i; i--){
        if (b[i] > a[i + 1] + a[i]){
            count += a[i + 1] + a[i];
            a[i + 1] = a[i] = 0;
        }
        else if (b[i] > a[i + 1]){
            count += b[i];
            a[i] -= b[i] - a[i + 1];
        }
        else{
            count += b[i];
            a[i + 1] -= b[i];
        }
    }
    if (a[0] + a[1] < b[0])
        count += a[0] + a[1];
    else
        count += b[0];
    cout << count << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define PER(i, a, b) for(int i = a; i >= b; i--)
#define LL long long
#define lowbit(x) x &(-x)

inline int read() {
    int x = 0, flag = 1;char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') flag = - 1;
        ch = getchar();
    }
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x * flag;
}
const int N = 1e5 + 5;
int n, m, v, p, ans;
LL a[N];

inline bool jud(int x) {
    int y = v - x - (p - 1);
    LL z = a[x] + m; LL sum = 0;
    REP(i, x + 1, n - p + 1) {
        if(z < a[i]) return false;
        sum += (z - a[i]);
    } 
    return sum >= 1LL * y * m;
}

int main() {   
    n = read(), m = read(); v = read(); p = read();
    REP(i, 1, n) a[i] = read();
    sort(a + 1, a + n + 1);
    int l = 1, r = n - p + 1;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(jud(mid)) {
            ans = n - mid + 1;
            r = mid - 1;
        } else l = mid + 1; 
    }
    printf("%d\n", ans);
	return 0;
}
//0 1 1 2 2 3
//1 56

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

using namespace std;

#define int long long 
#define double long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

int32_t main()
{
	int n,m,k;
	vector<int>f,s;
	
	cin >> n >> m >> k;
	for(int i = 0;i < n;i++)
	{
		int a;
		cin >> a;
		if(i == 0) f.push_back(a);
		else f.push_back(a+f[i-1]);
	}
	for(int i = 0;i < m;i++)
	{
		int a;
		cin >> a;
		if(i == 0) s.push_back(a);
		else s.push_back(a+s[i-1]);
	}
	
	int mx = 0;
	for(int i = 0; i < n;i++)
	{
		if(f[i] > k) break;
		int val = k - f[i];
		int ans = upper_bound(s.begin(),s.end(),val) - s.begin();
		mx = max(mx,i+1+ans);
	}
	for(int i = 0; i < m;i++)
	{
		if(s[i] > k) break;
		int val = k - s[i];
		int ans = upper_bound(f.begin(),f.end(),val) - f.begin();
		mx = max(mx,i+1+ans);
	}
	cout << mx << endl;
	return 0;
}

//140 130 120 -> 390
// 150 70 60 50 40 -> 370 
// 140 270 390
//150 220 280 330 370


Measured memory_bytes: 7972
#include <stdio.h>

int main(void)
{
	int i;
	int h[10];
	int first = 0;
	int second = 0;
	int third = 0;
	int n;
	int rank[3];
	int j;

	n = 0;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &h[i]);
	}
	for (j = 0; j < 3; j++){
		for (i = 0; i < 10; i++){
			if (h[n] < h[i]){
				n = i;
			}
		}
		rank[j] = h[n];
		h[n] = -1;
		n = 0;
	}


	h[first] = -1;

	for (i = 0; i < 10; i++){
		if (h[second] < h[i]){
			second = i;
		}
	}

	h[second] = -1;
	for (i = 0; i < 10; i++){
		if (h[third] < h[i]){
			third = i;
		}
	}
	printf("%d\n", rank[0]);
	printf("%d\n", rank[1]);
	printf("%d\n", rank[2]);

	return (0);
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


int main() {
  int N;
  cin >> N;
  string str;
  set<string> s;
  rep(i,N) {
    cin >> str;
    s.insert(str);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 19256
n,k=map(int,input().split())
l=[]
if k<=9 :
  while True:
    a=n%k
    if n>=k:
      l.append(a)
    n//=k
    if n<k :
      l.append(n)
      break
  print(len(l))
else:
  print(len(str(n)))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <functional>

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 100;

int N;

class Edge{
public:
	int from, to, cost;
	Edge(int from = 0, int to = 0, int cost = 0) :
		from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

static const int INFTY = (1 << 21);

class Node{
public:
	vector<Edge> edges;
	int dist;
	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
};

class Data{

public:
	int dist; Edge edge;
	Data(int dist, Edge edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}

};

int main() {

	cin >> N;
	Graph g(N);

	rep(i, N){
		int no; cin >> no;
		int n_edge; cin >> n_edge;

		rep(j, n_edge){
			int from = no;
			int to; cin >> to;
			int cost; cin >> cost;
			Edge e(from, to, cost);
			g.nodes[no].edges.push_back(e);
		}
	}

	int i = 0;
	g.nodes[i].dist = 0;

	priority_queue<Data, vector<Data>, greater<Data> > pq;
	for (auto e : g.nodes[i].edges){
		int dist = g.nodes[i].dist + e.cost;
		Data d(dist, e);
		pq.push(d);
	}

	int ret = 0;
	while (!pq.empty()){
		Data d = pq.top(); pq.pop();
		Node *n = &g.nodes[d.edge.to];
		if (n->dist != INFTY){ continue; }
		n->dist = d.dist;

		for (auto e : n->edges){
			int dist = n->dist + e.cost;
			Data d(dist, e);
			pq.push(d);
		}
	}

	rep(i, N){
		cout << i << " " << g.nodes[i].dist << endl;
	}
}

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

class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
		cnt = N;
		p = s = vector<int>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

int N,M;

struct edge{
    int s,t,c;
    bool operator<(const edge& r)const{
        return c<r.c;
    }
};

int main(){
    cin >> N >> M;
    vector<edge> v,u;
    int s,t,c;
    for(int i=0;i<M;i++){
        cin >> s >> t >> c;
        v.push_back({s,t,c});
    }
    sort(v.begin(),v.end());
    int cost = 0;
    UnionFind uf(N);
    for(auto x:v){
        if(!uf.is_same_set(x.s,x.t)){
            u.push_back(x);
            uf.unite(x.s,x.t);
            cost += x.c;
        }
    }
    int ans = 0,cnt = 0;
    for(auto y:u){
        UnionFind uf2(N);
        int cost2 = 0;
        for(auto x:v){
            if(x.s==y.s && x.t==y.t) continue;
            if(!uf2.is_same_set(x.s,x.t)){
                uf2.unite(x.s,x.t);
                cost2 += x.c;
            }
        }
        if(uf2.size(1)!=N || cost2!=cost){
            ans += y.c;
            cnt++;
        }
    }
    cout << cnt << " " << ans << endl;
}


Measured memory_bytes: 3868
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // int [] array ={n};      
        int min = 1000000;
        int max = -1000000;
        long sum = 0;
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            sum = sum + a;
            if (a > max) {
                max = a;
            }if (min > a) {
                min = a;
            }
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 41292
while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{arr << gets.chomp.split.map(&:to_i)}
    arr.map!{|ar| ar[1..-1]}
    divulged = gets.chomp.split.map(&:to_i)
    divulged.shift

    suspect = []
    arr.each_with_index{|ar, i| suspect <<  i + 1 if divulged - ar == []}
    puts (suspect.length == 1) ? suspect[0] : -1
end


Measured memory_bytes: 7308