akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
	int n,m;
	cin >> n >> m;
	string s;
	cin >> s;
	int a,b,f[n+1];
	f[0]=0;
	for(int i=1;i<n;i++)
	{
		f[i]=f[i-1];
		if(s[i]=='C'&&s[i-1]=='A') f[i]++;
	}
	for(int i=1;i<=m;i++)
	{
		cin >> a >> b;
		cout << f[b-1]-f[a-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		String s = fs.next();
		
		int max = 0;
		int now = 0;
		
		for(int i = 0; i < s.length(); i++) {
			char chari = s.charAt(i);
			if(chari == 'A' || chari == 'C' || chari == 'T' || chari == 'G') {
				now++;
				max = Math.max(now, max);
			}else {
				now = 0;
			}
		}
		System.out.println(max);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    map<int,int> cnt;
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;

    cout << cnt.size() << endl;
}


Measured memory_bytes: 256
# frozen_string_literal: true

$factors = {}

def factrize(n)
  (2..Math.sqrt(n)).each do |d|
    ex = 0
    while n % d == 0
      ex += 1
      $factors.store(d, ex)
      n /= d
    end
  end
  $factors.store(n, 1) if n != 1
end

n, p = gets.split.map(&:to_i)
ans = 1
factrize(p)
list = $factors.to_a
list.each do |factor|
  (1..factor[1] / n).each do |_i|
    ans *= factor[0]
  end
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n, w;
pair<int, int> p[maxn];
vector<int> v[4], psum[4];

bool read()
{
	if (scanf("%d %d", &n, &w) != 2)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].first, &p[i].second);

	return true;
}

void solve()
{
	llong ww = inf;

	forn (i, n)
		ww = umin(ww, p[i].first);

	forn (i, n)
		v[p[i].first - ww].push_back(p[i].second);

	forn (i, 4)
	{
		sort(v[i].begin(), v[i].end());
		reverse(v[i].begin(), v[i].end());
		psum[i].resize(size(v[i]));
		partial_sum(v[i].begin(), v[i].end(), psum[i].begin());
	}

	int ans = 0;

	forn (i1, size(v[0]) + 1)
		forn (i2, size(v[1]) + 1)
			forn (i3, size(v[2]) + 1)
				if (i1 * ww + i2 * (ww + 1) + i3 * (ww + 2) <= w)
				{
					int www = w - (i1 * ww + i2 * (ww + 1) + i3 * (ww + 2));
					int i4 = www / (ww + 3);
					i4 = min(i4, size(v[3]));
					ans = max(ans, (i1 ? psum[0][i1 - 1] : 0) + (i2 ? psum[1][i2 - 1] : 0)
							+ (i3 ? psum[2][i3 - 1] : 0) + (i4 ? psum[3][i4 - 1] : 0));
				}

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

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する


int main(){
    int n;
    cin >> n;
    ll ans = 1;
    ll mod = pow(10,9)+7;
    for(int i=1;i<=n;i++){ans =(ans*i)%mod;}
    cout << ans;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,k;
  cin>>n>>m>>k;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      if(i*(m-j)+j*(n-i)==k){
         cout<< "Yes" <<endl;
         return 0;
      }
    }
  }
  cout<< "No" <<endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }

    vector<int> dp(n);//動的計画法
    dp.at(0) = 0;
    dp.at(1) = abs(h.at(0) - h.at(1));
   

    for(int i = 2; i < n; i++){
       dp.at(i) = min( dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)) );
    }

    cout << dp.at(n - 1) << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef unsigned long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const double EPS = 1e-6;
const int MAX = 2000 * 100 + 47;


PII A[MAX];
PII B[MAX];
int DP[MAX];

