akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

//-----CODE------//
void solve(void)
{ 
  int X;
  cin>>X;
  int S = 100;
  int ANS = 0;
  while( S < X)
  {
    double Y = S;
    Y *= 1.01;
    S = (int)Y;
    // DEBUG(X);
    ANS++;
  }
  cout<<ANS<<endl;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define get(a,t) get<a>(t)
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const int INF=1e18;

void dprint(string s) { cout << endl;}
void dprint() { cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w=s.find(','); cout <<"["<< s.substr(0,w) << ": " << t << "] " ; dprint(s.substr(w+1, sz(s)-w), u...);} 


#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...); 
#endif
const int N=100005;

int32_t main()
{
	IOS;
	int a,b,n; cin>>a>>b>>n;
	int i=min(n,b-1);
	cout<<(i*a)/b-a*(i/b);
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip> // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <bits/stdc++.h>
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;
 
using namespace std;

int main(void){

  int a,b;
  cin >> a >> b;
  
  long long int mul = 1;

  if(a <= 0 && 0 <= b){
    cout << "Zero" << endl;
  }else if(a <= 0 && b <= 0){
    if((b-a) % 2 == 0){
      cout << "Negative" << endl;
    }else{
      cout << "Positive" << endl;
    }
  }else{
    cout << "Positive" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import bisect


def GETCOUNT(A,border,N):
    count = 0
    for i in range(N):
        index = bisect.bisect_left(A,border-A[i])
        count +=N-index
    return count

def get_ans(A,smt,border,N):
    sm=0
    for i in range(N):
        index = bisect.bisect_left(A,border-A[i])
        sm+=(N-index)*A[i]

        if index==N:
            continue
        sm+=smt[index]

    return sm


def resolve():
    N,M = map(int,input().split())
    A=[int(i) for i in input().split()]
    A.sort()

    smt=[0]*N
    smt[-1]=A[-1]
    for i in range(N-2,-1,-1):
        smt[i]=smt[i+1]+A[i]

    lid = 0 
    lco = N*N

    rid = A[-1]*2 +1
    rco = 0

    center =0
    center_count =0
    cc=0
    while True:
        center=(lid+rid)//2
        center_count=GETCOUNT(A,center,N)


        if center_count > M:
            lid = center
            lco = center_count
        else:
            rid = center
            rco = center_count
        
        if rid == lid+1 and rco != M and lco !=M:
            cc=lid*(lco - M)
            center = lid
            break



        if center_count == M:
            break
    
    print(get_ans(A,smt,center,N)-cc)








if __name__ == "__main__":
    resolve()

Measured memory_bytes: 55104
#!/usr/bin/env python3
import sys


def solve(S: str):
    a = 0
    m_a = 0
    for s in S:
        if s == "R":
            a+=1
            m_a  = max(a,m_a)
        else:
            a=0
    print(m_a)


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main(){
  int h, w;
  while(cin>>h>>w, h){
    for(int i=0;i<h;i++){
      cout<<"#";
      for(int j=0;j+2<w;j++){
	if(i==0||i==h-1) cout<<"#";
	else cout<<".";
      }
      cout<<"#"<<endl;;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,x;
    cin>>n>>m>>x;
    ll skill[n+10][m+10];
    rep(i,n){
        rep(j,m){
            skill[i][j]=0;
        }
    }
    ll dbag[m],l=0;
    rep(i,m) dbag[i]=0;
    vec<ll> c(n);
    
    rep(i,n){
        cin>>c[i];
        l+=c[i];
        rep(j,m) {
            cin>>skill[i][j];
            dbag[j]+=skill[i][j];
        }
    }
    
    rep(i,m){
        if(dbag[i]<x){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    
    ll mini=l;
    
    for (ll bit=0; bit<(1<<n); ++bit) {
        ll sum=0,d=0;
        vec<ll> ans(m,0);
        for (ll i=0; i < n; ++i) {
            
            if (bit & (1<<i)) {// 列挙に i が含まれるか
                sum+=c[i];
                rep(j,m){
                    ans[j]+=skill[i][j];
                }
            }
        }
        rep(j,m){
            if(ans[j]>=x) d++;
        }
        if(d==m) mini=min(mini,sum);
        
    }
    
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
typedef long long ll;
ll base1=27,ms1=73939133,inv1;
ll base2=63,ms2=998244353,inv2;
ll h1[N],h2[N],m1[N],im1[N],p[N],m2[N],im2[N];
map<pair<int,int>,int>mp;
char s[N];
ll ksm(ll x,ll k,ll ms){
	ll t=1;
	for (;k;k>>=1){
		if (k&1) t=(t*x)%ms;
		x=(x*x)%ms;
	}
	return t;
}
int main(){
	inv1=ksm(base1,ms1-2,ms1);
	inv2=ksm(base2,ms2-2,ms2);
	int n; 
	scanf("%d",&n);
	m1[0]=m2[0]=im1[0]=im2[0]=1;
	for (int i=1;i<=n*2;i++){
		m1[i]=m1[i-1]*base1%ms1;
		m2[i]=m2[i-1]*base2%ms2;
		im1[i]=im1[i-1]*inv1%ms1;
		im2[i]=im2[i-1]*inv2%ms2;
	}
	p[0]=n;
	scanf("%s",s+1);
	for (int i=1;i<=n;i++){
		if (s[i]=='+'){
			p[i]=p[i-1]; 
			h1[i]=(h1[i-1]+m1[p[i]])%ms1;
			h2[i]=(h2[i-1]+m2[p[i]])%ms2;
		}else if (s[i]=='-'){
			p[i]=p[i-1];
			h1[i]=(h1[i-1]+ms1-m1[p[i]])%ms1;
			h2[i]=(h2[i-1]+ms2-m2[p[i]])%ms2;
		}else if (s[i]=='>'){
			p[i]=p[i-1]+1;
			h1[i]=h1[i-1]; h2[i]=h2[i-1];
		}else{
			p[i]=p[i-1]-1;
			h1[i]=h1[i-1]; h2[i]=h2[i-1];
		}
		mp[make_pair(h1[i],h2[i])]++;
	}
	ll ans=0;
	for (int i=1;i<=n;i++){
		int d=p[i-1]-n;
	    ll t1=h1[n],t2=h2[n];
		if (d>=0){ t1=t1*m1[d]%ms1; t2=t2*m2[d]%ms2;}
		else t1=t1*im1[-d]%ms1,t2=t2*im2[-d]%ms2;
		t1=(t1+h1[i-1])%ms1; t2=(t2+h2[i-1])%ms2;
		ans+=mp[make_pair(t1,t2)];
		mp[make_pair(h1[i],h2[i])]--;	
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 57856
class Stack(object):
    def __init__(self):
        self.container = []

    def __len__(self):
        return len(self.container)

    def push(self, elem):
        self.container.append(elem)

    def pop(self):
        index = len(self.container) - 1
        if index < 0:
            return None
        ret = self.container[index]
        del self.container[-1]
        return ret

    def compare(self, val):
        return self.container[-1] == val

if __name__ == '__main__':
    string = [int(i) for i in input()]
    ret = 0
    stack = Stack()
    stack.push(string[0])
    for s in string[1:]:
        if stack.__len__() == 0:
            stack.push(s)
            continue
        if stack.compare(s):
            stack.push(s)
        else:
            ret += 2
            stack.pop()

    print(ret)

Measured memory_bytes: 5532
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX/5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N;
	cin >> N;
	vector<vector<int>>D(N, vector<int>(2));
	rep(i, N) {
		cin >> D[i][0] >> D[i][1];
	}
	int cnt = 0;
	rep(i, N) {
		if (D[i][0] == D[i][1]) {
			cnt++;
		}
		else {
			cnt = 0;
		}
		if (cnt == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

int main() {
  int N, M, X, ans = 1e9;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M) { cin >> A[i][j]; }
  }

  rep(bit, (1 << N)) {
    vector<int> tmp(M);
    int cost = 0;
    rep(i, N) {
      if (bit & (1 << i)) {
        cost += C[i];
        rep(j, M) tmp[j] += A[i][j];
      }
    }
    bool f = true;
    rep(i, M) if (tmp[i] < X) f = false;
    if (f) ans = min(ans, cost);
  }

  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int main() {
	ll w, h, x, y; cin >> w >> h >> x >> y;
	double mw = w / 2.0, mh = h / 2.0, f = 0, ans = w * h / 2.0;
	if (x == mw && y == mh)f = 1;
	cout << ans << " " << f << endl;
	return 0;
}

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

int main() {
 string A;
 cin>> A;

 if(A[0]==A[1] && A[1]!=A[2] && A[2]==A[3])cout << "Yes" << endl;
  else if(A[0]==A[2] && A[1]!=A[2] && A[3]==A[1])cout << "Yes" << endl;
  else if(A[0]==A[3] && A[1]==A[2] && A[3]!=A[1])cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll pr[mx],ar[mx],br[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    faster();
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum=0;
    if((a+b)>=k)
        sum+=min(a,k);
    else
    {
        k-=(a+b);
       sum+=a+(-1*k);
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3624
using System;

namespace A___Round_One
{
    class Program
    {
        static void Main (string[] args)
        {
            var c = new int[] {1,2,3};
            var a = int.Parse (Console.ReadLine ());
            var b = int.Parse (Console.ReadLine ());
            for (var i = 0; i < 3; i++)
            {
                if (c[i] != a && c[i] != b)
                {
                    Console.WriteLine (c[i]);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 11092
if __name__ == '__main__':
    n = int(input())
    ans = {}
    ans["AC"] = 0
    ans["WA"] = 0
    ans["TLE"] = 0
    ans["RE"] = 0

    for i in range(n):
        s = input()
        ans[s]+=1
    print("AC x " + str(ans["AC"]))
    print("WA x "+str(ans["WA"]))
    print("TLE x "+str(ans["TLE"]))
    print("RE x "+str(ans["RE"]))


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

typedef long long int ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int Q;
    cin >> Q;
    
    priority_queue<ll> mx; // put the small
    priority_queue<ll, vector<ll>, greater<ll>> mn; // put the large
    ll sum_b = 0, cnt = 0, large = 0, small = 0;
    for (int q = 0; q < Q; q++){
        int a;
        cin >> a;

        if (a == 1){
            ll b, c;
            cin >> b >> c;
            mn.push(b);
            large += b;
            while((int) mn.size() - (int) mx.size() > 1){
                mx.push(mn.top());
                large -= mn.top();
                small += mn.top();
                mn.pop();
            }

            while(!mx.empty() && mn.top() < mx.top()){
                ll tmp1 = mn.top(), tmp2 = mx.top();
                mn.pop();
                mx.pop();
                mn.push(tmp2);
                mx.push(tmp1);
                large += tmp2 - tmp1;
                small += tmp1 - tmp2;
            }
            sum_b += c;
            cnt += 1;
        }
        else{
            ll x;
            if (cnt % 2 == 0)
                x = mx.top();
            else
                x = mn.top();

            cout << x << " " << large - x * (ll) mn.size() + x * (ll) mx.size() - small + sum_b << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int x,a,b;
	cin>>x>>a>>b;
	cout<<(abs(x-a)<abs(x-b)?"A":"B")<<endl;
}


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



int main() {
	int N, K, X, Y;
	int xcnt=0, ycnt=0;
	cin >> N >> K >> X >> Y;

	if (N <= K) {
		cout << X * N << endl;
	}
	else {
		xcnt = K; ycnt = N - K;
		cout << X * xcnt + Y * ycnt << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#YouTube解説
N = int(input())
A = [int(a) for a in input().split()]
A.insert(0, 0)
A.append(0)

total_money = 0
for i in range(N+1):
  total_money += abs(A[i] - A[i+1])

for j in range(1, N+1):
  ans = 0
  A_im1 = A[j-1]
  A_i = A[j]
  A_ip1 = A[j+1]
  ans = total_money - abs(A_im1 - A_i) - abs(A_i - A_ip1) + abs(A_im1 - A_ip1)
  print(ans)

Measured memory_bytes: 14048
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt

  val a = for (i <- 0 to n / 4;
               j <- 0 to n / 7) yield 4 * i + j * 7 == n

  println(if (a.exists(p => p)) "Yes" else "No")
}


Measured memory_bytes: 25528
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n, m; cin >> n >> m; std::vector<long> a(m), b(m), c(m);
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}
	
	std::vector<bool> li(n, false);
	std::vector<long> dist(n, 1e18);
	dist[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(dist[a[j]] != 1e18 and dist[b[j]] > dist[a[j]] - c[j]){
				dist[b[j]] = dist[a[j]] - c[j];
				if(i == n - 1) li[b[j]] = true;
			}
		}
	}
				
	
	if(li[n - 1]) cout << "inf" << endl;
	else cout << -dist[n - 1] << endl;
	return 0;
}


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

static const int MAX = 100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];

void floyd() {
  for ( int k = 0; k < n; k++ ) {
    for ( int i = 0; i < n; i++ ) {
      if ( d[i][k] == INFTY ) continue;
      for ( int j = 0; j < n; j++ ) {
        if ( d[k][j] == INFTY ) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j] );
      }
    }
  }
}

int main() {
  int e, u, v, c;
  cin >> n >> e;

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      d[i][j] = ( (i == j) ? 0 : INFTY );
    }
  }

  for ( int i = 0; i < e; i++ ) {
    cin >> u >> v >> c;
    d[u][v] = c;
  }

  floyd();

  bool negative = false;
  for ( int i = 0; i < n; i++ ) if ( d[i][i] < 0 ) negative = true;

  if ( negative ) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
        if ( j ) cout << " ";
        if ( d[i][j] == INFTY ) cout << "INF";
        else cout << d[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

#define int long long

using namespace std;

class Solver {
};
	vector<vector<int>> permutation(vector<int> factors, vector<bool> used, int cnt) {
		vector<vector<int>> ret;
		if (cnt == 1) {
			for (int i = 0; i < factors.size(); i++) {
				if (used[i])continue;

				vector<int> tmp({ factors[i] });
				ret.emplace_back(tmp);
			}
			return ret;
		}

		for (int i = 0; i < factors.size(); i++) {
			if (used[i])continue;

			used[i] = true;
			vector<vector<int>> tmp = permutation(factors, used, cnt - 1);
			for (int j = 0; j < tmp.size(); j++) {
				tmp[j].emplace_back(factors[i]);
				ret.emplace_back(tmp[j]);
			}
			used[i] = false;
		}

		return ret;
	}

	signed main() {
		while (true) {
			int n;
			cin >> n;
			if (n == 0)break;

			vector<string> strs(n);
			for (int i = 0; i < n; i++) {
				cin >> strs[i];
			}

			map<char, int> indexes;
			set<char> heads;
			for (int i = 0; i < n; i++) {
				int div = 1;
				for (int j = strs[i].size() - 1; j >= 0; j--) {
					if (indexes.find(strs[i][j]) == indexes.end()) {
						indexes.emplace(strs[i][j], 0);
					}
					if (i == n - 1)indexes[strs[i][j]] -= div;
					else indexes[strs[i][j]] += div;
					div *= 10;
					if (j == 0 && strs[i].size() > 1)heads.emplace(strs[i][j]);
				}
			}

			vector<int> factors(10);
			for (int i = 0; i < 10; i++)factors[i] = i;
			//vector<bool> used(10, false);
			//vector<vector<int>> pats = permutation(factors, used, indexes.size());
			int res = 0;
			do {
				int val = 0;
				int j = 0;
				bool valid = true;
				for (auto key : indexes) {
					if (factors[j] == 0 && heads.find(key.first) != heads.end()) {
						valid = false;
						break;
					}
					val += key.second * factors[j];
					j++;
				}
				if (valid && val == 0)res++;

			} while (next_permutation(factors.begin(), factors.end()));
			
			int divider = 1;
			for (int i = 1; i <= 10 - indexes.size(); i++)divider *= i;
			cout << res/divider << endl;
		}
	}


Measured memory_bytes: 3108
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var output = "";
  var N = nextInt();
  while(N != 0){
    if(N % 2 == 1 || N % 2 == -1){
      if(output.length % 2 == 1){
        N++;
      }else{
        N--;
      }
      output = "1" + output;
    }else{
      output = "0" + output;
    }
    N /= 2;
  }
  if(output == ""){
    output = "0";
  }
  myout(output);
}


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

using namespace std;

vector<pair<int,int>> mochila;
const int MAX = 1e5+5;
long long memo[105][MAX];
int s, n; 

long long dp(int size, int w){    
    if(size == 0 || w == 0) return 0;
    if(mochila[size-1].first > w){
        return dp(size-1, w);
    } else {
        if(memo[size][w] != -1) return memo[size][w];
        long long &ans = memo[size][w] = 0LL;
        ans =  max(dp(size-1, w), mochila[size-1].second + dp(size-1, w - mochila[size-1].first));
        return ans;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n >> s;
    memset(memo, -1, sizeof memo);
    mochila.resize(n);
    for(int i = 0; i <n; i++){
        cin >> mochila[i].first >> mochila[i].second;  
    }
    cout << dp(n,s);
    return 0;
}

Measured memory_bytes: 82304
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        int co = 0;
        for(int i=1; i<s.Length; i++) {
            if(s[i-1] != s[i]) co++;
        }

        return co;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 11232
#include <iostream>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    if(n%2==0){
        if(n/2 >= k){
            puts("YES");
        }else{
            puts("NO");
        }
    }else{
        if(n/2+1 >= k){
            puts("YES");
        }else{
            puts("NO");
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
    int n, i;
    while(true){
        cin >> n;
        if(n == 0) break;
        int s[n];
        double mean = 0, sum = 0, var = 0;
        for(i = 0; i < n; i++){
            cin >> s[i];
            sum += s[i];
        }
        mean = sum / n;
        for(i = 0; i < n; i++){
            var += pow(s[i] - mean, 2);
        }
        cout << fixed << setprecision(4);
        cout << sqrt(var/n) << endl;
    }
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

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

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int n; cin>>n;
  int MOD = 1e9 + 7;
  ll s=0,t=0;
  for(int i=0;i<n;i++){
    ll a; cin >>a;
    s = (s+a*t)%MOD;
    t = (t+a)%MOD;
  }
  cout<<s<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,ans=1;
	cin >> n >> m;
	if (n==1) {
		cout << m;
		return 0;
	}
	for (int i = 2; i*i <= m; ++i) {
		if (m%i==0) {
			if (m/i >= n) ans = max(ans,i);
			if (i >= n) ans = max(ans,m/i);
		}
	}
	cout << ans;		
    return 0;
}


Measured memory_bytes: 256
s = []
for i in range(5):
	s.append(int(input()))
k = int(input())

r = "Yay!"
for i in range(5):
	if (r == ":("):
		break
	for n in range(i+1, 5):
		if((s[n] - s[i]) > k):
			r = ":("
			break

print (r)


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  int i;
  for (i = 0; i < s.length() + 1; i++) {
    if (i + 1 < s.length()) {
      if (s.at(i) != s.at(i + 1)) {
        s.erase(i, 2);
        i = max(i - 2, 0);
        count += 2;
      }
    }
  }
  for (i = 0; i < s.length() + 1; i++) {
    if (i + 1 < s.length()) {
      if (s.at(i) != s.at(i + 1)) {
        s.erase(i, 2);
        i = max(i - 2, 0);
        count += 2;
      }
    }
  }
  cout << count << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int a[N*2];
  for (int i=0;i<N*2;i++){
    cin >> a[i];
  }
  sort(a,a+N*2);
  int sum=0;
  for (int i=0;i<N*2;i+=2){
    sum+=a[i];
  }
  cout << sum << endl;
}

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

using ll = long long;

ll solve(int N, int x, vector<int> costs)
{
    auto result = numeric_limits<ll>::max();

    auto shift_cost = 0LL;
    auto min_costs = costs;
    for (auto shifts = 0; shifts < N; shifts++)
    {
        result = min(result, shift_cost + accumulate(begin(min_costs), end(min_costs), 0LL));

        shift_cost += x;

        for (auto i = 0; i < N; i++)
            min_costs[i] = min(min_costs[i], costs[(i-shifts-1+N)%N]);
    }

    return result;
}

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

    auto costs = vector<int>(N);
    for (auto& x : costs) cin >> x;

    cout << solve(N, x, costs) << endl;
}


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9+7;

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

const int N = 1e3 + 5;

int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x , y , z,k;
    cin >> x >> y >> z >> k;
    vector<ll>a(x),b(y),c(z);
    for(int i = 0; i < x; ++i)
            cin >> a[i];
    for(int i = 0; i < y; ++i)
            cin >> b[i];
    for(int i = 0; i < z; ++i)
            cin >> c[i];
    vector<ll> d;
    for(int i = 0; i < x; ++i)
        for(int j = 0; j < y; ++j)
            d.push_back(a[i]+b[j]);
    vector<ll>ans;
    sort(all(d));
    reverse(all(d));
    sort(all(c));
    reverse(all(c));
    for(int i = 0; i < min(k,x*y); ++i){
        for(int j = 0; j < z; ++j){
            ans.push_back(d[i]+c[j]);
        }
    }
    sort(all(ans));
    reverse(all(ans));
    for(int i = 0; i < k; ++i)
        cout << ans[i]<<'\n';
    return 0;
}


Measured memory_bytes: 42856
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    vector<tuple<string, int, int>> a;
    rep(i, N){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s, p, i));
    }
    sort(a.begin(), a.end());
    rep(i, N) cout << get<2>(a[i]) + 1 << endl;
    return 0;
}

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

long isPrime(long N) {
	if (N < 2 || (!(N & 1) && N != 2))
		return 0;
	for (int i = 3; i * i <= N; i += 2) {
		if (!(N % i))
			return 0;
	}
	return 1;
}

int main(void) {
	long X = 0;
	std::cin >> X;
	while (!isPrime(X++)) {
		continue;
	}
	std::cout << X - 1;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x
    
def main():
    n, k = [int(x) for x in stdin.readline().rstrip().split()]
    p = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    sort_p = sorted(p)
    print(sum(sort_p[0:k]))
main()

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

const int mod = 1e9 + 7;

int n;
char a[3][55];
int dp[55][16];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	a[1][0] = a[2][0] = '*';
	for (int i = 1; i <= 2; ++i) {
		for (int j = 1; j <= n; ++j) cin >> a[i][j];
	}

	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int mask = 0; mask < (1 << 4); ++mask) if (dp[i - 1][mask]) {
			int c1 = mask >> 2, c2 = mask & 3;
			for (int nc1 = 1; nc1 <= 3; ++nc1) for (int nc2 = 1; nc2 <= 3; ++nc2) {
				if (a[1][i - 1] == a[1][i] && c1 != nc1) continue;
				else if (a[1][i - 1] != a[1][i] && c1 == nc1) continue;

				if (a[2][i - 1] == a[2][i] && c2 != nc2) continue;
				else if (a[2][i - 1] != a[2][i] && c2 == nc2) continue;

				if (a[1][i] == a[2][i] && nc1 != nc2) continue;
				else if (a[1][i] != a[2][i] && nc1 == nc2) continue;

				dp[i][nc1 * 4 + nc2] += dp[i - 1][mask];
				while (dp[i][nc1 * 4 + nc2] >= mod) dp[i][nc1 * 4 + nc2] -= mod;
			}
		}
	}

	int ans = 0;
	for (int mask = 0; mask < 16; ++mask) ans = (ans + dp[n][mask]) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 256
for i in range(50):
    n = int(input())
    
    if n == 0:    break
    
    i = 0
    while 1:
        if n == 1:  break
        if n % 2 == 0:
            n = n / 2
        else:
            n = n*3 + 1
        i += 1
    
    print(i)


Measured memory_bytes: 5592
import java.util.*;

class Main {
	Scanner sc;
	
	private void calc() {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int c = 0;
		for (int i = 0; i < N; i++) {
			int idx = S.indexOf("ABC", i);
			if (idx == -1) break;
			c++;
			i = idx + 2;
		}
		System.out.println(c);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 23764
h, w = map(int, input().split())
cells = []
for i in range(h):
    s = input().split()
    cells.append(s[0])
ans = True
for i in range(1,h-1):
    for j in range(1,w-1):
        if cells[i][j] == '#':
            if cells[i-1][j] != '#' and cells[i+1][j] != '#' and cells[i][j-1] != '#' and cells[i][j+1] != '#':
                ans = False
                break
 
if ans: print("Yes")
else: print("No")

Measured memory_bytes: 9116
using System;
class BreakNumber
{
  static void Main(){
  	var a=int.Parse(Console.ReadLine());
    int b,c=0;
    for(b=0;b<=6;b++)if(a>=(int)Math.Pow((double)2,(double)b))c=(int)Math.Pow((double)2,(double)b);
    Console.Write("{0}",c);
  }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, n , m) for(int i = n; i <= m; i++)
using namespace std;
 
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
const int mod = 1000000007; 

long long inv[200000],fact[200000],ifact[200000];
long long comb(ll n, ll k){return fact[n] * ifact[k] % mod * ifact[n-k] % mod;}
 
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
	for (int i=2;i<200000;i++){
	    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	    fact[i] = fact[i-1] * i % mod;ifact[i] = ifact[i-1] * inv[i] % mod;
	}
	ll n;
	cin>>n;
	vi a(n+1);
	vi copy(n+1);
	rep(i,n+1) {
		cin>>a[i];
		copy[i]=a[i];
	}
	sort(copy.begin(), copy.end());
	ll c;
	rep(i,n){
		if(copy[i]==copy[i+1]){
			c=copy[i];
		}
	}
	ll A=0,B=0;
	rep(i,n+1){
		if(A==0&&c==a[i]){
			A=i;
		}
		else if(c==a[i]){
			B=i;
		}
	}
	if(B<A){
	    int R=B;
	    B=A;
	    A=R;
	}
	reps(i, 1, n+1){
	ll ans=0;
	    ll q=(n+1)%mod;
	    ll w=i%mod;
	    ll e=(A+n-B)%mod;
	    ll r=(i-1)%mod;
	    if(q>=w&&e>=r){
		ans=(comb(q,w)-comb(e,r)+mod)%mod;
	    }
	    else ans=comb(q,w);
        cout<<ans<<endl;
 
	}
	
}


Measured memory_bytes: 6656
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Rep(i,n) For(i,0,n)
#define Each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 8
#define MAX_M 30

int n, m, a, b, p;
int t[MAX_N];
int d[MAX_M][MAX_M];

double dp[1<<MAX_N][MAX_M];

void solve() {
	Rep(i,1<<n) fill(dp[i],dp[i]+m,INF);
	dp[(1<<n)-1][a] = 0;
	double res = INF;
	for(int S = (1<<n)-1; S >= 0; S--){
		res = min(res,dp[S][b]);
		Rep(v,m)Rep(i,n){
			if(S >> i & 1){
				Rep(u,m){
					if(d[v][u]>= 0){
						dp[S&~(1<<i)][u] = min(dp[S&~(1<<i)][u], dp[S][v] + (double)d[v][u]/t[i]);
					}
				}
			}
		}
	}
	if(res == INF){
		printf("Impossible\n");
	}else{
		printf("%.3f\n", res);
	}
}

int main(){
	while(1){
		scanf("%d %d %d %d %d", &n, &m, &p, &a, &b);
		if(n == 0) break;
		a--; b--;
		Rep(i,n){
			scanf("%d", &t[i]);
		}
		Rep(i,m)Rep(j,m){ d[i][j] = -1; d[j][i] = -1;}
		Rep(i,p){
			int x, y, z;
			scanf("%d %d %d", &x, &y, &z);
			x--;y--;
			d[x][y] = z;
			d[y][x] = z;
		}
		solve();
	}
	return 0;
}

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

int main() {
    int num = 1;
    int A, B;
    cin >> A >> B;

    int ans = 0;
    while (num < B) {
        ans++;
        num = (num-1) + A;
    }

    cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<char> pre, suf;
  bool rev = false;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
      swap(pre, suf);
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        pre.push_back(c);
      } else {
        suf.push_back(c);
      }
    }
  }
  string ans;
  for (auto c : pre) {
    ans.push_back(c);
  }
  reverse(ans.begin(), ans.end());
  if (rev) {
    reverse(s.begin(), s.end());
  }
  ans.append(s);
  for (auto c : suf) {
    ans.push_back(c);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1368
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

bool cmp(pint a, pint b) {
    return a.second < b.second;
}

int main() {

    int N, M, a, b;
    cin >> N >> M;

    vector<pair<int, int>> A(M);


    for(int i = 0; i < M; i++) {
        cin >> A[i].first >> A[i].second;
    }

    sort(ALL(A), cmp);

    int ans = 0;
    int endtime = 0;

    for(int i = 0; i < M; i++) {
        if (A[i].first >= endtime) {
            endtime = A[i].second;
            ans++;
        }
    }

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

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

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

  //移動距離
  int intTotalMove = 0;

  int X;

  for(int i = 1; i <= N; i++){

    cin >> X;
    
    //Aの方が近い場合
    if(X < K - X){
      intTotalMove = intTotalMove + (X * 2);
    }
    else{
      intTotalMove = intTotalMove + ((K - X) * 2);
    }
  }    
    
  cout << intTotalMove << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >>n;

    i64 ans{0};
    for (int i=1; i<n+1; ++i) {
        if (i % 3 != 0 && i % 5 != 0)
            ans += i;
    }

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

Measured memory_bytes: 3620
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

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

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

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

ll calcproduct(int n) {
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}

ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

ll combination(int n, int k) {
  ll ans;
  if (n == 1 || n== 0)
    ans = 0;
  else {
  ll a = calcproduct(n);
  ll b = calcproduct(k);
  ll c = calcproduct(n-k);
  b = mod_pow(b, MOD-2);
  c = mod_pow(c, MOD-2);
  ans = ((a*b)%MOD*c)%MOD;
  }
  return ans;
}

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

  string S;
  cin >> S;
  int n = S.size();
  vector<int> f(2019, 0);
  f[0] = 1;
  int temp = 1;
  int c = 0;
  rep(i, n) {
    int t = (int)(S[n-1-i]-'0') * temp % 2019;
    c += t;
    c %= 2019;
    f[c]++;
    temp *= 10;
    temp %= 2019;
  }
  ll ans = 0;
  // cout << combination(1, 2) << endl;
  rep(i, 2019) {
    // cout << f[i] << endl;
    ll a = ans;
    ans += combination(f[i], 2);
    // if (a != ans)
    //   cout << i << ' ' <<  ans << endl;
  }
  cout << ans << endl;
}


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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    bool ok=false;
    rep(i,k+1){
        int n = b*pow(2,i);
        int m = c*pow(2,k-i);
        //cout << a << " " << n << " " << m << endl;
        if(a < max(n,b) && n < max(m,c)){
            //cout << a << " " << n << " " << m << endl;
            ok = true;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int p, w, g, y = 0;
  
  for (int i = 0; i < N; i++) {
    string op;
    cin >> op;
    
    if (op == "P") {
      p = 1;
    }
    else if (op == "W") {
      w = 1;
    }
    else if (op == "G") {
      g = 1;
    }
    else if (op == "Y") {
      y = 1;
    }
  }
  
  if (p + w + g + y >= 4) {
    cout << "Four" << endl;
  }
  else if (p + w + g + y >= 3) {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ALL(obj) begin(obj), end(obj)
using ii = pair<int, int>;

class QuickFind {
public:
    int ans = 0;
    unordered_map<int, int> i2g;
    struct Group {
        int e = 0;
        vector<int> vs;
        int calc() {
            return min(e, (int)vs.size());
        }
    };
    vector<Group> g2i;

    void merge(int i, int j, int edge = 0) {
        // cerr << "i, j: " << i << " " << j << endl;
        int gi, gj;
        if (i2g.count(i)) {
            gi = i2g[i];
        } else {
            i2g[i] = gi = g2i.size();
            g2i.push_back({0, {i}});
        }
        if (i2g.count(j)) {
            gj = i2g[j];
        } else {
            i2g[j] = gj = g2i.size();
            g2i.push_back({0, {j}});
        }
        if (gi == gj) {
            ans -= g2i[gi].calc();
            g2i[gi].e += edge;
            ans += g2i[gi].calc();
            return;
        }
        ans -= g2i[gi].calc();
        ans -= g2i[gj].calc();
        if (g2i[gi].vs.size() < g2i[gj].vs.size()) swap(gi, gj);
        // jをiにmerge
        for (int v : g2i[gj].vs) {
            i2g[v] = gi;
            g2i[gi].vs.push_back(v);
        }
        g2i[gi].e += g2i[gj].e + edge;
        ans += g2i[gi].calc();
        g2i[gj].vs.clear();
    }
    void add_edge(int i, int x) {
        int gi = i2g[i];
        ans -= g2i[gi].calc();
        g2i[gi].e += x;
        ans += g2i[gi].calc();
    }
    bool same(int i, int j) { return i2g[i] == i2g[j]; }
};

signed main() {
    int n, K; cin >> n >> K;
    vector<vector<int>> G(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<ii> color(n);
    for (int i = 0; i < n; i++) {
        int c, d; cin >> c >> d;
        c--, d--;
        color[i] = {c, d};
    }

    vector<int> ans(n);
    function<QuickFind(int, int)> dfs = [&](int v, int prev) {
        QuickFind qf;
        for (int s : G[v]) if (s != prev) {
            auto tmp = dfs(s, v);
            if (qf.i2g.size() < tmp.i2g.size()) swap(qf, tmp);
            for (auto& gs : tmp.g2i) {
                if (gs.vs.size() == 0) continue;
                for (int i = 0; i < gs.vs.size() - 1; i++) {
                    int v0 = gs.vs[i], v1 = gs.vs[i + 1];
                    qf.merge(v0, v1);
                }
                int v0 = *gs.vs.begin();
                qf.merge(v0, v0, gs.e);
            }
        }
        qf.merge(color[v].first, color[v].second, true);
        ans[v] = qf.ans;
        return qf;
    };
    dfs(0, -1);

    for (int x : ans) cout << x << endl;
}



Measured memory_bytes: 84596
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int N,L;
  int APPLE[201];
  int tastesum = 0;
  int tastetemp = 0;
  int compare = 0;
  int result = 10000;
  int ans = 0;
  
  cin >> N >> L;
  
  for(int i = 1; i <= N; ++i){

	APPLE[i]=L+i-1;  
	tastesum = tastesum + APPLE[i];
  
  }
  
  for(int j = 1; j <= N; ++j){
  
	tastetemp = tastesum - APPLE[j];
  
	compare = tastesum - tastetemp;
  
	if(abs(compare) < result){
	
		result = abs(compare);
		ans = tastetemp;
		
	}
	
  }
    
    cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256