akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    

    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    rep(i,a+1)
    {
	    rep(j,b+1)
	    {
		    rep(k,c+1)
		    {
			    int tmpans = 500 * i + 100 * j + 50 * k;
			    if (tmpans == x) cnt ++;
		    }
	    }
    }

    cout << cnt << endl;
}


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

int main(){
   int num;
   int h,m,s;

   cin >> num;
   h = num/3600;
   m = (num%3600)/60;
   s = (num%3600)%60;
   cout << h << ":" << m << ":" << s << "\n";

   return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstdlib>
using namespace std;
string a;

void f(int p) {
	if(p==a.size()) {cout<<"YES"; exit(0);}
	if(a.substr(p,5)=="dream") f(p+5);
	if(a.substr(p,5)=="erase") f(p+5);
	if(a.substr(p,6)=="eraser") f(p+6);
	if(a.substr(p,7)=="dreamer") f(p+7);
}

int main() {
	cin>>a;
	f(0);
	cout<<"NO";
	return 0;
}

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

int main() {
   int W, H , x, y,r;
   cin >> W >>H >>x >> y>> r;
   if((x>=r) && (x<=(W-r))&& (y>=r) && (y<=(H-r))) cout << "Yes" << endl;

   else cout << "No" << endl;

}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<ll>ans(n + 1);
  rep(i,n){
    if(s[i] == '<'){
      ans[i + 1] = ans[i] + 1;
    }
  }
  for(int i = n - 1; i >= 0; i--){
    if(s[i] == '>'){
      if(ans[i] <= ans[i + 1])ans[i] = ans[i + 1] + 1;
    }
  }
  ll sum = 0;
  rep(i,n + 1)sum += ans[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define llu ll unsigned
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ft first
#define sd second
using namespace std;
const int MOD=(int)1e9+7;
// #pragma comment(linker, "/STACK:2000000")

string to_string(string s){return '"'+s+'"';}string to_string(const char* s){return to_string((string)s);}template <typename A, typename B>string to_string(pair<A, B> p){return "("+to_string(p.first)+", "+to_string(p.second)+")";}template<typename A>string to_string(A v){bool first=true;string res="{";for(const auto&x:v){if(!first){res+=", ";}first = false;res+=to_string(x);}res += "}";return res;}void debug_out(){cerr<<endl;}template<typename Head,typename... Tail>void debug_out(Head H,Tail... T){cerr<<" "<<to_string(H);debug_out(T...);}
#ifdef LOCAL
#define err(...)cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define err(...) 42
#endif
#ifdef SUBLIME
#define IO freopen("in.txt","r",stdin)//;freopen("out1.txt","w",stdout)
#else
#define IO
#endif

const int N=1e3+9;
typedef long double ld;
const ll inf = 2e9+9;
const ld eps = 1e-11;


ll x,y;
int ans;

int main(){

    IO;  ios::sync_with_stdio(false);cin.tie(0);
    cin>>x>>y;
    for(ll i=x;i<=y;i*=2){
        if(i>=x && i<=y)ans++;
    }
    cout<<ans;
    return 0; 
} 




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int ans=0;
    char a[5];

    for (int i = 0; i < 3; i++)
    {
        scanf("%c", &a[i]);
    }

    if (a[0] == 'R')
    {
        ans++;
        if (a[1] == 'R')
        {
            ans++;
            if (a[2] == 'R')
            {
                ans++;
            }
        }
    }
    else
    {
        if (a[1] == 'R')
        {
            ans++;
            if (a[2] == 'R')
            {
                ans++;
            }
        }
        else
        {
            if (a[2] == 'R')
            {
                ans++;
            }
        }
    }
      printf("%d",ans);

    return 0;
}

Measured memory_bytes: 1668
#include<stdio.h>

int main(void) {
int A, B, C, D;
int N;
scanf("%d", &N);
A = N/1000;
B = (N/100)%10;
C = (N/10)%10;
D = N%10;

int ans[8];
ans[0] = A+B+C+D;
ans[1] = A+B+C-D;
ans[2] = A+B-C+D;
ans[3] = A+B-C-D;
ans[4] = A-B+C+D;
ans[5] = A-B+C-D;
ans[6] = A-B-C+D;
ans[7] = A-B-C-D;


int op1, op2, op3;
for (int i = 0; i < 8; i++) {
 if (ans[i] == 7) {
     op1 = i/4;
     op2 = i/2;
     op3 = i;
     break;
}
}


char sym1, sym2, sym3;
if (op1 >= 1) sym1 = '-';
else sym1 = '+';
if (op2%2 == 0 ) sym2 = '+';
else sym2 = '-';
if (op3%2 == 0) sym3 = '+';
else sym3 = '-';

printf("%d%c%d%c%d%c%d=7", A, sym1, B, sym2, C, sym3,D);

return 0;

}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>

using namespace std;

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

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0,-1,0}; //次に行くところ
int dx[] = {0,1,0,-1}; //s上に同じ

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k,ans = 0;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++){
    cin >> p[i];
  }
  sort(p.begin(),p.end());

  for (int i = 0; i < k; i++){
    ans += p[i];
  }
  
  cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            //秒単位の時間Sを、h:m:sの形式へ変換して出力

            int S = int.Parse(Console.ReadLine());

            int h = S / 3600;           //1時間は3600秒なので、全体の秒数を3600で割った答えがh
            int m = S % 3600 / 60;      //(S/3600 の余り)/60
            int s = S % 3600 % 60;

            Console.WriteLine("{0}:{1}:{2}", h, m, s);  //フォーマット出力
                                                        //{0}の部分にh,{1}の部分にm

            Console.ReadKey();
        }
    }
}



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