int main()
{
    int x, y, xx, yy;
    scanf("%d%d%d%d", &x, &y, &xx, &yy);
    int n;
    scanf("%d", &n);
    FOR(i, 0, n)
        scanf("%d%d", &A[i].first, &A[i].second);
    
    if (x > xx)swap(x, xx), swap(y, yy);
    if (y > yy)
    {
        FOR(i, 0, n) A[i].second *= -1;
        y *= -1, yy *= -1;
    }
    int sz = 0;
    FOR(i, 0, n)
    {
        if (A[i].first < x || A[i].first > xx)continue;
        if (A[i].second < y || A[i].second > yy)continue;
        B[sz++] = A[i];
    }
    sort(B, B + sz);
    FOR(i, 0, MAX)
        DP[i] = INF;
    int mx = 0;
    FOR(i, 0, sz)
    {
        int j = lower_bound(DP, DP + n, B[i].second) - DP;
        DP[j] = B[i].second;
        mx = max(mx, j+1);
    }
    double ans = (xx - x) + (yy - y);
    ans *= 100;
    if (mx == xx - x + 1 || mx == yy - y + 1)ans += 5 * PI;
    ans += mx * (5 * PI - 20);
    printf("%.11f\n", ans);
}


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

int N;
struct Node{
	int x;
	int y;
	int r;
	int c;
	int rm;
};
struct Node nodes[100];
char memo[20000000];


int recur(int bit){
	int id[N];
	int len = 0;
	if(memo[bit] != -1){
		return memo[bit];
	}

	for(int i = 0; i< N; i++){
		if(bit & (1 << i)){
			int x = nodes[i].x;
			int y = nodes[i].y;
			int r = nodes[i].r;
			int flg = 1;
			for(int j = 0; j < i; j++){
				if(bit & (1 << j)){
					int xx = x - nodes[j].x;
					int yy = y - nodes[j].y;
					int rr = r + nodes[j].r;
					if(xx * xx + yy * yy < rr * rr){
						flg = 0;
						break;
					}
				}
			}
			if(flg) id[len++] = i;
		}
	}

	int ret = 0;
	for(int i = 0; i < len; i++){
		for(int j = i + 1; j < len; j++){
			int id1 = id[i];
			int id2 = id[j];
			if(nodes[id1].c == nodes[id2].c){
				int nb = bit;
				
				nb = nb & ~(1 << id1);
				nb = nb & ~(1 << id2);
				ret = max(ret, recur(nb) + 2);
			}
		}
	}
	return memo[bit] = ret;
}

int main(){
	while(cin >> N, N){
		for(int i = 0; i < 20000000; i++){
			memo[i] = -1;
		}

		for(int i = 0; i < N; i++){
			int x, y, r, c;
			cin >> x >> y >> r >> c;
			nodes[i].x = x;
			nodes[i].y = y;
			nodes[i].r = r;
			nodes[i].c = c;
			nodes[i].rm = 1;
		}
		int bit = 0;
		for(int i = 0; i < N; i++){
			bit = (bit << 1) | 1;
		}
		cout << recur(bit) << endl;
	}
}

Measured memory_bytes: 20692
#include <stdio.h>
#include <memory.h>

int main(void) {
	char i, c;
	int sum[26];
	memset((char*)sum, 0x00, sizeof(sum));
	
    while ((c=getc(stdin))!=EOF) {
    	if('A'<=c && c<='Z') {
    		sum[c-'A']++;
    	} else if('a'<=c && c<='z') {
			sum[c-'a']++;
    	}
    }
    
    for(i=0;i<26;i++) {
    	printf("%c : %d\n", i+'a', sum[i]);
    }
    
	return 0;
}

Measured memory_bytes: 524
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
using llint = long long int;
using lint = long int;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int n;
	vector<int> a, b, c;
	cin >> n;
	a.resize(n);
	b.resize(n);
	c.resize(n);
	rep(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	int ma = 0, mb = 0, mc = 0;
	rep(i, n) {
		int ma_old = ma;
		int mb_old = mb;
		int mc_old = mc;
		ma = max(mb_old + a[i], mc_old + a[i]);
		mb = max(mc_old + b[i], ma_old + b[i]);
		mc = max(ma_old + c[i], mb_old + c[i]);
	}
	cout << max({ma, mb, mc}) << endl;
	return 0;
}

