akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pi 3.141592654
int main()
{
    int n,k;
    cin>>n;
map<int,int>mp;
    for(int i=0;i<n-1;i++)
    {
        int x;
        cin>>x;
    mp[x]++;
    }
 for(int i=1;i<=n;i++)
    {

   cout<<mp[i]<<endl;
    }
}


Measured memory_bytes: 12972
def check(x, y, z):
    return x+y > z and x+z > y and y+z > x

n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if a[i] != a[j] and a[j] != a[k] and a[i] != a[k] and check(a[i], a[j], a[k]):
                ans += 1
print(ans)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for (auto& x : A) cin >> x;
	ll L = 0, R = 1LL<<30;
	while (R-L >= 2) {
		auto m = (L+R)/2;
		ll c = 0;
		for (auto x : A) {
			c += (x-1) / m;
		}
		if (c <= K) {
			R = m;
		} else {
			L = m;
		}
	}
	cout << R << endl;
}


Measured memory_bytes: 4836
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    long long a, b;
    cin >> a >> b;
    if (b-a >= 2019) {
        cout << 0;
    } else {
        long long mini = 2018;
        for (long long i=a; i<b; i++) {
            for (long long j=i+1; j<=b; j++) {
                mini = min(mini, (i*j)%2019);
            }
        }
        cout << mini;
    }
}

Measured memory_bytes: 256
import java.math.*;
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();
			int an =Integer.parseInt(a);
			int bn =Integer.parseInt(b);
			
			
			String ab ="" ;
			String ba =""  ;
			

			
			for (int i=0;i<bn;i++) {
				ab += a;
			}
			
			
			for (int i=0;i<an;i++) {
				ba += b;;
			}
			
			
			
			if(ab.compareTo(ba)<0) {
				System.out.println(ab);
			}else {
				System.out.println(ba);
			}
			
		}
				
	}

Measured memory_bytes: 25044
import std.algorithm;
import std.array;
import std.range;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;

alias FairyPos = Tuple!(int,int);