using namespace std;

class Dice{

public:
    unique_ptr<vector<int>> nums;
    unique_ptr<vector<vector<int>>> all;

    Dice(int n){
        nums.reset(new vector<int>(6));
        all.reset(new vector<vector<int>>(24, vector<int>(6)));
    }

    void rotate(char dir){
        int a, b, c, d;
        switch(dir){
        case 'N':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = b;
            nums->at(1) = c;
            nums->at(5) = d;
            nums->at(4) = a;
            break;
        case 'E':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = d;
            nums->at(2) = a;
            nums->at(5) = b;
            nums->at(3) = c;
            break;
        case 'W':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = b;
            nums->at(2) = c;
            nums->at(5) = d;
            nums->at(3) = a;
            break;
        case 'S':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = d;
            nums->at(1) = a;
            nums->at(5) = b;
            nums->at(4) = c;
            break;
        }
    }

    void print_pattern(int i){
        for(int j = 0; j < 6; j++){ cout << " " << all->at(i).at(j); }
        cout << endl;
    }

    void rotate_all(){
        int i = 0;
        for(;i < 4; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');
        for(;i < 8; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');
        for(;i < 12; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');
        for(;i < 16; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
        rotate('N');

        rotate('W');
        rotate('S');

        for(;i < 20; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }

        rotate('N');
        rotate('N');

        for(;i < 24; i++){
            for(int j = 0; j < 6; j++){ all->at(i).at(j) = nums->at(j); }
            rotate('E');
        }
    }

};

int main()
{
    Dice d(6);
    for(int i = 0; i < 6; i++){
        cin >> d.nums->at(i);
    }
    d.rotate_all();

    int n;
    cin >> n;
    int a, b;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        for(int i = 0; i < d.all->size(); i++){
            if(d.all->at(i).at(0) == a && d.all->at(i).at(1) == b){
                cout << d.all->at(i).at(2) << endl;
                break;
            }
        }
    }
}


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

long attack(long x)
{
    static unordered_map<long, long> memo;
    
   if(x==1)
     return 1;
    if( memo.find(x) != memo.end() )//already computed value is found
        return memo[x];
    else
        memo[x] =  attack(x/2) + attack(x/2)+1;
    
    return memo[x];
   
}

int main()
{
 
 long n;
 cin>>n;
 cout<< attack(n)<<endl;
   
   
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

s = input()

ans = [0]*len(s)

i = 0
len_left = 1
len_right = 0
intersec_left = 0
now_left = True

while i < len(s)-1:
    if s[i] == s[i+1] and now_left:
        len_left += 1
    elif s[i] != s[i+1] and now_left:
        len_right += 1
        intersec_left = i
        now_left = False
    elif s[i] == s[i+1]:
        len_right += 1
    else:
        if len_left%2 == 0:
            ans[intersec_left] += len_left//2
            ans[intersec_left+1] += len_left//2
        else:
            ans[intersec_left] += len_left//2+1
            ans[intersec_left+1] += len_left//2
        if len_right%2 == 0:
            ans[intersec_left] += len_right//2
            ans[intersec_left+1] += len_right//2
        else:
            ans[intersec_left] += len_right//2
            ans[intersec_left+1] += len_right//2+1
        len_left = 1
        len_right = 0
        intersec_left = i+1
        now_left = True
    i += 1
else:
    if len_left%2 == 0:
        ans[intersec_left] += len_left//2
        ans[intersec_left+1] += len_left//2
    else:
        ans[intersec_left] += len_left//2+1
        ans[intersec_left+1] += len_left//2
    if len_right%2 == 0:
        ans[intersec_left] += len_right//2
        ans[intersec_left+1] += len_right//2
    else:
        ans[intersec_left] += len_right//2
        ans[intersec_left+1] += len_right//2+1
    
print(*ans)

Measured memory_bytes: 6400
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n; string s;
    cin >> n >> s;

    vector<bool> c1(10, false), c2(100, false), c3(1000, false);

    REP(i, n) {
        int c = s[i] - '0';

        REP(j, 100) {
            if (c2[j]) c3[j * 10 + c] = true;
        }

        REP(j, 10) {
            if (c1[j]) c2[j * 10 + c] = true;
        }

        c1[c] = true;
    }

    int ans = 0;
    REP(i, 1000) if (c3[i]) ans++;

    print(ans);

}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<assert.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
template <class T>
int upmin(T &a, const T &b){return (b<a?a=b,1:0);}
template <class T>
int upmax(T &a, const T &b){return (b>a?a=b,1:0);}
namespace io
{
	const int SIZE=(1<<20)+1;
	char ibuf[SIZE],*iS,*iT;
	char obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1;
	int getc()
	{
		(iS==iT?iS=ibuf,iT=ibuf+fread(ibuf,1,SIZE,stdin):0);
		return iS==iT?EOF:*(iS++);
	}
	int f;
	char c;
	template <class T>
	void get(T &x)
	{
		f=1;
		for(c=getc();(c<'0'||c>'9')&&c!='-';c=getc());
		(c=='-'?f=-1,c=getc():0);
		x=0;
		for(;c>='0'&&c<='9';c=getc())
			x=x*10+c-'0';
		x*=f;
	}
	void flush()
	{
		fwrite(obuf,1,oS-obuf,stdout);
		oS=obuf;
	}
	void putc(char x)
	{
		*(oS++)=x;
		if(oS==oT)
			flush();
	}
	int a[55],t;
	template <class T>
	void put(T x)
	{
		if(!x)
			putc('0');
		x<0?putc('-'),x=-x:0;
		while(x)
		{
			a[++t]=x%10;
			x/=10;
		}
		while(t)
			putc(a[t--]+'0');
	}
	void space()
	{
		putc(' ');
	}
	void enter()
	{
		putc('\n');
	}
	struct flusher
	{
		~flusher()
		{
			flush();
		}
	}
	io_flusher;
}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b%a==0)
		printf("%d\n",a+b);
	else
		printf("%d\n",b-a);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sorted(a) sort(a.begin(),a.end())
#define rsorted(a) sort(a.rbegin(),a.rend())
#define test(val) cout<<val<<endl;
#define test1(val) cout<<val<<" ";

struct node{
	int cost;
	int arr[20];
};

int required_level;
ll min_cost = 1e14;
void backtrack(node books[], int start, vector<ll>level,int n, int m, ll current_cost){
	if(start>=n) return;

	for(int i=start;i<n;i++){

		current_cost+=books[i].cost;
		for(int j=0;j<m;j++) level[j]+=books[i].arr[j];

		for(int k=0;k<m;k++){
			if(level[k]<required_level){
				break;
			}
			if(k==m-1){ min_cost = min(min_cost,current_cost); }
		}

		backtrack(books,i+1,level,n,m,current_cost);
		for(int j=0;j<m;j++) level[j]-=books[i].arr[j];
		current_cost-=books[i].cost;
	}
	return;
}

void solve(){
	int n,m,x;
	cin>>n>>m>>x;
	required_level=x;
	node books[n];
	vector<ll>level(m,0);
	for(int i=0;i<n;i++){
		cin>>books[i].cost;
		for(int j=0;j<m;j++)
			cin>>books[i].arr[j];
	}
	backtrack(books,0,level,n,m,0ll);
	if(min_cost!=1e14)
	cout<<min_cost<<flush;
	else
	cout<<-1<<flush;
}

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

return 0;
}

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


int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> R(N);
    iota(R.begin(), R.end(), 1);  // 1, 2, 3, ... , N