Measured memory_bytes: 1408
x = int(input())

oil = []
for i in range(500,-1,-1):
    oil.append(pow(-(i),5))

for i in range(500):
    oil.append(pow((i+1),5))

cnt = -500


for i in oil:
    cnt_2 = -500
    for j in oil:
        if i-j == x:
            print(cnt,cnt_2)
            exit()
        cnt_2 +=1
    cnt += 1

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;

  for(int i = 0; i < N-2; i++){
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long d;
    cin >> n >> d;
    int k = 0;
    for(int i = 0; i < n; i++){
        long long a, b;
        cin >> a >> b;
        if(a * a + b * b <= d * d){
            k++;
        }
    }
    cout << k;
    return 0;
}

Measured memory_bytes: 3612
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
 int a , b , c , d ;
 cin >> a >> b >> c >> d ;
 cout << max ( min(b,d) - max(a,c) , 0  ) ;

return 0 ;
}


Measured memory_bytes: 256
# 1 <= N,K <= 10**5
# len(S) == N
N,K = map(int,input().split())
S = input()
#preprocess
neg = [0]
negSum = 0
pos = [0]
posSum = 0
value = 1
for i in range(N):
    c =S[i]
    if c == "1":
        posSum += 1
        if value == 0:
            neg.append(negSum)
            value = 1
    else:
        negSum += 1
        if value == 1:
            pos.append(posSum)
            value = 0
if value == 1:
    pos.append(posSum)
else:
    neg.append(negSum)
    pos.append(posSum)
# print(neg)
# print(pos)
L = len(neg)
#1 - K ... [i,min(L,i+K-1)] + [i,min(L+1,i+K)]
ans = pos[1]
for i in range(1,L):
    endI = min(L-1,i+K-1)
    # print(endI,i-1,endI+1,i-1)
    candidate = neg[endI] - neg[i-1] + pos[endI+1] - pos[i-1]
    ans = max(ans,candidate)
print(ans)

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

const int INF = 1000000;

int main()
{
	int k, x;
	cin >> k >> x;
	int r = max(-INF, x-k+1);
	int l = min(INF, x+k-1);
	for (int i = r; i < l; i++) cout << i << " ";
	cout << l << endl;
}


Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int N;
  cin >> N;
  string S,T;
  cin >> S >> T;
  string ans = "";
  rep(i,N){
    ans += S.at(i);
    ans += T.at(i);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int w[N],i,k,e,a,b,d,j;
    for(i=0;i<N;i++)
        cin>>w[i];
    for(i=0;i<N;i++){
        a=0;
        b=0;
        for(k=0;k<=i;k++)
            a=a+w[k];
        for(j=i+1;j<N;j++)
            b=b+w[j];
        d=a-b;
        if(d<0)
            d=-d;
        if(i==0)
            e=d;
        if(d<e)
            e=d;
    }
    cout<<e;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, m, l, r, ans = 0;
    cin >> n >> m;
    vector<int> k(n+1, 0);
    for(int i = 0; i < m; i++){
        scanf("%d%d", &l, &r);
        k[l-1] += 1;
        k[r]   -= 1;
    }
    for(int i = 0; i < n; i++){
        k[i+1] += k[i];
        if(k[i] == m) ans += 1;
    }
    if(k[n] == m) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    AB = [a*b for (a,b) in zip(A[i], B)]
    if sum(AB) + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
N, M = (int(x) for x in input().split())
graph = [[1000] * N for _ in range(N)]
before = []
for _ in range(M):
    a,b,c = (int(x) for x in input().split())
    before.append((a-1,b-1,c))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

for i in range(N):
    graph[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[j][i] = graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j])