void main(){
    auto inputs = readln.chomp.split.map!(to!int);
    auto a = inputs[0];
    auto b = inputs[1];
    auto c = inputs[2];
    string answer;
    if(c <= a + b){
        answer = "Yes";
    }else{
        answer = "No";
    }
    writeln(answer);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 2e5+5;
ll n, t, arr[nax];

int main(void){
	IOS
	cin >> n >> t;
	for(ll i=0;i<n;i++){
		cin >> arr[i];
	}
	ll tmp=0;
	for(ll i=0;i<n;i++){
		if(i==n-1) tmp+=t;
		else tmp+=(min(arr[i+1], arr[i]+t)-arr[i]);
		//cout << i << ' ' << tmp << '\n';
	}
	cout << tmp << '\n';
}


Measured memory_bytes: 5124
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,m = [int(i) for i in readline().split()]
sc = [[int(i) for i in readline().split()] for _ in range(m)]

ans = [0]*n

for s,c in sc:
    if n >= 2 and s-1 == 0 and c == 0: # 2桁以上の数で、左から1桁目が0を指定された場合は-1
        print(-1)
        break
    elif ans[s-1] == 0:
        ans[s-1] = c
    elif ans[s-1] != c: # 左からs桁目が異なる値を指定された場合は-1
        print(-1)
        break
else:
    if n >= 2 and ans[0] == 0:
        ans[0] = 1
    ans = sum([10**(n-i-1)*d for i,d in enumerate(ans)])
    print(ans)

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

int main()
{
    string a, b, c;
    int i=0, j=0, k=0;
    cin >> a >> b >> c;
    char turn = 'a';
    while(true){
        switch(turn){
            case 'a':
                if(i==a.size()){
                    cout << "A\n";
                    return 0;
                }
                turn = a[i];
                i++;
                break;
            case 'b':
                if(j==b.size()){
                    cout << "B\n";
                    return 0;
                }
                turn = b[j];
                j++;
                break;
            case 'c':
                if(k==c.size()){
                    cout << "C\n";
                    return 0;
                }
                turn = c[k];
                k++;
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
def guidebook(N: int, scores: list)->list:
    rev = {v: i for i, v in enumerate(scores)}
    scores.sort(key=lambda x: -x[1])
    scores.sort(key=lambda x: x[0])

    return [rev[v]+1 for v in scores]


if __name__ == "__main__":
    N = int(input())
    scores = []
    for _ in range(N):
        s, p = input().split()
        scores.append((s, int(p)))

    for ans in guidebook(N, scores):
        print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m;
  cin >> n >> m;
  cout << ((n-1)*n)/2 + ((m-1)*m)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
n=input()
l=list(n)
L=[]
for i in l:
    t=int(i)
    L.append(t)
m=len(L)
kisu=0
gusu=0
for i,k in enumerate(L):
    if(i%2==k):
        kisu+=1
    if(i%2!=k):
        gusu+=1
print(min(kisu,gusu))

Measured memory_bytes: 4724
#include<iostream>
using namespace std;
string s;
long ans;
int N;
int id(char c){return c=='R'?0:c=='G'?1:2;}
main()
{
	cin>>N>>s;
	for(int i=0;i<N;i++)
	{
		long L[3]={},R[3]={};
		for(int j=i-1;j>=0;j--)L[id(s[j])]++;
		for(int j=i+1;j<N;j++)R[id(s[j])]++;
		for(int j=0;j<3;j++)for(int k=0;k<3;k++)
		{
			if(id(s[i])!=j&&id(s[i])!=k&&j!=k)ans+=L[j]*R[k];
		}
		for(int k=1;;k++)
		{
			if(i-k<0||i+k>=N)break;
			if(s[i-k]!=s[i]&&s[i]!=s[i+k]&&s[i-k]!=s[i+k])ans--;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
typedef pair< int , int> P;
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const P& firstElof, const P& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
int a=0,b=0;
std::cin >> x;
std::vector<int> v(x);
rep(i,x)std::cin >>v[i];
for(;;){
  rep(i,x)if(v[i]%2==0)y++;
  if(y==x){
    rep(i,x)v[i]=v[i]/2;
  z++;
  y=0;
}else break;
}
std::cout << z << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    
    int n;
    cin>>n;
    set<string> v;
    rep(i,n){
        string a;
        cin>>a;
        v.insert(a);
    }
    cout<<v.size();
    
    
    
return 0;
}


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

int main(void)
{
  long  double PI = 3.14159265358979323846;
  double  r;
  cin >> r;

  cout << fixed << setprecision(6) <<  PI * (r * r) << " ";
  cout << fixed << setprecision(6) << 2 * PI * r << endl;
  return  0;

}



Measured memory_bytes: 3276
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    ll h; cin >> h;
    ll ans = 0, num = 1;
    while(h > 1) {
        ans += num;
        num *= 2;
        h /= 2;
    }
    ans += num;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define rep(i,n,k) for(int i=n;i<k;i++)
#define int unsigned long long
#define F first 
#define S second
#define P make_pair 

signed main(void){
 
    
    int n,m,q,p,ans;
    string s;
    ans=0;
    vector<int> v;
    cin>>n>>m;
    rep(i,0,m){
        cin>>p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    rep(i,0,m-1){
        if(ans<v[i+1]-v[i])
        ans=v[i+1]-v[i];
    }
    if(n-v[m-1]+v[0]>ans)
    ans=n-v[m-1]+v[0];
    cout<<n-ans<<endl;
    
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    vi h(n);
    rep(i,n) cin >> h[i];
    int ans = 0;
    for(int i = 0; i < n-1;i++ ) {
        if(h[i] >= h[i+1]) {
            int save = 0;
            while(h[i] >= h[i+1]) {
                save++;
                i += 1;
                if (i == n-1) break;
            }
            ans = max(ans, save);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
N, X = map(int,input().split())
L =list(map(int,input().split()))

ans_count = 1
ans = 0
for i in range(N):
    if ans + L[i] <= X:
        ans = ans + L[i]
        ans_count = ans_count+1
    else:
        break        
print(ans_count)    

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}//continue break
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        ll n,k;cin>>n>>k;
        ll a[n+1];rep(i,n)cin>>a[i+1];
        for(int i=k+1;i<=n;i++){
            if(a[i]>a[i-k]){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 5220
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var list = new List<int>();
        for (int i = 0; i < inp[0]; i++)
        {
            list.Add(inp[1] + i);
        }
        var sum = list.Sum();
        int[] a = new int[2];
        a[0] = list.Min();
        a[1] = list.Max();
        if (a[0] * a[1] <= 0) Console.WriteLine(sum);
        else if (a[0] < 0) Console.WriteLine(sum - a[1]);
        else Console.WriteLine(sum - a[0]);
    }
}

Measured memory_bytes: 13268
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a+b+c>=22)
{
cout<<"bust";
}
else
{
cout<<"win";
}
}

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

int main(){
    ll N;
    cin >> N;
    ll a = 0, b = 0, ab = 0, ans = 0;
    rep(i, 0, N){
        string s;
        cin >> s;
        if(s[0] == 'B' && s[s.size()-1] == 'A') ab++;
        else if(s[0] == 'B') a++;
        else if(s[s.size()-1] == 'A') b++;
        rep(j, 0, s.size()-1){
            if(s[j] == 'A' && s[j+1] == 'B') ans++;
        }
    }
    
    if(a == 0 && b == 0){
        if(ab > 0) ans += ab - 1;
    }else if(a == 0 || b == 0){
        ans += ab;
    }else{
        if(ab == 0) ans += min(a, b);
        else ans += ab + min(a, b); 
    }

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

Measured memory_bytes: 764
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		System.out.println(500 * k >= n ? "Yes" : "No");
	}
}


Measured memory_bytes: 35572
//code for love 
//love for code
//it does not matter how slow you go unless you don't stop

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n;cin>>n;int a[n];int t;for(int i=0;i<n;i++)a[i]=0;
   for(int i=0;i<n-1;i++)
   {
    cin>>t;a[t-1]++;   
   }
   for(int i=0;i<n;i++)
   cout<<a[i]<<endl;
   
}


Measured memory_bytes: 4420
H, W = map(int, input().split())
S = []
for i in range(H):
    s = input()
    S.append(list(s))

# 隣接のマスをループで表すために必要
di = [-1, 0, 1, 0]
dj = [0, -1, 0, 1]

def is_street(s, t):
    """
    道であること（壁ではないこと）を確認
    """
    return S[s][t] == '.'

def count(maze):
    """
    最大のコストを探索
    """
    r = -1
    for i in range(H):
        for j in range(W):
            r = max(r, maze[i][j])
    return r

def bfs(h, w):
    """
    h: スタート位置（高さ）
    w: スタート位置（横）
    """
    m = []  # スタート地点からの距離が入る
    for i in range(H):
        s = [-1] * W
        m.append(s)
    m[h][w] = 0  # スタート地点は0

    q = [[h, w]]
    while len(q) != 0:
        si, sj = q.pop(0)
        cost = m[si][sj]

        for i in range(4):
            ni = si + di[i]
            nj = sj + dj[i]
            if not (0 <= ni < H and 0 <= nj < W):
                continue
            if not is_street(ni, nj): 
                continue
            if m[ni][nj] != -1:
                continue

            m[ni][nj] = cost + 1
            q.append([ni, nj])

    max_cost = count(m)
    return max_cost

ans = -1
# 壁以外のすべてのマスをスタートにして探索
for i in range(H):
    for j in range(W):
        if not is_street(i, j):
            continue
        c = bfs(i, j)
        ans = max(ans, c)

print(ans)


Measured memory_bytes: 3188
/**
 * File              : A - Frog 1 .cpp
 * Author            : horcrux2301 <khajuriaharsh729@gmail.com>
 * Date              : 06.01.2019
 * Last Modified Date: 06.01.2019
 */

#include <bits/stdc++.h>
#define ll long long
#define mp(a,b)     make_pair(a,b)
#define newline     cout << endl;
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int main(){
    //clock_t tStart = clock();
    int test;
    test=1;
    //cin >> test;
    while(test--){
        ll n;
        cin >> n;
        ll arr[n];
        for(ll i=0;i<n;i++){
            cin >> arr[i];
        }
        ll dp[n];
        for(ll i=0;i<n;i++){
          dp[i]=1e10;
        }
        dp[0] = 0;
        dp[1] =  abs(arr[1]-arr[0]);
        for(ll i=2;i<n;i++){
            dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]));
        }
        cout << dp[n-1] << endl;
    }
    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<list>
using namespace std;

signed main() {
	list<int>L;
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		int c; cin >> c;
		if ((a+b) & 1)L.push_front(c);
		else L.push_back(c);
	}
	for (auto i = L.begin(); i != L.end(); i++) {
		if (i == --L.end()) { cout << *i << endl; }
		else cout << *i << " ";
	}
}

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

int main(){
    int h,w,n; cin >> h >> w >> n;
    int ma = max(h,w);
    if(n%ma == 0) cout << n/ma << endl;
    else cout << n/ma + 1<< endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Long, Integer> map = new HashMap<>();
        map.put(0L, 1);
        long sum = 0;
        for(int i=0 ; i<n; i++) {
            sum += sc.nextInt();
            map.put(sum, map.getOrDefault(sum, 0) + 1);
        }

        long res = 0;

        for(Map.Entry<Long, Integer> entry : map.entrySet()) {
            long key = entry.getKey();
            int v = entry.getValue();
            if(v > 1) {
                res += (long) v * (v-1) / 2;
            }
        }

        System.out.println(res);
    }

}


Measured memory_bytes: 99672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll k,a,b;
	cin>>k;
    cin>>a>>b;
	for(ll i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
    }
	cout<<"NG"<<endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

const int N_MAX = pow(10,5);

// factorial(階乗)の計算

ll fac[N_MAX+1] ={};

ll c_fac(int n) {
  if (fac[n]!=0) return fac[n];
  if (n==0) return fac[n]=1;
  return fac[n] = (c_fac(n-1)*n)%MOD;
}

// inverse(逆元)の計算

ll inv(ll a,ll m) {
  ll b = m, x = 1, y = 0;
  while (b!=0) {
    ll d = a/b;
    a -= b*d; swap(a, b);
    x -= y*d; swap(x, y);
  }
  return x>=0 ? x : x+m;
}

// combinataionの計算

ll nck(ll n, ll k) { 
  c_fac(n);
  if (n<k) return 0;
  ll nume = fac[n];
  ll deno = ( inv(fac[n-k],MOD) * inv(fac[k],MOD) ) % MOD;
  return ( nume * deno ) % MOD;
}

int main() {
  int N, K; cin >> N >> K;
  int r = N-K, b = K;
  rep(i,b) {
    ll result = ( nck(r+1,i+1) * nck(b-1,i) ) % MOD;
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*最大の利益*/
#include <stdio.h>
#define N 2000000

int main(){
  int i, j, n, min, max;
  int a[N];

  scanf("%d" ,&n);

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

  max = a[1] - a[0];
  min = a[0];
  
  for (i=1; i<n; i++){
    if (max < a[i]-min)
      max = a[i]-min;
      
    if (min > a[i])
      min = a[i];
  }
  
  printf("%d\n", max);
  
  return 0;
}



Measured memory_bytes: 2520
/*THINK GONNA FAIL ? IF U DIDNT FAIL THEN WHAT IS THE POINT OF LEARNING */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define ran(v) v.begin(),v.end()
#define mod 1000000007
#define inf 1e15
#define ff first
#define ss second
// #define N --

using namespace std;

vector<list<int>> adjList;
vector<int> dp;
int ans = INT_MIN;
int n, m;

void LongestPath(int node) {
	dp[node] = 0;
	for (int child : adjList[node]) {
		if (dp[child] == -1) LongestPath(child);
		dp[node] = max(dp[node], dp[child]);
	}

	dp[node]++;
	ans = max(ans, dp[node]);
}

int32_t main() {
	fast
	int t_c = 1;
//	cin >> t_c;
	while (t_c--) {
		cin >> n >> m;
		adjList.resize(n + 1), dp.resize(n + 1, -1);
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			adjList[a].pb(b);
		}
		for (int i = 1; i <= n; i++)
			if (dp[i] == -1) LongestPath(i);
		cout << ans  - 1 << endl;
	}
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
long double x[100100],y[100100];
char d[100100];
long double DINF = 1e18;
long double Umax,Umin;
long double Dmax,Dmin;
long double Lmax,Lmin;
long double Rmax,Rmin;
long double Ymin,Ymax;
long double Xmin,Xmax;
long double f(long double t){
	long double Y = max(Ymax,max(Umax+t,Dmax-t))-min(Ymin,min(Umin+t,Dmin-t));
	long double X = max(Xmax,max(Rmax+t,Lmax-t))-min(Xmin,min(Rmin+t,Lmin-t));
	//cout << t << ' ' << X << ' ' << Y << endl;
	return X*Y;
}
int main(){
	cin >> N;
	Umax = -DINF;
	Umin = DINF;
 
	Dmax = -DINF;
	Dmin = DINF;
 
	Lmax = -DINF;
	Lmin = DINF;
 
	Rmax = -DINF;
	Rmin = DINF;
 
	Xmax = -DINF;
	Xmin = DINF;
 
	Ymax = -DINF;
	Ymin = DINF;
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i] >> d[i];
		if(d[i]=='U'){
			Umax = max(Umax,y[i]);
			Umin = min(Umin,y[i]);
			Xmax = max(Xmax,x[i]);
			Xmin = min(Xmin,x[i]);
		}else if(d[i]=='D'){
			Dmax = max(Dmax,y[i]);
			Dmin = min(Dmin,y[i]);
			Xmax = max(Xmax,x[i]);
			Xmin = min(Xmin,x[i]);
		}else if(d[i]=='L'){
			Lmax = max(Lmax,x[i]);
			Lmin = min(Lmin,x[i]);
			Ymax = max(Ymax,y[i]);
			Ymin = min(Ymin,y[i]);
		}else{
			Rmax = max(Rmax,x[i]);
			Rmin = min(Rmin,x[i]);
			Ymax = max(Ymax,y[i]);
			Ymin = min(Ymin,y[i]);
		}
	}
	//cout << f(0.0) << endl;
  cout << fixed << setprecision(20);
  vector<long double> cand;

  cand.pb(0.0);

  cand.pb(Ymin-Umax);
  cand.pb(Ymax-Umax);
  cand.pb((Dmin-Umax)/2.0);
  cand.pb((Dmax-Umax)/2.0);
  cand.pb(Ymin-Umin);
  cand.pb(Ymax-Umin);
  cand.pb((Dmin-Umin)/2.0);
  cand.pb((Dmax-Umin)/2.0);
  cand.pb(Dmin-Ymax);
  cand.pb(Dmin-Ymin);
  cand.pb(Dmax-Ymax);
  cand.pb(Dmax-Ymin);
  
  cand.pb(Xmin-Rmax);
  cand.pb(Xmax-Rmax);
  cand.pb((Lmin-Rmax)/2.0);
  cand.pb((Lmax-Rmax)/2.0);
  cand.pb(Xmin-Rmin);
  cand.pb(Xmax-Rmin);
  cand.pb((Lmin-Rmin)/2.0);
  cand.pb((Lmax-Rmin)/2.0);
  cand.pb(Lmin-Xmax);
  cand.pb(Lmin-Xmin);
  cand.pb(Lmax-Xmax);
  cand.pb(Lmax-Xmin);

  long double ans = DINF;
  for(int i=0;i<cand.size();i++){
    if(cand[i]<0.0)continue;
    chmin(ans,f(cand[i]));
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N = 2e5+20, MOD = 1e9+7;

ll fact[N], ifact[N];

ll binpow(ll x, ll p){
	ll ans;
	for(ans = 1; p; p >>= 1, x = (x*x)%MOD)
		if(p&1) ans = (ans*x) % MOD;
	return ans;
}

void build(){
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < N; ++i){
		fact[i] = fact[i-1] * i % MOD;
		ifact[i] = binpow(fact[i],MOD-2);
	}
}

ll comb(int n, int k){
	return fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}

int n;
int tsz[N];
ll dp[N],ans[N];
vector<int> adj[N];

void dfs(int u, int p = -1){
	dp[u] = 1;
	tsz[u] = 1;
	for(int v : adj[u]) if(v != p){
		dfs(v,u);
		tsz[u] += tsz[v];
	}
	int rem = tsz[u]-1;
	for(int v : adj[u]) if(v != p){
		dp[u] = dp[u] * dp[v] % MOD * comb(rem,tsz[v]) % MOD;
		rem -= tsz[v];
	}
}

void go(int u, int p = -1){
	ans[u] = dp[u];
	for(int v : adj[u]) if(v != p){
		ll ways = dp[u];
		ll divi = dp[v]*comb(n-1,tsz[v]) % MOD;
		ways = ways * binpow(divi,MOD-2) % MOD;
		dp[v] = dp[v] * ways % MOD * comb(n-1,n-tsz[v]) % MOD;
		go(v,u);
	}
}

int main(){

	fastio;
	build();
	int a,b;
	cin >> n;
	REP(i,0,n-1){
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	dfs(1);
	go(1);

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

	return 0;
}


Measured memory_bytes: 20980
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	ll a, b;
	cin >> a >> b;
	cout << a * b << '\n';
}



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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAX_N = 18;
int n;
int a[1 << MAX_N];
pii dp[2][1 << MAX_N];

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

  for (int k = 1; k < (1 << n); k++) {
    dp[0][k] = max(mp(a[0],0), mp(a[k],k));
    dp[1][k] = min(mp(a[0],0), mp(a[k],k));
    for (int i = 0; i < n; i++) {
      if ((k & (1 << i)) != 0) {
        pii new_v = dp[0][k & ~(1 << i)];
        //printf("i=%d new_v=%d\n", i, new_v);
        if (new_v > dp[0][k]) {
          dp[1][k] = dp[0][k];
          dp[0][k] = new_v;
        } else if (dp[0][k].second != new_v.second && new_v > dp[1][k]) {
          dp[1][k] = new_v;
        }
      }
    }
    assert(dp[0][k].second != dp[1][k].second);
    //printf("dp[0][%d]=%d dp[1][%d]=%d\n", k, dp[0][k].first, k, dp[1][k].first);
  }

  int m = 0;
  for (int k = 1; k < (1 << n); k++) {
    m = max(m, dp[0][k].first + dp[1][k].first);
    //printf("init_m=%d\n", m);
    for (int i = 0; i < n; i++) {
      if ((k & (1 << i)) != 0) {
        int j = (k & ~(1 << i)) | ((1 << i) - 1);
        //printf("k=%d i=%d j=%d\n", k, i, j);
        m = max(m, dp[0][j].first + dp[1][j].first);
      }
    }
    cout << m << endl;
  }

  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll k, t;
	cin >> k >> t;
	vll a(t);
	priority_queue<vll> pq;
	for (ll i = 0; i < t; i++) {
		cin >> a[i];
		pq.push({a[i], i});
	}

	ll ans = 0;
	ll prev = -1;
	while (k--) {
		vll v = pq.top();
		pq.pop();
		if (v[1] != prev) {
			v[0]--;
			if (v[0] > 0) pq.push(v);
			prev = v[1];
		}
		else if (pq.empty()) {
			v[0]--;
			if (v[0] > 0) pq.push(v);
			prev = v[1];
			ans++;
		}
		else {
			vll w = pq.top();
			pq.pop();
			w[0]--;
			pq.push(v);
			if (w[0] > 0) pq.push(w);
			prev = w[1];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
use std::collections::*;
// use std::io::prelude;
use std::io;
use std::io::Read;
use std::cmp::*;

fn main(){
    let t_cases = 1;
    for _ in 0..t_cases{
        solve();
    }
}

fn solve(){
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut t = String::new();
    io::stdin().read_line(&mut t).unwrap();
    t = t.trim().to_owned();
    s = s.trim().to_owned();
    let (m,n) = (s.len(),t.len());
    let mut dp = vec![vec![0i32;n+1];m+1];
    let s = s.as_bytes();
    let t = t.as_bytes();
    for i in 1..(m+1){
        for j in 1..(n+1){
            if s[i-1] == t[j-1]{
                dp[i][j] = dp[i-1][j-1]+1;
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    // println!("{}",dp[m][n]);
    let mut res = String::new();
    let mut m = m;
    let mut n = n;
    while m>0 || n>0{
        if m==0 || (n>0 && dp[m][n-1]==dp[m][n]){
            // res.push(t[n-1] as char);
            n-=1;
        }else if n==0 || (m>0 && dp[m-1][n]==dp[m][n]){
            // res.push(s[m-1] as char);
            m-=1;
        }else{
            res.push(s[m-1] as char);
            m-=1;
            n-=1;
        }
    }
    println!("{}",res.chars().rev().collect::<String>());
}

Measured memory_bytes: 41212
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> H >> W;
	cout << (N - H + 1)*(N - W + 1) << endl;
	return 0;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector< pair<int, int> > AB(N);
  int A, B;
  for (int i = 0; i < N; ++i) {
    cin >> A >> B;
    AB[i] = make_pair(A, B);
  }

  sort(AB.begin(), AB.end());

  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    if (AB[i].second >= M) {
      ans += (long long) AB[i].first * M;
      break;
    } else {
      ans += (long long) AB[i].first * AB[i].second;
      M -= AB[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *r, *l, *p;
};

Node *root, *NIL;

Node *find(Node *u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->l;
    else u=u->r;
  }
  return u;
}

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->l;
    }else{
      x=x->r;
    }
  }

  z->p=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->l=z;
    }else{
      y->r=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->l);
  printf(" %d", u->key);
  inorder(u->r);
}

void preorder(Node *u){
  if(u==NIL)return;
  printf(" %d", u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  int n, i, x;
  string com;

  scanf("%d", &n);

  for(i=0;i<n;i++){
    cin>>com;
    if(com[0]=='f'){
      scanf("%d", &x);
      Node *t=find(root, x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }else if(com=="insert"){
      scanf("%d", &x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 22104
#include <stdio.h>
bool used[11]={0,0,0,0,0,0,0,0,0,0,0};int mn(int a, int b) {return (a<b)?a:b;}
void dfs(int v, int sz, int &ans, int here) {used[here]=1;if (!v && !sz) ans++;if (v>=0 && sz>0) for (int j=mn(mn(v,9),here);j>=0;j--) if (!used[j]) dfs(v-j,sz-1,ans,j);used[here]=0;}
int main() {int N,M,i;while (1) {scanf("%d %d",&N,&M);if (!N && !M) return 0;i=0;dfs(M,N,i,10);printf("%d\n",i);}}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end()
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

  int N, ans = 0;
  string s;  cin >> N >> s;
  for(int i = 0 ; i < 1000 ; i++){
    int c[3] = {i / 100, (i / 10) % 10, i % 10};
    int f = 0;
    for(int j = 0 ; j < N ; j++){
      if(s[j] == ('0' + c[f]))  f++;
      if(f == 3)  break;
    }
    if(f == 3)  ans += 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var w = readLine()!!.split(" ").map { it.toInt()}
    var l = 0
    var r = 0
    var lp = 0
    var rp = n-1
    repeat(n){
        if (l > r){
            r += w[rp]
            rp--
        }else{
            l += w[lp]
            lp++
        }
    }
    println(if (l > r) l - r else r - l)
}


Measured memory_bytes: 37924
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second


void solve()
{
    ll n,m;cin>>n>>m;
    if(min(m,n)==1)
    {
        if(max(m,n)==1)cout<<1<<endl;
        else if(max(m,n)==2)cout<<0<<endl;
        else cout<<max(n,m)-2<<endl;
    }
    else cout<<n*m-2*(n+m)+4<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

const int MAX_N = 100000 + 10;
int a[MAX_N];
ll ans[MAX_N];

int main2() {
  int N;
  cin >> N;
  REP(i, N) cin >> a[i];
  memset(ans, 0, sizeof(ans));
  vector< pair<int,int> > v;
  REP(i, N) v.emplace_back(a[i],i);
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  // REP(i, N) cout << "(" << v[i].first << "," << v[i].second << ")"; cout << endl;

  for (int i = 0, x = v[0].first, m = v[0].second; i < N; ) {
    while (i < N && v[i].first == x) {
      m = min(m, v[i].second);
      i++;
    }
    if (i == N) {
      ll add = (i) * (ll)(x - 0);
      ans[ m ] += add;
    } else {
      ll add = (i) * (ll)(x - v[i].first);
      ans[ m ] += add;
      x = v[i].first;
    }

    if (i == N) break;
  }

  REP(i, N) cout << ans[i] << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll d; cin >> d;
    vector<ll> ansl(365,-1);
    vector<ll> c(26);
    vector<ll> las(26,0);
    vec2(s,d,26,0);
    REP(i,26) cin >> c[i];
    REP(i,d)REP(j,26) cin >> s[i][j];
    ll con = 0;
    REP(i,d){
        ll ma = -1*INF;ll mind = -1;
        REP(j,26)if(ma<s[i][j]){
            ma=s[i][j];
            con-=c[j]*(i+1-las[j]);
            mind=j;
        }
        ansl[i]=mind;
        con+=c[mind]*(i+1-las[mind]);
        las[mind]=i+1;
    }
    
    REP(i,d) cout << ansl[i]+1 << endl;
}


Measured memory_bytes: 3644
using System;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            string t = Console.ReadLine();
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(t);
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
            }
            for (int i = n; i > 0; i--)
            {
                Console.Write(a[i - 1]);
                if (i == 1)
                {
                    break;
                }
                Console.Write(" ");
            }
            Console.WriteLine("");
        }
    }
}

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
typedef long long ll;
using namespace std;
typedef pair<int, int> ii;
#define MAXN 200200
#define INF 1001001001001001001LL

int n, m, nn = 1;
int l[MAXN], r[MAXN];
ll a[MAXN], pre;
vector<int> v[MAXN];
ll t[MAXN * 4], prop[MAXN * 4];
ll reza = 0LL;

void propaj(int cv, int lo, int hi)
{
  if (lo < hi) {
    prop[cv * 2] += prop[cv];
    prop[cv * 2 + 1] += prop[cv];
  }
  t[cv] += prop[cv];
  prop[cv] = 0;
}

void add(int cv, int le, int ri, int lo, int hi, ll val)
{
  propaj(cv, lo, hi);
  if (le > ri || lo > hi || le > hi || ri < lo) return;

  if (lo >= le && hi <= ri) {
    prop[cv] += val;
    propaj(cv, lo, hi);
    return;
  }

  int mid = (lo + hi) / 2;

  add(cv * 2, le, ri, lo, mid, val);
  add(cv * 2 + 1, le, ri, mid + 1, hi, val);
  t[cv] = max(t[cv * 2], t[cv * 2 + 1]);
}

ll maks(int cv, int le, int ri, int lo, int hi)
{
  propaj(cv, lo, hi);
  if (le > ri || lo > hi || le > hi || ri < lo) return -INF;

  if (lo >= le && hi <= ri) {
    return t[cv];
  }

  int mid = (lo + hi) / 2;

  ll lc = maks(cv * 2, le, ri, lo, mid);
  ll rc = maks(cv * 2 + 1, le, ri, mid + 1, hi);
  t[cv] = max(lc, rc);
  return t[cv];
}

int main()
{
  scanf("%d%d", &n, &m);
  for (int n2 = n; n2; n2 /= 2) nn *= 2;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%lld", &l[i], &r[i], &a[i]);
    l[i]--; r[i]--;
    v[l[i]].pb(i);
    v[r[i] + 1].pb(-i - 1);
  }
  for (int i = 0; i < n; i++) {//cout<<maks(1, 0, nn - 1, 0, i - 1)<<endl;
    for (int j: v[i]) {
      if (j >= 0) {
        add(1, l[j], r[j], 0, nn - 1, -a[j]);
        pre += a[j];
      }
      else {
        j = -j - 1;
        add(1, l[j], r[j], 0, nn - 1, a[j]);
        pre -= a[j];
      }
    }

    ll ri = max(maks(1, 0, i - 1, 0, nn - 1) + pre, pre);
    //cout<<ri<<' '<<pre<<'.'<<maks(1, 0, i - 1, 0, nn - 1)<<endl;
    add(1, i, i, 0, nn - 1, ri);
    reza = max(reza, ri);
  }
  printf("%lld\n", reza);
  return 0;
}


Measured memory_bytes: 22272
#include <stdio.h>

int main()
{
    int i, N, sum = 0, va[10];

    scanf("%d", &N);

    int N2 = N;
    for (i = 0; N > 0; i++) {
        va[i] = N % 10;
        N /= 10;
        sum += va[i];
    }

    if (N2 % sum == 0)
        printf("Yes");
    else
        printf("No");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int A[3][105],pr[105],suff[105];
int main ()
{
    int N;
    cin >> N;
    for(int i=1;i<=2;i++){
        for(int j=1;j<=N;j++)
            cin >> A[i][j];
    }
    for(int i=1;i<=N;i++)pr[i]=pr[i-1]+A[1][i];
    for(int i=N;i>=1;i--)suff[i]=suff[i+1]+A[2][i];
    int res=0;
    for(int i=1;i<=N;i++)
        res=max(res,suff[i]+pr[i]);
    cout<<res;
    return 0;
}
/*

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mk make_pair

int main()
{
	ll a;
	cin>>a;
	ll b=100,count=0;
	while(b<a)
	{
		b+=b/100;
		count++;
	}
	cout<<count<<endl;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<vector<UL>> E(N);
		vector<UL> P(N, (UL)-1);
		vector<UL> S;
		rep(i, N - 1) {
			UL a, b; cin >> a >> b; a--; b--;
			E[a].push_back(b);
			E[b].push_back(a);
		}
		queue<UL> Q; Q.push(0);
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			S.push_back(p);
			for (UL e : E[p]) {
				if (P[p] == e) continue;
				P[e] = p;
				Q.push(e);
			}
		}
		vector<vector<UL>> dp(N + 1);
		reverse(S.begin(), S.end());
		P[0] = N;
		rep(i, S.size()) {
			UL p = S[i];
			UL ans = 0;
			UL s = 0; for (UL d : dp[p]) s ^= d;
			ans = s + 1;
			dp[P[p]].push_back(ans);
		}
		if (dp[N][0] == 1) cout << "Bob" << endl;
		else cout << "Alice" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

int main() {
    int k, x;
    cin >> k >> x;
    if(500*k >= x){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int ans=0;
int a[200010];
vector<bool>v(200010,false);

bool check(int x){
  ans++;
  if(v[1]==true)return true;
  if(v[x]==false){
    v[x]=true;
    return check(a[x]);
  }else return false;

  return false;
}

int main(){

  int n;cin>>n;
  rep(i,0,n){
    cin>>a[i];
    a[i]--;
  }

  if(check(a[0]))out(ans-1)
  else out(-1)


  return 0;
}


Measured memory_bytes: 640