akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
	int l,r,T;
	cin>>l>>r;
	ll temp=r/2019-(l-1)/2019;
	if(temp!=0){
		cout<<0<<endl;
	}else{
		ll ans=2019;
		for(int i=l;i<=r;i++){
			for(int j=i+1;j<=r;j++){
				temp=1ll*i*j%2019;
				ans=min(ans,temp);
			}
		}
		cout<<ans<<endl;
	} 
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <set>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)

    #define INF 100000000
    #define MOD 100000007

    #define writeln(n) cout<<n<<endl

    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

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

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

    llong pownew(llong m, llong n) {
        if (n == 0) { return 1; }
        if (n % 2 == 0) { return pow(m*m, n/2); }
        return pow(m, n-1) * m;
    }

    bool isprime(int p) {
        if (p == 1) return false;
        for (int i = 2; i < p; i++) {
            if (p%i == 0) return false;
        }
        return true;
    }

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

    const int inf=100000000;

    long long modpow(long long a, long long n, long long mod) //a^n
    {
        long long res = 1;
        while (n > 0) {
            if (n & 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

    int gcd(int a, int b) {
        return b != 0 ? gcd(b, a % b) : a;
    }
    //setprecision(10);



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

        int m,d; cin>>m>>d;
        int cnt=0;
        if(d<22||m<4) cnt=0;
        else {
            for (int j = 4; j <= m; j++) {
                for (int i = 1; i <= d; i++) {
                    if((i/10)>=2&&(i%10)>=2) 
                    {
                        if (i < 100 && j == (i / 10) * (i % 10)) ++cnt;
                    }
                }
            }
        }
        cout<<cnt<<endl;

        return  0;
    }


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

int main(){
  int N ;
	cin >> N;
	
  vector<int64_t>number(87);
  
  number.at(0) = 2;
  number.at(1) = 1;

 	if(N>1){ 
  		for(int i = 2 ; i<=N ; i++){
  			number.at(i)=number.at(i-1)+number.at(i-2);
  		}
	 } 
  cout << number.at(N) << endl;
}

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

#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)

int main() {
    int N, Q, t, u, v, res;
    cin >> N >> Q;
    dsu d(N);
    REP(i, Q) {
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            res = d.same(u, v);
            cout << int(res) << endl;
        }
    }
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  string S; cin >> S;
  bool ok = false;
  if(S.at(0) == S.at(1)){
    if(S.at(2) == S.at(3) && S.at(0) != S.at(2)){
      ok = true;
    }
  } else if(S.at(0) == S.at(2)){
    if(S.at(1) == S.at(3) && S.at(0) != S.at(1)){
      ok = true;
    }
  } else if(S.at(0) == S.at(3)){
    if(S.at(1) == S.at(2) && S.at(0) != S.at(1)){
      ok = true;
    }
  }
  if(ok){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<long long> x(n), y(n), z(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    long long res = 0;
    for (int i = 0; i < 8; i++) {
        vector<long long> s(n);
        for (int j = 0; j < n; j++) {
            s[j] = ((i & 0b001) == 0 ? 1 : -1) * x[j]
                    + ((i & 0b010) == 0 ? 1 : -1) * y[j]
                    + ((i & 0b100) == 0 ? 1 : -1) * z[j];
        }

        sort(s.begin(), s.end(), greater<long long>());

        long long r = 0;
        for (int j = 0; j < m; j++) {
            r += s[j];
        }

        if (res < r) {
            res = r;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  char a[3];
  std::cin >> a;
    
  bool _1 = a[0] == 'R';
  bool _2 = a[1] == 'R';
  bool _3 = a[2] == 'R';
  
  if (_1 && _2 && _3){
    std::cout << '3' << std::endl;
  }else if( (_1 && _2) || (_2 && _3) ){
    std::cout << '2' << std::endl;
  }else if(_1 || _2 || _3){
    std::cout << '1' << std::endl;
  }else{
    std::cout << '0' << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#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>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#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 <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> v(100010);
  rep(i, n){
    ll kari;
    cin>>kari;
    v.at(i)=kari;
  }
  set<ll> S;
  rep(i, m){
    ll a, b;
    cin>>a>>b;
    if(v.at(a-1)>=v.at(b-1)){
      S.insert(b);
    }
    if(v.at(a-1)<=v.at(b-1)){
      S.insert(a);
    }
  }
  cout<<n-sz(S)<<endl;
    

}


Measured memory_bytes: 6956
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int count = 0;
    vector<int> v(m);
    vector<int> d(m-1);
    rep(i, m) cin >> v[i];
    sort(v.rbegin(), v.rend());
    rep(i, m-1) d[i] = v[i] - v[i+1];
    sort(d.rbegin(), d.rend());
    rep(i,m-1) if (i >= n-1) count += d[i];
    cout << count << endl;
    return 0;
}


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

int32_t main(){
     int n; cin>>n;
     if(n%2){
          cout<<0;
     }
     else{
          int cnt=0;
          int curr=5;
          while(1){
               if(curr>n)break;
               cnt+=(n/curr)/2;
               curr=curr*5;
          }
          cout<<cnt;
     }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		long[] sum=new long[32];
		sum[0]=1;
		sum[1]=1;
		sum[2]=2;
		for(int i=3; i<=31; i++) {
			sum[i]=sum[i-1]+sum[i-2]+sum[i-3];
		}
		while(true) {
			int a=sc.nextInt();
			if(a==0) {
				System.exit(0);
			}
			else {
				long yrs=(sum[a]+3649)/3650;
				pl(yrs);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}



Measured memory_bytes: 24452
import bisect
import operator
import collections
import sys
input = sys.stdin.readline


class RAQ():
    
    def __init__(self, size):
        """初期化"""
        self.size = size
        self.sub = [0 for i in range(size + 1)]
        self.r = 0
        self.v = 0
    
    @classmethod
    def from_array(cls, a):
        st = cls(len(a))
        for i, x in enumerate(a):
            st.add(i, i+1, x)
        return st

    def add(self, a, b, value):
        """区間[a, b) に対する加算"""
        if a > b:
            raise ValueError("a must be less than equal b.")
        self.sub[a] += value
        self.sub[b] -= value

    def get(self, key):
        """値の取得"""
        if key < self.r - 1:
            self.r = 0
            self.v = 0
        for i in range(self.r, key):
            self.v += self.sub[i]
        self.r = key
        return self.v + self.sub[key]


def read():
    N, D, A = list(map(int, input().strip().split()))
    XH = list()
    for i in range(N):
        x, h = list(map(int, input().strip().split()))
        XH.append((x, h))
    return N, D, A, XH


def solve(N, D, A, XH):
    XH = sorted(XH)
    X = [x for x, h in XH]
    H = [h for x, h in XH]

    st = RAQ.from_array(H)

    ans = 0
    i = 0
    while i < N:
        x = XH[i][0]
        h = st.get(i)
        c = h // A + (h % A > 0)
        ans += c
        v = c * A
        lidx = bisect.bisect_left(X, x)
        ridx = bisect.bisect_left(X, x + 2 * D + 1)
        st.add(lidx, ridx, -v)
        m = -1
        i += 1
        while i < N:
            h = st.get(i)
            if h > 0:
                break
            i += 1
    return ans


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 43092
#include<stdio.h>
int main(void){
	int l,s,cnt=0,n,sort[5],i,j;
	while(scanf("%d",&n),n!=0000){
		cnt=0;
		while(n!=6174 && n%1111!=0){
			sort[0]=n/1000;
			sort[1]=n/100-sort[0]*10;
			sort[2]=n/10-(sort[0]*100+sort[1]*10);
			sort[3]=n%10;
			for(i=0;i<4;i++){
				for(j=i+1;j<4;j++){
					if(sort[i]<sort[j]){
					 	sort[4]=sort[i];
					 	sort[i]=sort[j];
					 	sort[j]=sort[4];
					}
				}
			}
			l=sort[0]*1000+sort[1]*100+sort[2]*10+sort[3];
			s=sort[3]*1000+sort[2]*100+sort[1]*10+sort[0];
			n=l-s;
			cnt++;
		}
		if(n%1111==0)printf("NA\n");
		else printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
constexpr int ceil(int a, int b)
{
    return (a + b - 1) / b;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;
    cout << ceil(n, 2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner teclado = new Scanner(System.in);
		int a, p;
		a=teclado.nextInt();
		p=teclado.nextInt();
		if(a >=0 && p >= 0 && a <=100 && p <= 100) {
			
				System.out.println(((a*3)+p)/2);
			}
		
		}
	}

Measured memory_bytes: 21076
package main
import "fmt"
var S, T string

func main() {
	fmt.Scanf("%s", &S)
	fmt.Scanf("%s", &T)
	m := len(S)
  	cnt := 0
  	for i:=0; i<m; i++ {
      	if S[i] == T[i] {
      		cnt++
        }	
  	}
  	fmt.Println(len(S) - cnt)
}


Measured memory_bytes: 4584
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }

ll comb(ll n, ll r){ // nCr
	ll ans = 1;
	REP(i,r) ans *= n - i;
	REP(i,r) ans /= r - i;
	return ans;
}

int main() {
	// 入力
	ll N;
	cin >> N;
 
	// 解法
	ll sosuu[15] = {2,3,5,7,11
					,13,17,19,23,29,
					31,37,41,43,47};
	ll count[15] = {0};
	REP(i,15){
		ll power = 1;
		while(pow(sosuu[i],power)<=N){
			// printf("%lld \n", pow(sosuu[i],power));
			count[i] += N/pow(sosuu[i],power);
			power++;
		}
		// printf("%lld: %lld\n", sosuu[i], count[i]);
	}
	// REP(i,15) printf("%lld: %lld\n", sosuu[i], count[i]);
	// p**4*q**4*r*2, p**14*q**4, p**24*q**2, p**74
	ll ans = 0; // 考えうる組み合わせの数
	for (ll p = 0; p < 15; ++p){
		for (ll q = 0; q < 15; ++q){
			for (ll r = 0; r < 15; ++r){
				if (count[p]>=4 & count[q]>=4 & count[r]>=2
					& p<q & p!=r & q!=r
				) ans++;
			}
		}
	}
	for (ll p = 0; p < 15; ++p){
		for (ll q = 0; q < 15; ++q){
			if (count[p]>=14 & count[q]>=4 & p!=q) ans++;
		}
	}
	for (ll p = 0; p < 15; ++p){
		for (ll q = 0; q < 15; ++q){
			if (count[p]>=24 & count[q]>=2 & p!=q) ans++;
		}
	}
	for (ll p = 0; p < 15; ++p){
			if (count[p]>=74) ans++;
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 256
while True:
    data=list(map(int,input().split()))
    if data[0]==0 and data[1]==0:break
    cnt=0
    
    for i in range(1,data[0]-1):
        for j in range(i+1,data[0]):
            for k in range(j+1,data[0]+1):
                if i+j+k==data[1]:cnt+=1
    
    print(cnt)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n, h[100007], dp[100007], k;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> h[i];
	}
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		dp[i] = 2e9;
		for(int j = i - 1; j >= max(1, i - k); j --){
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n];
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 25 21:15:35 2020

@author: NEC-PCuser
"""

N = int(input())
A = list(map(int, input().split()))

money = 1000
kabu = 0

for i in range(N):
    if (i <= N - 2 and A[i] > A[i + 1]):
        money += kabu * A[i]
        kabu = 0
    elif (i <= N - 2 and kabu == 0):
        kabu = money // A[i]
        money = money % A[i]

if (kabu != 0):
    money += kabu * A[N - 1]

print(money)

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

const int MAX = 1001001;
int main()
{
	int n, boss[MAX];
	cin >> n;
	
	
	for (int i=2; i<=n; ++i) {
		int a;
		cin >> a;
		boss[a]++;
	}
	
	for (int i=1; i<=n; ++i) {
		cout << boss[i] << "\n";
	}
	return 0; 
}



Measured memory_bytes: 4384
//AtCoder ABC119 B - Digital Gifts
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    vector<pair<string,double>> xun(N);
    for(auto&& xu:xun){
        cin>>xu.second>>xu.first;
    }
    double ans=0;
    for(const auto& xu:xun){
        if(xu.first=="JPY")ans+=xu.second;
        else ans+=xu.second*380000;
    }
	cout << fixed << std::setprecision(10) << ans << endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;;
	vector<P> A[N];
	rep(i,N){
		int t; cin >> t;
		rep(j,t){
			int x,y; cin >> x >> y;
			A[i].push_back(P(x-1,y)); 
		}
	}	

	int ans = 0;
	for(int bit=0; bit<(1<<N); bit++){
		bool flag = true;
		for(int i=0; i<N; i++){
			if(bit&(1<<i)){
				for(P u : A[i]){
					if(u.second){
						if( !(bit&(1<<u.first)) ){flag=false; break;}
					}else{
						if(bit&(1<<u.first)){flag=false; break;}
					}
				}
				if(!flag)break;
			}
		}
		if(flag){ ans = max(ans,__builtin_popcount(bit)); }
	}
	cout << ans << endl;
	
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;

struct res{
	long long int x,y;
};


long long int two[80]={1};
const long long int mod=1000000007;
int main(){
	queue<res>que;
	long long int n,m,a[200005],cou=0,L[200005],R[200005],D[200005],x[200005];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		
	}
	
	for(int i=1;i<n;i++){
		res tmp;
		if(a[i]>a[i+1]&&a[i+1]>=0){
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			cou++;
			a[tmp.x]+=a[tmp.y];
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]>=0&&abs(a[i+1])<=a[i]){
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			cou+=2;
			a[tmp.x]+=a[tmp.y];
			a[tmp.x]+=a[tmp.y];
		}
	}
	
	for(int i=n-1;i>=1;i-=1){
		res tmp;
		if(a[i]>a[i+1]&&a[i+1]<0&&a[i]>=0&&abs(a[i+1])>a[i]){
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			cou+=2;
			a[tmp.x]+=a[tmp.y];
			a[tmp.x]+=a[tmp.y];
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]<0){
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			cou++;
			a[tmp.x]+=a[tmp.y];
		}
	}
	for(int i=1;i<n;i++){
		res tmp;
		if(a[i]>a[i+1]&&a[i+1]>=0){
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			cou++;
			a[tmp.x]+=a[tmp.y];
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]>=0&&abs(a[i+1])<=a[i]){
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			cou+=2;
			a[tmp.x]+=a[tmp.y];
			a[tmp.x]+=a[tmp.y];
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]>=0&&abs(a[i+1])>a[i]){
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			cou+=2;
			a[tmp.x]+=a[tmp.y];
			a[tmp.x]+=a[tmp.y];
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]<0){
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			cou++;
			a[tmp.x]+=a[tmp.y];
		}
	}
	cout<<cou<<endl;
	for(int i=0;i<cou;i++)
	{
		res tmp=que.front();
		cout<<tmp.y<<" "<<tmp.x<<endl;
		
		que.pop();
	}
	
}


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

int main() {
  string a;
  int A,cou=0;
  cin>>A>>a;
  A-=2;
  for(int i=0;i<A;i++){
    if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C'){
      cou++;
    }
  }
  cout<<cou<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int R;
    cin >> R;

    if(R < 1200){
        cout << "ABC" << endl;
    }else if(R < 2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }

}

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

int w, h, n;
int sx, sy, gx, gy;
int t[102][102];

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

bool check(int x, int y, int c){
  if(x == gx && y == gy) return true;

  t[y][x] = -1;

  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(nx < 0 || w <= nx || ny < 0 || h <= ny || t[ny][nx] != c) continue;
    if(check(nx, ny, c)) return true;
  }

  return false;
}

void putBlock(int c, int d, int x, int y){
  int addX = (d == 0 ? 4 : 2);
  int addY = (d == 0 ? 2 : 4);

  for(int i = y; i < y + addY; i++){
    for(int j = x; j < x + addX; j++){
      t[i][j] = c;
    }
  }
}

int main(){
  while(cin >> w >> h, w || h){
    cin >> sx >> sy; sx--; sy--;
    cin >> gx >> gy; gx--; gy--;
    cin >> n;

    memset(t, -1, sizeof(t));

    for(int i = 0; i < n; i++){
      int c, d, x, y;
      cin >> c >> d >> x >> y;

      x--;
      y--;
      putBlock(c, d, x, y);
    }

    /*
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        printf("%2d", t[i][j]);
      }
      cout<<endl;
    }
    */

    if(t[sy][sx] != -1 && check(sx, sy, t[sy][sx])){
      cout << "OK\n";
    }
    else{
      cout << "NG\n";
    }
  }
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(int)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef long double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int SIZE=2*1e5;
const int INF=1LL<<30;
const LL p=7+1e9;
int main(){
	string s;
	cin >> s;
	int ans=0;
	char now='A';
	REP(i,s.size()){
		if(now>=s[i]) ans++;
		now=s[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3156
N,M = map(int,input().split())

w = [[0 for i in range(N)] for j in range(N)]
for i in range(0,M):
	a,b = map(int,input().split())
	w[a-1][b-1] += 1
	w[b-1][a-1] += 1


for i in range(0,N):
	sum = 0
	for j in range(0,N):
		sum += w[i][j]
	print(sum)


Measured memory_bytes: 3060
import sys

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(C)] for r in range(R)] for i in range(4)]
    DP[0][0][0] = 0
    for r in range(R):
        for c in range(C):
            for i in range(4):
                if DP[i][r][c] > -1:
                    if r + 1 < R: 
                        DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c])
                    if c + 1 < C: 
                        DP[i][r][c+1] = max(DP[i][r][c+1], DP[i][r][c])
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c] + item[r][c])
                        if c + 1 < C: DP[i+1][r][c+1] = max(DP[i+1][r][c+1], DP[i][r][c] + item[r][c])

    ans = DP[3][R-1][C-1]
    for i in range(3): ans = max(ans, DP[i][R-1][C-1] + item[R-1][C-1])
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 467568
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll X, A;
    cin >> X >> A;
    cout << (X < A ? 0 : 10) << endl;
    return 0;
}


Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define ll  long long
#define all(v) v.begin(), v.end()
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<b;++i)
#define repb(i,a,b) for(LL i=a;i>b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL r,c,k,a[3005][3005],dp[3005][3005][5];

LL mx(LL i, LL j) {
	LL ret = dp[i][j][3];
	rep(k,0,3) ret = max(ret, dp[i][j][k]);
	return ret;
}

int main()
{
	FIO;
	cin >> r >> c >> k;
	while(k--) {
		LL x, y, z;
		cin >> x >> y >> z;
		a[x][y] = z;
	}
	rep(i,1,r+1) rep(j,1,c+1) {
		dp[i][j][0] = max(dp[i][j-1][0], mx(i-1, j));
		if(a[i][j] > 0) {
			dp[i][j][1] = max(dp[i][j-1][1], max(dp[i][j-1][0], mx(i-1, j)) + a[i][j]);
			dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + a[i][j]);
			dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + a[i][j]);
		}
		else {
			dp[i][j][1] = dp[i][j-1][1];
			dp[i][j][2] = dp[i][j-1][2];
			dp[i][j][3] = dp[i][j-1][3];
		}
	}
	cout << mx(r, c) << endl;
}

Measured memory_bytes: 426204
#include<stdio.h>
#include<stdlib.h>
int main(void)
{int n,t=0,q,i;
int *p; 
scanf("%d",&n);
p=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&p[i]);
for(q=n-1;q>=0;q=q-2)
printf("%d ",p[q]);
if(n%2==1)
t=1; 
for(;t<n;t=t+2)
printf("%d ",p[t]);
 
return 0;
} 

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

int main() {
  string s;
  int c;
  cin >> s;
  if (s.at(0) == '1') {
    c++;
  }
    
  if (s.at(1) == '1') {
    c++;
  }
  
    
  if (s.at(2) == '1') {
    c++;
  }

  cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a<b)
        cout << "a < b";
    else if(a==b)
        cout << "a == b";
    else
        cout << "a > b";
    cout << endl;
    return 0;
} 


Measured memory_bytes: 3076
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N, M;
   cin >> N >> M;
   vector<int> pos(N,0);
   int favs[N][M];
   for(int i = 0 ; i <N; i++){
      for(int j = 0; j <M; j++){
         cin >> favs[i][j];
         favs[i][j]--;
      }
   }
   vector<bool> used(M,false);
   int ans = N;
   for(int j = 0 ; j < M; j++){
      vector<int> cnt(M,0);
      int target = 0;
      int m=0;
      for(int i = 0 ; i <N; i++){
         int f = favs[i][pos[i]];
         cnt[f]++;
         if(cnt[f]>m){
            m=cnt[f];
            target = f;
         }
      }
      // delete target
      //cout << m << " " << target << endl;
      used[target]=true;
      ans = min(m,ans);
      if(j!=M-1){
         for(int i = 0 ; i <N; i++){
            while(used[favs[i][pos[i]]]==true) pos[i]++; 
         }
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char grid[100][100];
int w,h;
int ans=0;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
bool searched[100][100];
int a=0,b=0;

bool inrange(int x,int y){
  if(x<0||y<0||x>=h||y>=w) return false;
  else return true;
}

void search(int x,int y){
  if((grid[x][y]=='.'||grid[x][y]=='@')&&searched[x][y]==false&&inrange(x,y)){
	searched[x][y]=true;
	ans++;
	//	cout <<x <<' '<<y << endl;
	  REP(i,4) {
	  search(x+dx[i],y+dy[i]);
	}
  }
}

int main(){
  while(1){
	cin >> w >> h;
	if(w==0&&h==0) break;
	ans = 0;
	REP(i,h){
	  REP(j,w){
		cin >> grid[i][j];
		searched[i][j]=false;
		if(grid[i][j]=='@'){
		  a=i;
		  b=j;
		}
	  }
	}
	search(a,b);

	cout<<ans<<endl;
  }
}

Measured memory_bytes: 1176
def partions(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d

def main():
    N=int(input())
    A=partions(N)
    if len(A)%2==1:
        print(2*A[(len(A)-1)//2]-2)
    else:
        print(A[len(A)//2-1]+A[len(A)//2]-2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define MOD 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && b == c)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    void run(){
	while(sc.hasNext()){
	    System.out.println(sc.nextDouble()*sc.nextDouble()/3.305785);
	}
    }
}

Measured memory_bytes: 18372
n, k = map(int, input().split())
s = input()

i = 0
x = 0

cumulative = [0]

while i < n:
    i0 = i
    x = s[i]
    while i < n and x == s[i]:
        i += 1
    cumulative.append(cumulative[-1] + i - i0)


x = s[0] == '1'
ans = 0
m = len(cumulative)
for i in range(1, m):
    j = i + 2 * k if x else i + 2 * k - 1
    ans = max(ans, cumulative[min(j, m-1)] - cumulative[i-1])
    if m <= j:
        break
    x = not x
print(ans)


Measured memory_bytes: 78104
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#define endl "\n"
typedef long long int ll;
typedef unsigned long long int ull;
typedef float fl;
typedef long double ld;
using namespace std;

int GCD(int a,int b)
{
    if (b==0) return a; else return GCD(b,a%b);
}

void solve()
{   int k; cin >> k; ll sum=0;
    for (int a=1;a<=k;++a) {
        for (int b=1;b<=k;++b) {
            for(int c=1;c<=k;++c) {
                sum+=GCD(GCD(a,b),c);
    }}}
            cout << sum;
}

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


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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && c <= b) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    string s, t;
    cin >> s >> t;

    map<char, char> mp1, mp2;
    REP(i, s.size()){
        auto itr = mp1.find(s[i]);
        if(itr == mp1.end()){
            mp1[s[i]] = t[i];
        }else if(mp1[s[i]] != t[i]){
            cout << "No" << endl;
            return 0;
        }

        itr = mp2.find(t[i]);
        if(itr == mp2.end()){
            mp2[t[i]] = s[i];
        }else if(mp2[t[i]] != s[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	vector<int>sigfront(n);
	sigfront.at(0) = 0;
	for (int i = 1; i < n; i++) {
		if (i == 1)sigfront.at(i) = a.at(0);
		else sigfront.at(i) = __gcd(sigfront.at(i - 1), a.at(i - 1));
	}
	vector<int>sigback(n);
	sigback.at(0) = 0;
	for (int i = 1; i < n; i++) {
		if (i == 1)sigback.at(i) = a.at(n - 1);
		else sigback.at(i) = __gcd(sigback.at(i - 1), a.at(n - i));
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (sigfront.at(i) == 0 || sigback.at(n - 1 - i) == 0)ans = max(ans, max(sigfront.at(i), sigback.at(n - 1 - i)));
		else ans = max(ans, __gcd(sigfront.at(i), sigback.at(n - 1 - i)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {

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

        System.out.println(dfs(H));

    }

    static private long dfs(long h){
        if(h==1) return 1;

        long time = dfs(h/2)*2 + 1;

        return time;
    }


}


Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
#include <string.h>

int main() {
	int i, j, k;
	long long int l = 0;
	int m, g, n, q;
	long long int f;
	int h;
	int a[110000];

	scanf("%d %d", &h, &n);


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

	if (l < h) {
		printf("No");
	}
	else {
		printf("Yes");
	}



	return 0;
}

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

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

int dp[200010][3];
//dp[i][pre] i文字目まで使っていて、以前にpre文字分使っている
//i文字目というのは、s[i-1]文字目までに該当することに注意！！

int main() {

    string s; cin >> s;
    int n = s.length();
    s += "#####"; //文字列を長くして範囲外参照が起きないように

    for (int i = 0; i < n+1; ++i) {
        for (int j = 0; j < 3; ++j) {
            dp[i][j] = -INF;
        }
    }

    dp[0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int pre = 0; pre < 3; ++pre) {
            for (int j = 1; j < 3; ++j) {
                if (0 <= dp[i][pre]) { //一個前の文字列が作られている
                    if (pre == j) { //一個前の文字列とこれから作る文字列の長さが同じ
                        if (j == 1) {
                            if (s[i-1] == s[i]) continue; //一個前の文字列を同じだとダメ
                        } else {
                            if (s[i-2] == s[i] && s[i-1] == s[i+1]) continue; //一個前の文字列を同じだとダメ
                        }
                    }

                    dp[i+j][j] = max(dp[i+j][j], dp[i][pre] + 1);
                }
            }
        }
    }

    cout << max(dp[n][1], dp[n][2]) << endl;
}

Measured memory_bytes: 2948
#include<stdio.h>

#define MAX 1000000000

int min(int a, int b) {
    if (a < b)
        return a;
    return b;
}

int max(int a, int b) {
    if (a > b)
        return a;
    return b;
}

int abs(int a){
    if (a < 0)
        return -1*a;
    return a;
}

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

    int dp[100009][3];

    int act[100009][3];

    for (int i=0; i < n; i++){
        scanf("%d %d %d", &act[i][0], &act[i][1], &act[i][2]);
        dp[i][0] = dp[i][1] = dp[i][2] = 0;
    }
    dp[0][0] = act[0][0];
    dp[0][1] = act[0][1];
    dp[0][2] = act[0][2];

    for (int i=1; i < n; i++){
        dp[i][0] = act[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = act[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = act[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }
    printf("%d\n", max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])));

    return 0;
}


Measured memory_bytes: 4072
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;
typedef long long ll;
double EPS=1e-10;
typedef pair<int,int> pii;
bool EQ(double a,double b){
	return abs(a-b)<EPS;
}

bool f[300010];
void solve(){
	for(int i=0;i<300010;i++) f[i]=1;
	vector<int> v;
	int d[]={1,6};
	v.push_back(6);
	bool ok=1;
	for(int i=1;ok;i++){
		for(int j=0;j<2;j++){
			if(i*7+d[j]>300000){
				ok=0;
				break;
			}
			v.push_back(i*7+d[j]);
		}
	}
	for(int i=0;i<v.size();i++){
		if(f[v[i]]){
			for(int j=2;j*v[i]<=300000;j++) f[j*v[i]]=0;
		}
	}
	//for(int i=0;i<v.size();i++) cout<<v[i]<<" "<<f[v[i]]<<endl;
	int n;
	while(cin>>n,n!=1){
		vector<int> ans;
		for(int i=0;i<v.size();i++){
			if(!(n%v[i])&&f[v[i]]) ans.push_back(v[i]);
		}
		cout<<n<<": ";
		for(int i=0;i<ans.size()-1;i++){
			cout<<ans[i]<<" ";
		}
		cout<<ans[ans.size()-1]<<endl;
	}
}

int main(){
	solve();
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N, M;
	cin >> N >> M;

	if( N >= M ) {
		cout << "0\n";
	}
	else {
		vector<int> X( M );
		for( auto& v: X ) { cin >> v; }
		sort( X.begin(), X.end() );

		vector<int> Y( M-1 );
		for( int i = 0; i < M-1; ++i ) {
			Y[i] = X[i+1] - X[i];
		}
		sort( Y.begin(), Y.end() );

		int result = 0;
		for( int i = 0; i < M-N; ++i ) {
			result += Y[i];
		}

		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N, vector<int>());
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    int ok = 0;
    for(auto v : G[0]) {
        for(auto nv : G[v]) {
            if(nv == N - 1)
                ok = 1;
        }
    }
    if(ok) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

ll N,M,Q,ans = 0;
ll a[60],b[60],c[60],d[60];
ll A[60];

void dfs(ll *B,ll n){
    if(n - 1 == N){
        ll res = 0;
        rep(i,Q){
            if(B[b[i]] - B[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans,res);
    }else{
        FOR(i,B[n-1],M){
            B[n] = i;
            dfs(B,n+1);
        }
    }
    return ;
}

int main(){
    cin >> N >> M >> Q;
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(A,1);
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 45
#define BASE 2

int V,E;
int start,goal;
int ans;
vector<int> G[NUM];
bool used[NUM];
int counted[NUM]; //★★何番目のノードを探索する際に、コスト計上したか★★
int table[NUM];

void recursive(int node_id,int num_passed,int sum_cost){ //num_passed:0オリジンで、今回が何番目のノードか

	if(sum_cost >= ans)return;

	if(node_id == goal){

		ans = min(ans,sum_cost);
		return;
	}

	vector<int> WORK;
	int tmp_cost,next_node;
	for(int i = 0; i < G[node_id].size(); i++){ //次のノードのループ

		tmp_cost = sum_cost;
		next_node = G[node_id][i];
		if(used[next_node] == true || num_passed-counted[next_node] >= BASE)continue;
		used[next_node] = true;
		WORK.clear();

		//次に訪問するノードの隣接ノードのコストを計上する
		for(int k = 0; k < G[next_node].size(); k++){
			if(counted[G[next_node][k]] >= 0)continue;
			counted[G[next_node][k]] = num_passed;
			WORK.push_back(G[next_node][k]);
			tmp_cost += table[G[next_node][k]];
		}
		recursive(next_node,num_passed+1,tmp_cost);

		used[next_node] = false;
		for(int k = 0; k < WORK.size(); k++){
			counted[WORK[k]] = -1;
		}
	}
}


int main(){

	scanf("%d %d",&V,&E);

	start = 0;
	goal = V-1;

	for(int i = 0; i < V; i++){
		scanf("%d",&table[i]);
	}

	int from,to;

	for(int loop = 0; loop < E; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
		G[to].push_back(from);
	}

	ans = BIG_NUM;

	for(int i = 0; i < V; i++){
		used[i] = false;
		counted[i] = -1;
	}

	used[start] = true;
	counted[start] = 0;
	int first_cost = table[start];

	//スタートの隣接辺のコストを計上する(★固定★)
	for(int i = 0; i < G[start].size(); i++){
		counted[G[start][i]] = 0;
		first_cost += table[G[start][i]];
	}

	vector<int> WORK;
	int tmp_cost,next_node;
	for(int i = 0; i < G[start].size(); i++){ //次のノードのループ

		tmp_cost = first_cost;
		next_node = G[start][i];
		used[next_node] = true;
		WORK.clear();

		//次に訪問するノードの隣接ノードのコストを計上する
		for(int k = 0; k < G[next_node].size(); k++){
			if(counted[G[next_node][k]] >= 0)continue;
			counted[G[next_node][k]] = 1;
			WORK.push_back(G[next_node][k]);
			tmp_cost += table[G[next_node][k]];
		}
		recursive(next_node,2,tmp_cost);

		used[next_node] = false;
		for(int k = 0; k < WORK.size(); k++){
			counted[WORK[k]] = -1;
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3312
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B && B == C){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    S = input()
    
    #solve
    N = len(S)
    cnt=0
    ans=0
    for i in range(N):
        if S[i]=='S':
            cnt+=1
        else:
            if cnt:
                cnt-=1
                ans+=2
    print(N-ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 9292
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		long count=0,sum=0,res=0;
		Map<Long, Integer> map = new TreeMap<Long,Integer>();
		for(int i=0;i<n;i++) {
			long key=sc.nextLong();
			int v=sc.nextInt();
			if(map.get(key)==null) {
				map.put(key,v);
			}else {
				map.put(key, map.get(key)+v);
			}
		}
		for(long buff : map.keySet()) {
			count+=map.get(buff);
			if(count<m) {
				sum+=map.get(buff)*buff;
			}else {
				sum+=(map.get(buff)-(count-m))*buff;
				break;
			}
			//System.out.println(buff+" "+map.get(buff));
		}
		System.out.println(sum);
	}
}



Measured memory_bytes: 89748