ans = 0
for x in before:
    if graph[x[0]][x[1]] != x[2]:
        ans += 1
print(ans)

Measured memory_bytes: 9252
#include <stdio.h>
#include <stdlib.h>

#define N 2000001

void CountingSort(int *, int *, int);

int n;

int main () {
  int *A, i, *B, k = 0;

  scanf("%d",&n);  
  A = (int *)malloc(sizeof(int) * N);
  B = (int *)malloc(sizeof(int) * N);

  for(i = 1; i <= n ; i++) {
    scanf("%d",&A[i]);
    if(k < A[i]) k = A[i];
  }
  
  CountingSort(A, B, k);

  for(i = 1 ; i <= n ; i++) {
    if(i < n)printf("%d ",B[i]);
    else printf("%d\n",B[i]);
  }
  
  free(A);
  free(B);
  
  return 0;
}


void CountingSort(int A[], int B[], int k) {
  int C[10000], i, j;

  for(i = 0 ; i <= k ; i++) C[i] = 0;

  for(j = 1 ; j <= n ; j++) {
    C[A[j]]++;
  }
  
  
  for(i = 1 ; i <= k ; i++) {
    C[i] = C[i] + C[i-1];
  }


  for(j = n ; j >= 1 ; j--) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}



Measured memory_bytes: 17076
#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	string S;
	cin>>S;

	if(S[S.size()-1]=='s')cout<<S<<"es"<<endl;
	else cout<<S<<"s"<<endl;

	



	

		return 0;
}


Measured memory_bytes: 3660
a,b,c = gets.split(" ").map(&:to_i)

for i in 0..6
  if a > b 
    d = b
    b = a
    a = d
  end
  if a > c
    d = c
    c = a
    a = d
  end
  if b > c
    d = c
    c = b
    b = d
  end
end
print a," ",b," ",c,"\n"

Measured memory_bytes: 8632
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

std::int64_t run()
{
	int N;
	std::cin >> N;
	std::int64_t n = N;
	std::int64_t ret = n * (n * n + 3 * n + 2) / 6;
	for (auto _ : boost::irange(N - 1))
	{
		std::int64_t u, v;
		std::cin >> u >> v;
		if (v < u)
		{
			std::swap(u, v);
		}
		ret -= u * (N + 1 - v);
	}
	return ret;
}

void Main()
{
	std::cout << run() << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3640
#include<stdlib.h>
#include<iostream>

using namespace std;

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

  int base = 753;
  int range = 1e9;
  for (int i = 0; i + 2 < S.size(); i++) {
    string num = S.substr(i,3);
    range = min(range, abs(base - atoi(num.c_str())));
  }
  cout << range << endl;
}

Measured memory_bytes: 256
from collections import deque
from functools import reduce
from math import gcd

def gcd3(*numbers):
    return reduce(gcd, numbers)

K = int(input())
ans = 0

for _ in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd3(_, b, c)
print(ans)

Measured memory_bytes: 69644
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=rd())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int rd(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=x*10+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (200010)
#define P (2019)
int n,ans,tmp,p10(1),b[P]{1};
char s[N];
signed main(){
	cin>>s+1,n=strlen(s+1);
	Frn_(i,n,1)tmp=(tmp+p10*(s[i]&15))%P,ans+=b[tmp]++,p10=p10*10%P;
	wr(ans),exit(0);
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b, k;
	cin >> a >> b >> k;

	bool isTakahashiTurn = true;
	while (k--) {
		if (isTakahashiTurn) {
			a = a & 1 ? max(0, a - 1) : a;

			b += a / 2;
			a /= 2;
		} else {
			b = b & 1 ? max(0, b - 1) : b;

			a += b / 2;
			b /= 2;
		}

		isTakahashiTurn = !isTakahashiTurn;
	}

	cout << a << " " << b << endl;
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int ans = 1;
	for (int i = 1; i < N; i++)
	{
		if(S[i-1]!=S[i]) ans++;
	}
  cout << ans;
}

Measured memory_bytes: 512
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5, M = 1e9 + 7; // 998244353
const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0};
const ll INF = 1e18 + 10LL;
const ld PI = 4.0 * atan((ld) 1.0), EPS = 1e-6;
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string YN(bool x) { return x ? "YES" : "NO"; }