    int a, b, i = 1;
    do {
        if (equal(P.begin(), P.end(), R.begin(), R.end())) a = i;
        if (equal(Q.begin(), Q.end(), R.begin(), R.end())) b = i;
        i++;
    } while (next_permutation(R.begin(), R.end()));
    cout << abs(a - b) << endl;

    return 0;
}

Measured memory_bytes: 3588
N, M = map(int, input().split())
S = list(input())

S.reverse()
ans = []

i = 0
while(True):
    for j in range(M, 0, -1):
        if i + j >= N:
            ans.append(N - i)
            i = N
            break
        if S[i + j] == "0":
            ans.append(j)
            i += j
            break
    else:
        print(-1)
        exit(0)
    if i == N:
        break

ans.reverse()
print(" ".join(map(str, ans)))



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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	int cntAB = 0;
	int cntA = 0;
	int cntB = 0;
	int cntBA = 0;
	string find_word("AB");
	REP(i, n) {
		string s; cin >> s;
		auto pos = s.find(find_word);
		while (pos != string::npos) {
			cntAB++;
			pos = s.find(find_word, pos + find_word.length());
		}
		if (s.front() == 'B' && s.back() == 'A') cntBA++;
		if (s.front() == 'B' && s.back() != 'A') cntB++;
		if (s.front() != 'B' && s.back() == 'A') cntA++;
	}

	if (cntBA) {
		if (cntB + cntA)
			cout << cntAB + cntBA + min(cntB, cntA) << '\n';
		else
			cout << cntAB + cntBA - 1 << '\n';
	} else
		cout << cntAB + min(cntB, cntA) << '\n';
	return 0;
}

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