void solve(int tcn) {
	int n, k, ans = 0;
	cin >> n >> k;
	vector<int> p(n);
	forn(i, n)
		cin >> p[i];
	sort(p.begin(), p.end());
	forn(i, k)
		ans += p[i];
	cout << ans << nl;
}

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

	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve(i);
	}
	return 0;
}


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

int main(){
    long long a, b, c;
    std::cin >> a >> b >> c;

    long long ans;
    if(0 == a % 2 || 0 == b % 2 || 0 == c % 2){
        ans = 0;
    }else{
        ans = std::min({a * b, b * c, c * a});
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
 
int main() {
    int a, b;
    cin >> a >> b;
    int c = a+b;
    
    if(c%2 == 1) {
        cout << "IMPOSSIBLE";
    }
    else {
        cout << c/2;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a;
    int b;
    scanf("%d %d", &a, &b);
    if(a < b){
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else if(a == b){
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2608
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {


    public static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        int[] stones = new int[n];
        for(int i = 0; i < n; i += 1)
            stones[i] = in.nextInt();

        int[] store = new int[n];

        for(int i = 1; i < n; i += 1) {
            store[i] = Integer.MAX_VALUE;

            for(int j = 1; j <= k; j += 1) {
                if(i-j >= 0)
                    store[i] = Math.min(store[i], store[i-j] + Math.abs(stones[i] - stones[i-j]));
            }
        }

        out.println(store[n-1]);
    }


    public static InputReader in = new InputReader();
    public static PrintWriter out;

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        /**
         * When you call next(), that entire line will be skipped.
         * No flushing buffers.
         * Doesn't work when you want to scan the remaining line.
         *
         * @return entire line
         */
        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
                tokenizer = null;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }
}

Measured memory_bytes: 35772
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int length;
	static int[] array;
	public static void main(String[] args) {
		while(read()){
			solve();
		}

	}
	
	static boolean read(){
		length = sc.nextInt();
		if(length == 0) return false;
		array = new int[length];
		for(int i = 0; i < array.length; i++){
			array[i] = sc.nextInt();
		}
		return true;	
	}
	
	static void solve(){
		int n = 32;
		int index = 0;
		while(n > 0){
			n = n - (n - 1)%5;
			System.out.println(n);
			n = n - array[index];
			if(n >= 0){
				System.out.println(n);
			}else{
				System.out.println(0);
			}
			index = (index+1)%length;
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int n;
	int a[1000];
	cin >>n;

	int max = 0;
	int min = 50000;
	REP(i,n){
		cin >>a[i];
		if(a[i]>max) max = a[i];
		if(a[i]<min) min = a[i];
	}
	cout << max - min << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct node{int par,l,r,sib,deg,h;};
node N[30];

int get_dep(int x,int dep){
  if(N[x].par==-1) return dep;
  return get_dep(N[x].par,dep+1);
}

int mk_h(int x){
  int res=0;
  if(N[x].l!=-1)mk_h(N[x].l),res=N[N[x].l].h+1;
  if(N[x].r!=-1)mk_h(N[x].r),res=max(res,N[N[x].r].h+1);
  return N[x].h=res;
}


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++)N[i].par=N[i].sib=-1,N[i].h=0;;


  for(int i=0,a;i<n;i++){
    cin>>a;
    cin>>N[a].l>>N[a].r;
    if(N[a].l!=-1) N[N[a].l].par=a;
    if(N[a].r!=-1) N[N[a].r].par=a;
    if(N[a].l!=-1)N[N[a].l].sib=N[a].r;
    if(N[a].r!=-1)N[N[a].r].sib=N[a].l;
    N[a].deg=(N[a].r!=-1)+(N[a].l!=-1);
  }
  for(int i=0;i<n;i++)if(N[i].par==-1)N[i].h=mk_h(i);

  for(int i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,N[i].par,N[i].sib,N[i].deg,get_dep(i,0),N[i].h);
    if(N[i].par==-1) cout <<"root";
    else if(N[i].l==-1&&N[i].r==-1) cout <<"leaf";
    else cout << "internal node";
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int n,k,gc,i;
    int a[100010];
    bool flag;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    gc=a[1];
    for(i=2;i<=n;i++)
        gc=gcd(gc,a[i]);
    flag=false;
    for(i=1;i<=n;i++)
        if (a[i]>=k && (a[i]-k)%gc==0) flag=true;
    if (flag) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

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

int n;

int main(){
  cin >> n;
  vector<int> V(n);
  rep(i, n) cin >> V[i];

  vector<int> A(100010);
  vector<int> B(100010);
  rep(i, n){
    if (i%2==0) A[V[i]]++;
    else B[V[i]]++;
  }

  int max_a, max_b;
  max_a = max_element(A.begin(), A.end()) - A.begin();
  max_b = max_element(B.begin(), B.end()) - B.begin();

  if (max_a != max_b) cout << (n/2-A[max_a]) + (n/2-B[max_b]) << endl;
  else{
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    cout << min((n/2-A[0]) + (n/2-B[1]), (n/2-A[1]) + (n/2-B[0])) << endl;
  }
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int d, t, s;
    cin >> d >> t >> s;
    yn(d <= t * s);

    return 0;
}


Measured memory_bytes: 3652
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64, int64> pll;

const int INF = 0x3f3f3f3f;


int dict[10];

int main(){

	for (int i = 0; i < 5; ++i) dict["24579"[i]] = 0;
	for (int i = 0; i < 4; ++i) dict["0168"[i]] = 1;
	for (int i = 0; i < 1; ++i) dict["3"[i]] = 2;

	int N;	scanf("%d",&N);
	N = dict['0'+(N%10)];
	if(N == 0)	puts("hon");
	if(N == 1)	puts("pon");
	if(N == 2)	puts("bon");



}



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

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

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


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

	cin >> N >> M >> K;
	H = (N + M - 1) / (K - 1);
	vector<vector<long long int>>dp(H + 1, vector<long long int>(N + M));
	dp[0][0] = 1;
	long long int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < N + M; j++) {
			for (int k = 0; k < K; k++) {
				if (j + k >= N + M)continue;
				if (i + 1 == H && !k)continue;
				dp[i + 1][j + k] += dp[i][j];
				dp[i + 1][j + k] %= MOD;
				if ((j + k) % (K - 1) != M % (K - 1))continue;
				if (!k)continue;
				if (i + 1 == H)continue;
				if (j + k > M)continue;
				int num = (K - 1)*(i + 1);
				num++;
				num -= j + k;
				if (num > N)continue;
				ans += dp[i][j];
				ans %= MOD;
			}
		}
	}
	ans += dp[H][M];
	ans %= MOD;
	cout << ans << endl;
}

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

int main(void) {
    int N;cin>>N;
    int now = 0;
    int result = 0;
    for (int i = 0; i < N; i++) {
        int H;cin>>H;
        if (now <= H) {
            result++;
            now = H;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;

#define MAX_N 1010

typedef struct {
	int w;
	int o;
} baggage;

int n;
int cost;
baggage W[MAX_N];
int visited[MAX_N];

int cmp(const void *a, const void *b) {
	return ((const baggage *)a)->w - ((const baggage *)b)->w;
}

void calc() {
	int i;
	qsort(W, n, sizeof(baggage), cmp);
	for (i = 0; i < n; i++) {
		if (visited[i]) continue;
		visited[i] = 1;

		int c1, c2, j;
		for (c1 = 0, j = W[i].o; j != i; j = W[j].o) {
			c1 += W[i].w + W[j].w;
			visited[j] = 1;
		}
		for (c2 = 2*(W[0].w+W[i].w), j=W[i].o; j != i; j = W[j].o) {
			c2 += W[0].w + W[j].w;
		}

		if (c1 < c2) cost += c1;
		else cost += c2;
	}
}

int main(int argc, char **argv)
{
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &W[i].w);
		W[i].o = i;
	}
	calc();

	printf("%d\n", cost);
	return 0;
}

Measured memory_bytes: 660
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y, h;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++)
		sum *= (x--);
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n;
	cin >> n;
	cout << floor(n / 3.0) << endl;
	getchar(); getchar();
}

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

int K;
queue<long> q;
long vert(char a){
    if(a=='0')return 0;
    if(a=='1')return 1;
    if(a=='2')return 2;
    if(a=='3')return 3;
    if(a=='4')return 4;
    if(a=='5')return 5;
    if(a=='6')return 6;
    if(a=='7')return 7;
    if(a=='8')return 8;
    if(a=='9')return 9;
}

void serch(){
    //1の位を取り出して幅優先探索
    int count=0;
    for(int i=1;i<10;i++)q.push(i);
    while(count!=K-1){
        //push
        long last;
        string str=to_string(q.front());
        char p = str.at(str.size()-1);
        last = vert(p);
        if(last!=0)q.push(q.front()*10+last-1);
        q.push(q.front()*10+last);
        if(last!=9)q.push(q.front()*10+last+1);
        //除去
        q.pop();
        //count
        count++;
    }
  cout<<q.front()<<endl;
}





int main(){
    cin>>K;   
    serch();
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char map[][] = new char[h][w];
        for (int i = 0; i < h; i++) {
            map[i] = sc.next().toCharArray();
        }
        int hokoPoint[][] = new int[h][w];
        for (int i = 0; i < h; i++) {
            int[] arr = new int[w];
            for (int j = 0; j < w; j++) {
                if(map[i][j]=='#') {
                    arr[j] = 0;
                } else {
                    arr[j] = 1;
                    if(j > 0) arr[j] += arr[j-1];
                }
            }
            for(int j = w-1; j > 0; j--) {
                if(arr[j-1] != 0 && arr[j] != 0) {
                    arr[j-1] = arr[j];
                }
            }
            hokoPoint[i] = arr;
        }

//        for (int i = 0; i < h; i++) {
//            System.out.println(Arrays.toString(hokoPoint[i]));
//        }

        int tatePoint[][] = new int[w][h];
        for (int i = 0; i < w; i++) {
            int[] arr = new int[h];
            for (int j = 0; j < h; j++) {
                if(map[j][i]=='#') {
                    arr[j] = 0;
                } else {
                    arr[j] = 1;
                    if(j > 0) arr[j] += arr[j-1];
                }
            }
            for(int j = h-1; j > 0; j--) {
                if(arr[j-1] != 0 && arr[j] != 0) {
                    arr[j-1] = arr[j];
                }
            }
            tatePoint[i] = arr;
        }
//        for (int i = 0; i < w; i++) {
//            System.out.println(Arrays.toString(tatePoint[i]));
//        }

        int max = Integer.MIN_VALUE;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                max = Math.max(max, hokoPoint[i][j] + tatePoint[j][i]);
            }
        }
        System.out.println(max-1);
    }
}


Measured memory_bytes: 114836
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;cin>>k;
    k--;
    cout<<a[k]<<endl;
}

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

int main() {
        int w,h,i,j;
        for(;;){
        cin>>h>>w;
        if(w==0&&h==0)break;
	for(i=0;i<h;i++){
        for(j=0;j<w;j++){
        cout<<"#";
        }
        if(j==w){cout<<endl;}
        }
        if(i==h){cout<<endl;}
}}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n;
  cin >> n;
  vi a(n+10), b(n+10), c(n+10);
  rrep(i,n){
    cin >> a[i] >> b[i] >> c[i];
  }
  
  ll dp[n+10][3];
  rep(i,3){
   dp[0][i]=0;
  }
  srep(i,1,n+1){
    dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
  return 0;
  
}

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

using namespace std;

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  map<string, int> wk;
  wk["SUN"] = 7;
  wk["MON"] = 6;
  wk["TUE"] = 5;
  wk["WED"] = 4;
  wk["THU"] = 3;
  wk["FRI"] = 2;
  wk["SAT"] = 1;
  string key;
  cin >> key;
  cout << wk[key] << endl;
  
  return 0;
}

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

const int nax = 3010;
int cx = 0, cy = 0;
vector<int> lx, ly;
ll area = 0;
int done[nax][nax], bx[nax][nax], by[nax][nax];