int n;

void dfs(string s, char maxc){
    if(s.size() == n){
        printf("%s\n", s.c_str());
        return;
    }
    for(char c = 'a'; c <= maxc; c++){
        dfs(s + c, max(maxc, (char)(c+1)));
    }
}

int main(){
    cin >> n;
    dfs("", 'a');
    return 0;
}

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

long long int dp[101][21];

int main() {

    int n;

    cin >> n;

    short a[n];

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

    for(int i=0;i<101;i++){
        for(int j=0;j<21;j++){
            dp[i][j] = 0;
        }
    }

    /*for(int j=0;j<21;j++){
        if(j>=a[0]){
            dp[1][j] += dp[0][j-a[0]] + 1;
        }
    }*/

    dp[1][a[0]] = 1;

    for(int i=1;i<n-1;i++){
        for(int j=0;j<21;j++){
            if(j>=a[i]&&dp[i][j-a[i]] != 0){
                dp[i+1][j] += dp[i][j-a[i]];
            }
            if(a[i]+j<21 && dp[i][a[i]+j]!=0){
                dp[i+1][j] += dp[i][a[i]+j];
            }
        }
    }

    /*for(int i=0;i<=n-1;i++){
        for(int j=0;j<21;j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    int ans;

    cin >> ans;

    cout << dp[n-1][ans] << endl;

    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;

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



int main(){
    // int u, v;
    // bool updated = false;
    ll N, M, cost, total_num;
    scanf("%lld", &N);
    total_num = 0;
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=N;j++){
            ll gcd1 = gcd(i, j);
            for(ll k=1;k<=N;k++){
                ll gcd2 = gcd(gcd1, k);
                total_num += gcd2;
            }
        }
    }

    printf("%lld\n", total_num);


    return 0;

}

Measured memory_bytes: 3232
# -*- coding: utf-8 -*-

def can_reach(a):
    c = 0
    n = [0, 0]
    for point in a:
        c = point[0] - c
        dis = abs(point[1] - n[0]) + abs(point[2] - n[1])
        if (dis > c) or ((c - dis) % 2 != 0):
            return False
        c = point[0]
        n[0] = point[1]
        n[1] = point[2]
    return True

def main():
    n = int(input())
    a = [ list(map(int, input().split())) for _ in range(n)]

    print('Yes' if can_reach(a) else 'No')

if __name__ == '__main__':
    main()


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

int main(){
	int n;
	ll k;
	cin >> n >> k;
	vector<int> f(n),a(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];
	sort(a.begin(),a.end());
	sort(f.rbegin(),f.rend());
	ll l(-1),r(pow(10,15));
	while(r-l>1){
		ll c = (l+r)/2;
		ll s(0);
		rep(i,n){
			if(a[i] - c/f[i] > 0) s += a[i] - c/f[i];
		}
		if(s <= k){
			r = c;
		}else{
			l = c;
		}
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 1920
# https://atcoder.jp/contests/abc069/tasks/arc080_b
# 自明では？
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


H, W = read_ints()
N = read_a_int()
A = read_ints()

out = []
for i, a in enumerate(A, start=1):
    out.extend([i] * a)

# outをHWに並び替える #ただし連続性を担保するために蛇のようにする必要がある。

import numpy as np
out = np.array(out)
out = out.reshape((H, W))
for i, o in enumerate(out):
    if i & 1:
        print(*o)
    else:
        print(*o[::-1])


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

int main() {
    int N,D,X,A;
    cin >> N >> D >> X;
    
    rep(i,N) {
        cin >> A;
        X += (D-1)/A+1;
    }

    cout << X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#define long long int int
using namespace std;

const int maxk = 18;

class edge{
public:
  int t,c,l;

  edge(int to, int color, int length) : t(to),c(color),l(length) {}
};

int depth[100005];
int parent[maxk + 1][100005];
vector<edge> g[100005];
int dist[100005];
int num[100005];


void dfs(int v, int prev, int d, int de,int n) {
  depth[v] = d;
  parent[0][v] = prev;
  dist[v] = de;
  num[v] = n;
  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i].t;
    if(u != prev) {
      n++;
      dfs(u,v,d+1,de+g[v][i].l,n);
    }
  }
  
  return;
}

  

void init(int V) {
  dfs(0,-1,0,0,0);
  
  for(int k = 0; k < maxk; k++) {
    for(int i = 0; i < V; i++) {
      if(parent[k][i] < 0) parent[k+1][i] = -1;
      else parent[k+1][i] = parent[k][parent[k][i]];
    }
  }
  return;
}

int lca(int u, int v) {
  if(depth[u] > depth[v]) swap(u,v);
  for(int k = 0; k < maxk; k++) {
    if((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if(u == v) return u;
  for(int k = maxk - 1; k >= 0; k--) {
    if(parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}


int n,q;

typedef pair<int,int> P;
map<int,P> s[100005];

int C[100005];
int D[100005];


void dfs2(int v, int prev, int n) {

  if(n != num[v]) cout << "aaaaaaaaaaaaaaaaaaaa"<<endl;
  
  for(auto itr = s[v].begin(); itr != s[v].end(); ++itr) {
    int u = itr->first;
    itr->second.first = C[u];
    itr->second.second = D[u];
    
  }

  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i].t;
    if(u != prev) {
      C[g[v][i].c]++;
      D[g[v][i].c] += g[v][i].l;
      n++;
      dfs2(u,v,n);
      C[g[v][i].c]--;
      D[g[v][i].c] -= g[v][i].l;
    }
  }
  
}

int x[100005];
int y[100005];
int u[100005];
int v[100005];

signed main() {
  cin >> n >> q;



  for(int i = 0; i < n - 1; i++) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--,b--;
    g[a].push_back(edge(b,c,d));
    g[b].push_back(edge(a,c,d));
  }

    init(n);
 
  for(int i = 0; i < q; i++) {
    cin >> x[i] >> y[i] >> u[i] >> v[i];
    u[i]--,v[i]--;
   
    s[u[i]][x[i]] = P(0,0);
    s[v[i]][x[i]] = P(0,0);
    int t = lca(u[i],v[i]);
    s[t][x[i]] = P(0,0);
  }
  dfs2(0,-1,0);

  for(int i = 0; i < q; i++) {
    int tmp = s[u[i]][x[i]].first * y[i];
    int tmp2 = s[v[i]][x[i]].first * y[i];
    int tmp3 = s[lca(u[i],v[i])][x[i]].first * y[i];

    int tmp4 = s[u[i]][x[i]].second;
    int tmp5 = s[v[i]][x[i]].second;
    int tmp6 = s[lca(u[i],v[i])][x[i]].second;
    
    int di = dist[u[i]] + dist[v[i]] - 2 * dist[lca(u[i],v[i])];
    int di2 = tmp4 + tmp5 - 2 * tmp6;
    int di3 = tmp + tmp2 - 2 * tmp3;
    
    
    cout << di - di2 + di3 << endl;
    
  }
}
			      


Measured memory_bytes: 40504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var H = IO.GetIntList();

            H = H.OrderBy(h => h).ToList();

            long ans = 0;
            for(int i = 0; i < Math.Max(str[0] - str[1], 0); i++)
            {
                ans += H[i];
            }

            Console.WriteLine(ans);
        }

    }

    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 36096
N, K = [int(i) for i in input().split()]

memo = [0] * (10 ** 5 + 10)
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    memo[a] += b

for i, b in enumerate(memo):
    if K <= memo[i]:
        print(i)
        quit()
    K -= memo[i]


Measured memory_bytes: 5740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=1e5+5;
const ll MAXLG=__lg(MAXN)+2;

ll n,sqt,ss,idx;
vector<ll> s[MAXN];
/********** Main()  function **********/
int main()
{
  IOS();

  cin>>n;

  ss = -1;
  for(ll i=1;i<=2*n;i++){
    if(i*(i-1)==n*2){
      ss = i;
      break;
    }
  }


  if(ss == -1) {
    cout<<"No"<<endl;
  } else {
      cout<<"Yes"<<endl;
      cout<<ss<<endl;
      // assert(ss < MAXN);
      for(ll i=0;i<ss;i++){
        for(ll j=i+1;j<ss;j++){
          s[j].pb(++idx);
          s[i].pb(idx);
        }
      }
      // assert(idx == n);

      for(ll i=0;i<ss;i++){
        cout<<s[i].size();
        //assert(s[i].size() == ss - 1);
        REP(j,SZ(s[i]))cout<<" "<<s[i][j];
        cout<<endl;
      }
  }

  return 0;
}


Measured memory_bytes: 5632
ai = lambda: list(map(int, input().split()))

h,w,d = ai()
ph = [0 for _ in range(h*w + 1)]
pw = [0 for _ in range(h*w + 1)]

for i in range(h):
    a = ai()
    for j in range(w):
        ph[a[j]] = i
        pw[a[j]] = j


score = [0 for _ in range(h*w + 1)]
for i in range(d+1, h*w+1):
    score[i] = score[i-d] + abs(ph[i]-ph[i-d]) + abs(pw[i]-pw[i-d])


q = int(input())
ans = []
for _ in range(q):
    l,r = ai()
    ans.append(score[r]-score[l])
print(*ans, sep='\n')


Measured memory_bytes: 15036
#include <stdio.h>
#include <math.h>

int main(void)
{
  int a, b, c;
  double rad, s, l, h;
  scanf("%d %d %d", &a, &b, &c);
  
  rad = c * M_PI / 180.0; 
  s = 1 / 2.0 * a * b * sin(rad);
  l = a + b + sqrt(a * a + b * b - 2 * a * b * cos(rad));
  h = s * 2.0 / a;
  
  printf("%f\n%f\n%f\n", s, l, h);
  return (0);
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	int kotae = 0;
	rep(i, N - 1) {
		if (S[i] == S[i + 1]) kotae++;
	}
	kotae += K * 2;
	if (kotae >= N) kotae = N - 1;

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 512
import bisect
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def rle(s):
    import itertools
    return list(map(lambda x: (x[0], len(list(x[1]))), itertools.groupby(s)))


n, m = ril()
s = rs()
ls = rle(s)

for a, b in ls:
    if a == '1' and b >= m:
        print(-1)
        exit()

acc = [ls[-1][1]]
for a, b in reversed(ls[:-1]):
    acc.append(acc[-1] + b)

res = []
pos = 0

while True:
    if pos == n:
        break
    i = bisect.bisect(acc, pos + m)
    if i % 2 == 0:
        if pos + m < n + 1:
            res.append(m)
            pos += m
        else:
            res.append(n - pos)
            break
    else:
        new_pos = acc[i - 1] - 1
        res.append(new_pos - pos)
        pos = new_pos
print(*res[::-1])

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

using namespace std;

int n, k;
int h[100000];
int mn[100000];
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        mn[i] = 1000000001;
    }
    mn[0] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            if (i - j < 0) break;
            mn[i] = min(mn[i], mn[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << mn[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int maxtime(int x) {
    // Maximum consuming time for x-minute order
    return (x + 9) / 10 * 10;
}
int remtime(int x) {
    // Remained time for x-minute order
    return maxtime(x) - x;
}
int main() {
    long long N, A, B, C, D, E, sum;
    cin >> N >> A >> B >> C >> D >> E;
    sum = max({ (N-1)/A, (N-1)/B, (N-1)/C, (N-1)/D, (N-1)/E }) + 5;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000


int main() {
	char c[8000];
	vector<long long> d[8];

	f(i, 1000) {
		c[i] = 'F';
		c[1000 + i] = 'E';
		c[2000 + i] = 'S';
		c[3000 + i] = 'T';
		c[4000 + i] = 'I';
		c[5000 + i] = 'V';
		c[6000 + i] = 'A';
		c[7000 + i] = 'L';
	}
	long long b[N];
	int e[N];
	f(i, N) {
		b[i] = 0;
		e[i] = -1;
	}
	long long n, k, t, bt;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%lld", &n);
	for (int i = 1; i <= 6; i++) {
		x = 1;
		d[i].push_back(x);
		f(j, 9 * i) {
			d[i].push_back(x);
			x = x * 2;
		}
		f(j, 511)d[i].push_back(x);
	}
	x = 1;
	while (n > 0) {
		if(n%2==1)d[7].push_back(x);
		x *= 2;
		n /= 2;
	}
	f(i, 512) {
		b[i] = 1;
		if (i > 0)e[i - 1] = i;
	}
	for (int i = 1; i <= 7; i++) {
		k = 0;
		x = 0;
		bt = -1;
		t = 0;
		while (k < d[i].size()) {
			if (d[i][k] <= x) {
				e[bt] = (1000 * i) + k;
				e[(1000 * i) + k] = t;
				bt = (1000 * i) + k;
				b[(1000 * i) + k] = x;
				k++;
			}
			else {
				if ((t / 1000) == (i - 1))x += b[t];
				bt = t;
				t = e[t];
			}
		}
	}
	t = 0;
	while (t >= 0) {
		printf("%c", c[t]);
		t = e[t];
	}
	printf("\n");


	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#include<stdio.h>
#define mod 1000000007;
using namespace std;
using ll = int64_t;
using ld = long double;
long double pi = 2 * acos(0.0);
ll M = 1e18;

void solve() {
    ll n;
    cin >> n;
    ll a[n];
    bool flag = 0;
    for(ll i = 0; i < n; i++) {cin >> a[i]; if(!a[i]) flag = true;}
    ll ans = a[0];
    if(flag) {cout << 0; return;}
    else {
        if(ans > M) {cout << "-1"; return;}
        for(ll i = 1; i < n; i++) {
            if(ans > (ld)M / a[i]) {cout << -1; return;}
            ans *= a[i];
        }
    }
    cout << ans;
}

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


Measured memory_bytes: 4480
// AtCoder Regular Contest 076
// E - Connected?

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;


const int MAX_N = 100000;

ll R, C;
int N;
vector<pair<ll, int>> border;
stack<int> s;
bool used[MAX_N];

int main() {

    ll x[2], y[2], idx;
    bool is_border;


    cin >> R >> C >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[0] >> y[0] >> x[1] >> y[1];
        is_border = true;
        for (int j = 0; j < 2; j++) {
            is_border = is_border && (x[j] % R == 0 || y[j] % C == 0);
        }
        if (!is_border) {
            continue;
        }
        for (int j = 0; j < 2; j++) {
            if (x[j] == 0) {
                idx = C - y[j];
            } else if (y[j] == 0) {
                idx = C + x[j];
            } else if (x[j] == R) {
                idx = C + R + y[j];
            } else if (y[j] == C) {
                idx = C + R + C + R - x[j];
            }
            border.push_back(make_pair(idx, i));
        }
    }

    memset(used, 0, sizeof(used));
    sort(border.begin(), border.end());

    for (auto &p : border) {
        if (used[p.second]) {
            if (s.top() != p.second) {
                cout << "NO" << endl;
                return 0;
            }
            s.pop();
        } else {
            s.push(p.second);
            used[p.second] = true;
        }
    }

    cout << "YES" << endl;

    return 0;

}





Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int size(int n,int k){
  int ans=1,s=k;
  while(s<n){
    ans++;
    s+=k-1;
  }
  return ans;
}
int main(){
  int n,k;
  cin >> n >> k;
  int ans=1,tmp;
  for(int i=0;i<n;i++){
    cin >> tmp;
    if(tmp==1){
      tmp=i;
      break;
    }
  }

  if(tmp+k-1>n-1 || tmp-k+1<0){
    cout << size(n,k) << endl;
  }else{
    cout << size(tmp,k)+size(n-tmp+1,k)<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
main(){
    int x, y, z, k; cin >> x >> y >> z >> k;
    int a[x], b[y], c[z];
    vector<int> t, r;
    rep(i, x) cin >> a[i]; sort(a, a + x, greater<int>());
    rep(i, y) cin >> b[i]; sort(b, b + y, greater<int>());
    rep(i, z) cin >> c[i]; sort(c, c + z, greater<int>());
    rep(i, x) rep(j, y) t.push_back(a[i] + b[j]); sort(t.begin(), t.end(), greater<int>());
    rep(i, min((int)t.size(), k)) rep(j, z) r.push_back(t[i] + c[j]); sort(r.begin(), r.end(), greater<int>());
    rep(i, k) cout << r[i] << '\n';
}

Measured memory_bytes: 43108
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	}

	public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	}
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int e[1000][3];
    int dis[100][100];
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < n; ++ j) {
            dis[i][j] = 0x3f3f3f3f;
        }
    }
    for (int i = 0; i < m; ++ i) {
        scanf("%d%d%d", &e[i][0], &e[i][1], &e[i][2]);
        -- e[i][0], -- e[i][1];
        dis[e[i][0]][e[i][1]] = e[i][2];
        dis[e[i][1]][e[i][0]] = e[i][2];
    }
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < m; ++ i) {
        if (dis[e[i][0]][e[i][1]] != e[i][2]) ++ ans;
    }
    printf("%d\n", ans);
    return 0;
}

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

double ESP = 1e-10;

struct point {
  double x, y;
};

int main() {
  point P[4];

  while(true){
    for(int i = 0; i < 4; i++){
      cin >> P[i].x >> P[i].y;
    }
    if(cin.eof()) break;

    if(abs((P[1].y - P[0].y)*(P[3].y - P[2].y) + (P[3].x - P[2].x)*(P[1].x - P[0].x)) < ESP) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

    return 0;
}

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

static const int MAX = 100;
static const int INF = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
    int d[MAX], color[MAX];
    int u, minc;

    for(int i = 0; i < n; i++){
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;

    while(1){
        minc = INF;
        u = -1;
        for(int i = 0; i < n; i++){
            if(color[i] != BLACK && minc > d[i]){
                minc = d[i];
                u = i;
            }
        }

        if(minc == INF) break;

        color[u] = BLACK;

        for(int v = 0; v < n; v++){
            if(M[u][v] != INF && color[v] != BLACK){
                if(d[u] + M[u][v] < d[v]){
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for(int i = 0; i < n; i++){
        cout << i << " " << d[i] << endl;
    }
}

int main(){
    cin >> n;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = INF;
        }
    }

    for(int i = 0; i < n; i++){
        int from, k, to, c;
        cin >> from >> k;
        for(int j = 0; j < k; j++){
            cin >> to >> c;
            M[from][to] = c;
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		char str[] = br.readLine().toCharArray();

		long tmp = 0;
		long ans = 0;

		for (int i = 0; i < str.length - 1; ++i) {
			if (str[i] == 'A') {
				tmp++;
			} else if (str[i] == 'B' && str[i + 1] == 'C') {
				ans += tmp;
				i++;
			} else {
				tmp = 0;
			}
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 36436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int dp[45][450][450];
const int inf = 1<<29;

int main(){
    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for(int i=0; i<N; ++i) cin >> a[i] >> b[i] >> c[i];

    for(int i=0; i<45; ++i) for(int j=0; j<450; ++j) for(int k=0; k<450; ++k) dp[i][j][k] = inf;
    dp[0][0][0] = 0;

    for(int i=0; i<N; ++i){
        for(int j=0; j<=400; ++j){
            for(int k=0; k<=400; ++k){
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
            }
        }
    }

    int ans = inf;
    for(int j=1; j<=400; ++j){
        for(int k=1; k<=400; ++k){
            if(Ma*k == Mb*j) ans = min(ans, dp[N][j][k]);
        }
    }

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

    return 0;
}

Measured memory_bytes: 35840
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x%N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x)%N;
		y = y >> 1;
		x = (x * x)%N;
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, k, q;
	cin >> n >> k >> q;
	vector<ll> arr(n, 0);
	f(i, 0, q)
	{
		ll temp;
		cin >> temp;
		arr[temp - 1] += 1;
	}
	ll sum = 0;
	f(i, 0, n)
	{
		sum += arr[i];
	}
	f(i, 0, n)
	{
		if (sum - arr[i] >= k)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;;
	}
	return 0;
}


Measured memory_bytes: 1408
n,m =map(int ,input().split())
k =[]
count =0
for i in range(n):
    a =list(map(int, input().split()))
    for j in a[1:]:
        k.append(j)
for b in range(m+1):
    if k.count(b) ==n:
        count +=1
print(count)

Measured memory_bytes: 3060
n = int(input())
d = {}
i = 0
x, s = [], []
for _ in range(n):
    a, b = map(int, input().split())
    k = a + b
    if not k in d:
        d[k] = i
        x.append([])
        s.append(k)
        i += 1
    x[d[k]].append([a, b])
t, a = 0, 0
s.sort(reverse = True)
l = len(x)
for i in range(l):
    x[i].sort(reverse = True)
now = 1
ans = 0
for i in s:
    y = x[d[i]]
    i, j = 0, len(y) - 1
    while i <= j:
        if now:
            ans += y[i][0]
            i += 1
        else:
            ans -= y[j][1]
            j -= 1
        now ^= 1
print(ans)

Measured memory_bytes: 47248
n=int(input())
s=input()

suc=[0]*(n-1)
ans=0
for i,c in enumerate(s):
    for j in range(n-1):
        idx=(i+1+j)%n
        if idx==0:
            suc[j]=0#またぐのは禁止
        if c==s[idx]:
            suc[j]+=1
            suc[j]=min(suc[j],j+1,n-1-j)#最大j+1を超えると重なるため
            ans=max(ans,suc[j])
        else:
            suc[j]=0
print(ans)

Measured memory_bytes: 43100
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a <= b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    cout << n/3 << endl;
    return 0;
}

Measured memory_bytes: 3588