void bfs(int sx, int sy) {
  stack<pair<int,int>> q;
  q.emplace(sx,sy);
  while (q.size()) {
    auto [xi,yi] = q.top();
    q.pop();
    if (xi < 0 || yi < 0 || xi+1 >= cx || yi+1 >= cy) {
      cout << "INF" << endl;
      exit(0);
    }
    if (done[yi][xi]++) continue;
    ll x0 = lx[xi], x1 = lx[xi+1];
    ll y0 = ly[yi], y1 = ly[yi+1];
    area += (x1-x0)*(y1-y0);
    if (!bx[yi][xi])
      q.emplace(xi-1,yi);
    if (!bx[yi][xi+1])
      q.emplace(xi+1,yi);
    if (!by[yi][xi])
      q.emplace(xi,yi-1);
    if (!by[yi+1][xi])
      q.emplace(xi,yi+1);
  }
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int nv, nh;
  cin >> nv >> nh;
  map<int,int> mx, my;
  mx[0],my[0];
  vector<array<int,3>> hori, vert;
  for (int i = 0; i < nv; i++) {
    int sy, ey, x;
    cin >> sy >> ey >> x;
    vert.push_back({sy, ey, x});
    mx[x];
    my[sy], my[ey];
  }
  for (int i = 0; i < nh; i++) {
    int y, sx, ex;
    cin >> y >> sx >> ex;
    hori.push_back({y, sx, ex});
    mx[sx], mx[ex];
    my[y];
  }
  for (auto&[x,c] : mx) {
    c = cx++;
    lx.push_back(x);
  }
  for (auto&[y,c] : my) {
    c = cy++;
    ly.push_back(y);
  }
  for (auto [sy, ey, x] : vert) {
    int ei = my[ey];
    int xi = mx[x];
    for (int i = my[sy]; i < ei; i++) {
      bx[i][xi] = 1;
    }
  }
  for (auto [y, sx, ex] : hori) {
    int ei = mx[ex];
    int yi = my[y];
    for (int i = mx[sx]; i < ei; i++) {
      by[yi][i] = 1;
    }
  }

  /*for (int i = 0; i < cy; i++) {
    for (int j = 0; j < cx; j++)
      cout << bx[i][j] << ' ' << by[i][j] << "   ";
  cout << endl;
  }*/
  bfs(mx[0],my[0]);
  cout << area << endl;
}


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

int main() {
  int K, S;
  cin >> K >> S;
  
  int answer = 0;
  for ( int i = 0 ; i < K + 1 ; i++ ){
    for (int j = 0 ; j < K + 1 ; j ++ ) {
      if ( (S - i - j ) <= K && (S - i - j) >= 0 ){
        answer++;
      }
    }
  }
  cout << answer;
}

Measured memory_bytes: 384