akhauriyash/Code-Regression huggingface dataset:
R,G,B,N =map(int,input().split())

cnt =0
    
for r in range(int(N/R)+1):
  ball = N-r*R 
  for g in range(int(ball/G)+1):
    res = N- (r*R+g*G)
    if  res >=0 and res%B ==0:
      cnt+=1
    
print(cnt)
            


Measured memory_bytes: 2940
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){	
	long long a;
	cin>>a;
	int b=a;
	long long sum=0;
	while(a!=0){
		sum=a%10+sum;
		a=a/10;
	}
	if(b%sum==0){
		cout<<"Yes";
	}
	else{
		cout<<"No"; 
	}
    return 0;
} 

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n;
int xi[100010], yi[100010];
int xj[100010], yj[100010];
long long count(int sx, int sy){
  long long time = 0, l, m = 0;
  for(int i = 0;i < n; i++){
    l = llabs(sx - xj[i]) + llabs(sy - yj[i]);
    m = max(m, l);
    time += l * 2;
  }
  return time - m;
}
void comp(long long *t, long long k, int *x1, int *y1, int x2, int y2){
  if(k < *t){
    *t = k; *x1 = x2; *y1 = y2;
  }
}
int main(void){
  int w, h;
  int x1, y1, x2, y2, sx, sy;
  long long t, k;
  scanf("%d %d %d", &w, &h, &n);
  for(int i = 0;i < n; i++){
    scanf("%d %d", xi + i, yi + i);
    xj[i] = xi[i]; yj[i] = yi[i];
  }
  sort(xi, xi + n); sort(yi, yi + n);
  if(!(n % 2)){
    sx = x1 = xi[n / 2 - 1]; sy = y1 = yi[n / 2 - 1];
    x2 = xi[n / 2]; y2 = yi[n / 2];
    t = count(x1, y1);
    k = count(x1, y2);
    comp(&t, k, &sx, &sy, x1, y2); 
    k = count(x2, y1);
    comp(&t, k, &sx, &sy, x2, y1); 
    k = count(x2, y2);
    comp(&t, k, &sx, &sy, x2, y2); 
  } else{
    sx = xi[n / 2]; sy = yi[n / 2];
    t = count(sx, sy);
  }
  printf("%lld\n", t);
  printf("%d %d\n", sx, sy);
}


Measured memory_bytes: 2600
INF=10**30
N=list(map(int,list(input())))[::-1]
l=len(N)
dp=[[INF,INF] for i in range(l+1)]
dp[0][0]=0
for i in range(l):
    dp[i+1][0]=min([dp[i+1][0],dp[i][0]+N[i],dp[i][1]+N[i]+1])
    dp[i+1][1]=min([dp[i+1][1],dp[i][0]+(10-N[i]),dp[i][1]+(9-N[i])])
ans=min(dp[l][0],dp[l][1]+1)
print(ans)

Measured memory_bytes: 246636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int h, w;
char grid[2002][2002];
int num[4][2002][2002];

void search(){
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			if (grid[i][j] == '.'){
				num[0][i][j] = num[0][i][j-1] + 1;
				num[1][i][j] = num[1][i-1][j] + 1;
			}else{
				num[0][i][j] = 0;
				num[1][i][j] = 0;
			}
		}
	}
	for (int i = h; i >= 1; i--){
		for (int j = w; j >= 1; j--){
			if (grid[i][j] == '.'){
				num[2][i][j] = num[2][i][j+1] + 1;
				num[3][i][j] = num[3][i+1][j] + 1;
			}else{
				num[2][i][j] = 0;
				num[3][i][j] = 0;
			}
		}
	}
	return;
}

int main(){
	cin >> h >> w;
	for (int i = 0; i < 2002; i++){
		for (int j = 0; j < 2002; j++){
			grid[i][j] = '#';
		}
	}
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> grid[i][j];
		}
	}

	search();

	int ans = 0;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			int sum = 0;
			for (int k = 0; k < 4; k++){
				sum += num[k][i][j];
			}
			ans = max(ans, sum-3);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 70072
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#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++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  vector<int>a(n);
  rep(i,n)
  {
    cin>>a[i];
    a[i]-=i+1;
  }
  sort(all(a));
  int m=a[n/2];
  ll res=0;
  rep(i,n)
  {
    res+=abs(a[i]-m);
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 1024
public class Main {
	public static void main(String[] args) {
		java.util.Scanner stdIn = new java.util.Scanner(System.in);
		
		while(true){
			char[] s = stdIn.next().toCharArray();
			if(s.length<2){
				break;
			}
			int a=0, b=0;
			for(int i=1;i<s.length;){
				if(s[i++]<'B') a++; else b++;
			}
			if(a>b) a++; else b++;
			System.out.println(a+" "+b);
		}
	}
}

Measured memory_bytes: 12000
while True:
    n,m = map(int,input().split());
    if n == 0 and m == 0:
        break;
    B = list(map(int, input().split()));

    sum = 0;
    for i in range(0,n):
        for j in range(0,n):
            if i != j:
                if m >= B[i]+B[j]:
                    if sum <= B[i]+B[j]:
                        sum = B[i]+B[j];

    if sum == 0:
        print("NONE");
    else:
        print(sum);


Measured memory_bytes: 5628
import math

# A B H Mの入力
A, B, H, M = map(int, input().split())

# 規定時間時の短針の先端ベクトル
Ax = A * math.cos(math.radians(H * 30 + 0.5 * M))
Ay = A * math.sin(math.radians(H * 30 + 0.5 * M))

# 規定時間時の長針の先端ベクトル
Bx = B * math.cos(math.radians(6 * M))
By = B * math.sin(math.radians(6 * M))

print(math.sqrt((Ax - Bx) ** 2 + (Ay - By) ** 2))

Measured memory_bytes: 9512
n = gets.to_i
h = gets.chomp.split(' ').map(&:to_i)
dp = Array.new(100100, 10**9)

dp[0] = 0
0.upto(n-2) do |i|
  dp[i+1] = [dp[i+1], dp[i] + (h[i] - h[i+1]).abs].min
  dp[i+2] = [dp[i+2], dp[i] + (h[i] - h[i+2]).abs].min if i+2 < n
end

print(dp[n-1])

Measured memory_bytes: 21600
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
 
#define fr first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forln(i, l, n) for (int i = l; i < n; ++i)

#define LOCAL

using namespace std;

#ifdef LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n';
#else 
	#define dbg(x)
#endif

//tg: @galebickosikasa
 
const int maxn = (int) 3e5;
const ll inf = (ll) 2e9;
const ld pi = 3.14159265358979323846264;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

random_device rd;
mt19937 SuperRandom(rd());



int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<int> goo (n);
	cinv (goo);
	int f = 1;
	for (auto& x: goo) {
		if (x % 2) continue;
		if (x % 3 == 0 || x % 5 == 0) continue;
		f = 0;
	}
	if (f) cout << "APPROVED";
	else cout << "DENIED";




}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, j, n, buf1, buf2, num[102], solve[102], rank;

	n=0;
	while(1){
		scanf("%d,%d", &buf1, &buf2);
		if(buf1 == 0 && buf2 == 0)
			break;
		n++;
		num[n] = buf1;
		solve[n] = buf2;
	}
	
	for(i=1; i<=n-1; i++){
		for(j=n-1; j>=i; j--){
			if(solve[j] < solve[j+1]){
				buf1 = num[j];
				num[j] = num[j+1];
				num[j+1] = buf1;
				buf2 = solve[j];
				solve[j] = solve[j+1];
				solve[j+1] = buf2;
			}
		}
	}

	while(scanf("%d", &buf1) != EOF){
		for(i=1; i<=n; i++){
			if(num[i] == buf1)
				break;
		}

		if(i==1)
			printf("1\n");
		else {
			rank = 1;
			for(j=2; j<=i; j++){
				if(solve[j-1] > solve[j])
					rank++;
			}
			printf("%d\n", rank);
		}
	}

	return 0;
}
	

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	int ans = N * (N - 1) / 2 + M * (M - 1) / 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
li = [ int(it) for it in input().split() ]

dp=[0]*(100000+11)

for it in li:
  dp[it] += 1
  dp[it+1] += 1
  dp[it+2] += 1
  
ma = 0
for it in dp:
  ma = max(it,ma)

print ( ma )

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

int main(){
  int N;
  cin >> N;
  vector<long long> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec[i];
  }
  vector<long long> ans(N);
  for(int j=0;j<N;j++){
    if(j%2==0)
      ans[0]+=vec[j];
    else
      ans[0]-=vec[j];
  }
  cout << ans[0];
  for(int k=1;k<N;k++){
    ans[k]=2*vec[k-1]-ans[k-1];
    cout << " " << ans[k];
  }
  cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int ans = 0;
  if(s == "SUN") {
    ans = 7;
  } else if(s == "MON") {
    ans = 6;
  } else if(s == "TUE") {
    ans = 5;
  } else if(s == "WED") {
    ans = 4;
  } else if(s == "THU") {
    ans = 3;
  } else if(s == "FRI") {
    ans = 2;
  } else if(s == "SAT") {
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}

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

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

typedef long long ll;

using namespace std;

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

    float ans;

    if(N == 1) ans = 1;
    else if(N % 2 == 0) ans = 0.5;
    else ans = ceil(float(N)/2.0)/float(N);
    cout << ans << endl;

    return 0;
}

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

#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
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 f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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

	int n; cin >> n;
	vi a(n); FOR (i, 0, n - 1) cin >> a[i], a[i]--;
	vi ans;
	NFOR (it, n-1, 0) {
		if (*max_element(all(a)) > it) {
			cout << "-1\n";
			return 0;
		}
		int j = -1;
		FOR (i, 0, sz(a) - 1) {
			if (a[i] == i) {
				j = i;
			}
		}
		if (j == -1) {
			cout << "-1\n";
			return 0;
		}
		a.erase(a.begin() + j);
		ans.push_back(j);
	}
	reverse(all(ans));
	for (int i: ans) cout << i+1 << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[8][8];
	while(scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[0][0],&a[0][1],&a[0][2],&a[0][3],&a[0][4],&a[0][5],&a[0][6],&a[0][7])!=EOF)
	{
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[1][0],&a[1][1],&a[1][2],&a[1][3],&a[1][4],&a[1][5],&a[1][6],&a[1][7]);
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[2][0],&a[2][1],&a[2][2],&a[2][3],&a[2][4],&a[2][5],&a[2][6],&a[2][7]);
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[3][0],&a[3][1],&a[3][2],&a[3][3],&a[3][4],&a[3][5],&a[3][6],&a[3][7]);
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[4][0],&a[4][1],&a[4][2],&a[4][3],&a[4][4],&a[4][5],&a[4][6],&a[4][7]);
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[5][0],&a[5][1],&a[5][2],&a[5][3],&a[5][4],&a[5][5],&a[5][6],&a[5][7]);
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[6][0],&a[6][1],&a[6][2],&a[6][3],&a[6][4],&a[6][5],&a[6][6],&a[6][7]);
		scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[7][0],&a[7][1],&a[7][2],&a[7][3],&a[7][4],&a[7][5],&a[7][6],&a[7][7]);
		for(int x=0;x<8;x++)
		{
			for(int y=0;y<8;y++)
			{
				if(a[x][y]==1)
				{
					if(a[x][y+1]==1)
					{
						if(a[x+1][y]==1)
						{
							if(a[x+1][y+1])
							{						
								printf("A\n");
							}
							else if(a[x+1][y-1])
							{
								printf("G\n");
							}
						}
						else if(a[x][y+2]==1&&a[x][y+3]==1)
						{
							printf("C\n");
						}
						else if(a[x+1][y+1]==1&&a[x+1][y+2]==1)
						{
							printf("E\n");
						}
					}
					else if(a[x+1][y]==1)
					{
						if(a[x+2][y]==1&&a[x+3][y]==1)
						{
							printf("B\n");
						}
						else if(a[x+1][y-1]==1&&a[x+2][y-1]==1)
						{
							printf("D\n");
						}
						else if(a[x+1][y+1]==1&&a[x+2][y+1]==1)
						{
							printf("F\n");
						}
					}
					x=10;
					y=10;
				}
			}
		}
	}
}

Measured memory_bytes: 1012
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-13

#define INF 1e9
const int MaxSize = 1050 + 10;
const LL MOD = 1e9 + 7;
const int AS = 26;

string s, t;

/*
 https://atcoder.jp/contests/abc142/tasks/abc142_e
 E - Get Everything
 */
int N, M, a[MaxSize], cs[MaxSize], mc[MaxSize][5000]; //the official solution uses a 1-d solution

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/pycp/A_1.in", "r", stdin);
	cin >> N >> M;

	LPE(i, 1, M)
	{
		int b;
		cin >> a[i] >> b;
		int curS = 0;
		LP(j, 0, b)
		{
			int c;
			cin >> c;
			curS = curS | (1 << (c - 1));
		}

		cs[i] = curS;
	}

	int full = (1 << N) - 1;
	LPE(i, 0, M)
	{
		LPE(j, 0, full)
			mc[i][j] = INF;
	}

	mc[0][0] = 0;

	LP(i, 0, M) //the value of i is a catch!
	{
		LPE(j, 0, full)
		{
			if (mc[i][j] == INF)
				continue;

			int nextS = j | cs[i + 1];

			mc[i+1][j] = min(mc[i+1][j], mc[i][j]); //CATCH!
			mc[i + 1][nextS] = min(mc[i + 1][nextS], mc[i][j] + a[i + 1]);

//			cout << i + 1 << " " << nextS << " " << mc[i + 1][nextS] << endl;
		}
	}

	if (mc[M][full] == INF)
		cout << -1;
	else
		cout << mc[M][full];

	return 0;
}



Measured memory_bytes: 20736
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

double dp[301][301][301];
vector<int> val(301);

double cal(int n, int a, int b, int c){
    double sum = a+b+c;
    if( sum == 0 )
        return 0;
    if( dp[a][b][c] )
        return dp[a][b][c];
    double res, t = 0;
    res = (double)n;
    if( a != 0 )
        res += cal(n, a-1, b, c)*a;
    if( b != 0 )
        res += cal(n, a+1, b-1, c)*b;
    if( c != 0 )
        res += cal(n, a, b+1, c-1)*c;
    return dp[a][b][c] = res/sum;
}



int main(){
	optimizeIO();
    int n, a, b, c;
    cin >> n;
    a = b = c = 0;
    REP(i, 0, n){
        cin >> val[i];
        if( val[i] == 1 )
            a++;
        else if( val[i] == 2 )
            b++;
        else
            c++;
    }
    printf("%0.12f", cal(n, a, b, c));

	return 0;
}

Measured memory_bytes: 213376
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
void g(char *s,int n){
    int i;
    char t;
    rep(i,n/2){
        t=s[i];
        s[i]=s[n-i-1];
        s[n-i-1]=t;
    }
}

int main(void){
    int i,j,c,f,l[100],r;
    char s[100],ans[100];
    while(1){
        chin(s);
        if(s[0]=='.')break;
        MEMSET(ans);
        MEMSET(l);
        j=0;
        c=0;
        f=-1;
        rep(i,strlen(s)){
            if(s[i]=='+')c++;
            else if(s[i]=='-')c--;
            else if(s[i]=='['){
                f++;
                l[f]=j;
            }
            else if(s[i]==']'){
                r=j-1;
                g(ans+l[f],r-l[f]+1);
                f--;
            }
            else if(s[i]=='?'){
                ans[j++]='A';
                c=0;
            }
            else{
                ans[j++]=(s[i]-'A'+c%26+26)%26+'A';
                c=0;
            }
        }
        puts(ans);
    }
    return 0;
}



Measured memory_bytes: 2016
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
 
vector<pair<int, ll> > path[100005];
int par[100005];
int dep[100005];
int siz[100005];
ll cst[100005];
int hev[100005];
void dfs(int a){
	siz[a]=1;
	for(int i=0; i<path[a].size(); i++){
		int d=path[a][i].first;
		if(d==par[a]) continue;
		par[d]=a;
		dep[d]=dep[a]+1;
		cst[d]=path[a][i].second;
		dfs(d);
		siz[a]+=siz[d];
		if(!hev[a] || siz[hev[a]]<siz[d])
			hev[a]=d;
	}
}
 
ll k;
ll add[100005];
ll edgecost(int a){
	ll ret=add[a]+add[par[a]]+cst[a];
	return ret%k ? ret : 0;
}
 
int pos[100005];
int hl_par[100005];
 
ll bit[100005];
ll sum(int i){
	ll ret=0;
	while(i){
		ret+=bit[i];
		i-=i&-i;
	}
	return ret;
}
void set(int i, ll x){
	x-=sum(i+1)-sum(i);
	i++;
	while(i<100005){
		bit[i]+=x;
		i+=i&-i;
	}
}
 
int lca(int a, int b){
	int p=hl_par[a], q=hl_par[b];
	if(p==q) return dep[a]<dep[b]?a:b;
	if(dep[p]<dep[q]) return lca(a, par[q]);
	else return lca(par[p], b);
}
ll cost(int a){
	int p=hl_par[a];
	ll ret=sum(pos[a])-sum(pos[p]);
	if(p) ret+=edgecost(p)+cost(par[p]);
	return ret;
}
ll cost(int a, int b){
	int p=hl_par[a], q=hl_par[b];
	if(p==q) return abs(sum(pos[a])-sum(pos[b]));
	if(dep[p]<dep[q]){
		swap(p, q);
		swap(a, b);
	}
	return sum(pos[a])-sum(pos[p])+edgecost(p)+cost(par[p], b);
}
 
int main(){
	int n;
	cin >> n >> k;
	for(int i=0; i<n-1; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		path[a].push_back(make_pair(b, c));
		path[b].push_back(make_pair(a, c));
	}
	for(int i=0; i<n; i++) hev[i]=0;
	par[0]=dep[0]=cst[0]=0;
	dfs(0);
 
	for(int i=0; i<n; i++) add[i]=0;
 
	int cnt=0;
	for(int i=0; i<n; i++) pos[i]=-1;
	for(int i=0; i<n; i++){
		if(i && hev[par[i]]==i) continue;
		int j=i;
		do{
			pos[j]=cnt++;
			hl_par[j]=i;
		}while(j=hev[j]);
	}

	for(int i=0; i<100005; i++) bit[i]=0;
	for(int i=0; i<n; i++)
		set(pos[i], edgecost(hev[i]));
	 
	int q;
	cin >> q;
	for(int i=0; i<q; i++){
		string s;
		ll a, b;
		cin >> s >> a >> b;
		if(s[0]=='a'){
			add[a]+=b;
			set(pos[a], edgecost(hev[a]));
			if(a) set(pos[a]-1, edgecost(a));
		}else{
			// cout << cost(a)+cost(b)-2*cost(lca(a, b)) << endl;
			cout << cost(a, b) << endl;
		}
	}
}

Measured memory_bytes: 21076
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    M, D = map(int, readline().split())
    ans = 0
    for m in range(1,M+1):
        for d in range(1,D+1):
            d = str(d)
            if len(d)==1:
                d = '0'+d
            if int(d[0])>=2 and int(d[1])>=2 and int(d[0])*int(d[1])==m:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]

N = int(input())
red = [inpl() for _ in range(N)]
blue = [inpl() for _ in range(N)]
red = sorted(red,key = lambda x: -x[0])
blue = sorted(blue,key = lambda x: x[1])
ans = 0

for a,b in red:
    for c,d in blue:
        if a<c and b<d:
            ans +=1
            blue.remove([c,d])
            break
print(ans)

Measured memory_bytes: 3064
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N = int(input())
graph = [set() for i in range(N+1)]

for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    w = w % 2
    graph[u].add((v,w))
    graph[v].add((u,w))


res = [None for i in range(N+1)]

# v は今見ている頂点，p はｖの親
def dfs(node,p,color): # Depth First Serch
    res[node] = color
    for new_node,w in graph[node]:
        if new_node == p:continue
        if w == 1:dfs(new_node,node,1-color)
        else:dfs(new_node,node,color)
#tree 探索　
# vは頂点，ｐは親
dfs(0,-1,0)

for i in range(N):
    print(res[i])


Measured memory_bytes: 90192
import java.io.*;

public class Main{
    
        static int Ap = 0;
        static int Bp = 0;

    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        try{
            while(true){
                int a = Integer.parseInt(br.readLine());

                if(a == 0) break;
                
                Ap = Bp = 0;

                for(int i = 0; i < a; i++){
                    String[] tmp = br.readLine().split(" " , 2);
                    int[] points = new int[2];
                    points[0] = Integer.parseInt(tmp[0]);
                    points[1] = Integer.parseInt(tmp[1]);
                    judgement(points);
                }

                System.out.println(Ap + " " + Bp);

            }
        }catch(IOException e){
            e.printStackTrace();
        }

    }

    public static void judgement (int[] p){
        if(p[0] > p[1]){
            Ap += (p[0]+p[1]);
        }else if(p[0] < p[1]){
            Bp += (p[0]+p[1]);
        }else if(p[0] == p[1]){
            Ap += p[0];
            Bp += p[1];
        }
    }
}

Measured memory_bytes: 36004
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a; cin >> a;
    cout << a + a * a + a * a * a << endl;
}

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

using namespace std;

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))


#define fr(i, n) for(ll i=0; i<n;i++)
#define fr1(i, n) for(ll i=1; i<=n;i++) 

#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

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

int main()
{
	// #ifndef LOCAL
 //    readf("in.txt");
 //    writef("out.txt");
 //    #endif

    int n;

    cin>>n;

    cout<<cel(n,2)<<nl;

    
    

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	while (x - b >= 0) {
		x -= b;
	}

	cout << x << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int x,y; cin>>x>>y;
	fore(i,0,x+1) if(2*i+4*(x-i)==y)cout<<"Yes\n",exit(0);
	cout<<"No\n";
}

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

int main() {
   int N,M;
   cin >> N >> M;
   int cnt=0,ans=0;
   int like[30][30];

   for(int i=0;i<30;i++){
     for(int j=0;j<30;j++){
       like[i][j]=0;
     } 
   }

  for(int i=0;i<N;i++){
   int K; cin >> K;
     for(int j=0;j<K;j++){
       int a;
       cin >> a;
       like[i][a-1] = 1;
     }
  }

  for(int j=0;j<M;j++){
    for(int i=0;i<N;i++){
      if(like[i][j] == 1){
       cnt++;
      }
    }
   if(cnt==N){
   ans++;
   }
   cnt=0;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ABS(x)		((x)<0 ? -(x):(x))
int main(){
  long long		n,t,a,h,mini,tmp,min=999999999999999999;
  scanf("%lld%lld%lld", &n, &t, &a);
  for(int i=0; i<n; i++){
    scanf("%lld", &h);
    tmp = ABS(1000*t - 6*h - 1000*a);
    if( tmp < min ){ min = tmp; mini = i; }
  }
  printf("%lld", mini+1);
  return 0;
}

Measured memory_bytes: 1660
import collections
import sys
A = []
n = int(input())
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            A.append(i**2+j**2+k**2+i*j+j*k+k*i)
c = collections.Counter(A)


for x in range(1,n+1):
    print(c[x])
sys.exit()


Measured memory_bytes: 49220
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        h: usize, n: usize,
        av: [usize; n]
    };

    let sum = av.into_iter().sum::<usize>();
    let res = if sum >= h { "Yes" } else { "No" };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2840
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        int n = IO.INT();
        int[] m = IO.INT(' ');
        int c = 0;

        for (int i = 0; i < n; i++)
        {
            int min = i;
            for (int j = i; j < n; j++)
            {
                if (m[j] < m[min]) { min = j; }
            }
            if (i != min)
            {
                int buf = m[i];
                m[i] = m[min];
                m[min] = buf;
                c++;
            }
        }
        IO.WRITE(string.Join(" ", m.Select(s => s.ToString()).ToArray()));
        IO.WRITE(c);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

Measured memory_bytes: 9688
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SIZE 400000

#define QUERY_PUSH 0
#define QUERY_ACCESS 1
#define QUERY_POP 2

#define POS_FRONT 0
#define POS_BACK 1

struct deque
{
    int head, tail, list[MAX_SIZE];
};

typedef struct deque * Deque;

void pushBack(Deque, int);
void pushFront(Deque, int);
void popBack(Deque);
void popFront(Deque);
void randomAccess(Deque, int);

int main(void) {
    int n, query, opt, val;
    
    struct deque sd = {0, 0};
    Deque d = &sd;

    scanf("%d", &n);
    while (n--) {
        scanf("%d", &query);
        if (query == QUERY_PUSH) {
            scanf("%d %d", &opt, &val);
            if (opt == POS_FRONT)
                pushFront(d, val);
            else if (opt == POS_BACK)
                pushBack(d, val);
        } else if (query == QUERY_ACCESS) {
            scanf("%d", &val);
            randomAccess(d, val);
        } else if (query == QUERY_POP) {
            scanf("%d", &opt);
            if (opt == POS_FRONT)
                popFront(d);
            else if (opt == POS_BACK)
                popBack(d);
        }
    }

    return 0;
}

void pushBack(Deque d, int x)
{
    d->list[d->tail] = x;
    d->tail = (d->tail + 1) % MAX_SIZE;
}

void pushFront(Deque d, int x)
{
    d->head = (d->head - 1 + MAX_SIZE) % MAX_SIZE;
    d->list[d->head] = x;
}

void popBack(Deque d)
{
    d->tail = (d->tail - 1 + MAX_SIZE) % MAX_SIZE;
}

void popFront(Deque d)
{
    d->head = (d->head + 1) % MAX_SIZE;
}

void randomAccess(Deque d, int p)
{
    printf("%d\n", d->list[(d->head + p) % MAX_SIZE]);
}


Measured memory_bytes: 3368
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
typedef pair<int,int> P;
typedef long long ll;
int a,l;
int p[100];

int main(void){
    while(true){
        cin>>a>>l;
        string s,t;
        if((a==0)&&(l==0))break;
        int x=0,y=0,z=0;
        int index=0;
        p[index++]=a;
        int ansx=0,ansy=0,ansz=0;
        do{
            s="";
            t="";
            for(int i=0;i<l;i++){
                if(a<pow(10,l-i-1))s+="0";
                else{
                    x=(int)a/pow(10,l-i-1);
                    a=a%(int)pow(10,l-i-1);
                    char b=x+'0';
                    s=s+b;
                }
            }
            sort(s.begin(),s.end());
            t=s;
            reverse(t.begin(),t.end());
            x=0,y=0;
            for(int i=0;i<s.length();i++){
                z=s[i]-'0';
                x+=(int)z*pow(10,l-i-1);
            }
            for(int i=0;i<t.length();i++){
                z=t[i]-'0';
                y+=(int)z*pow(10,l-i-1);
            }
            a=y-x;
            p[index++]=a;
            bool flag=false;
            for(int l=0;l<index-1;l++){
                for(int m=l+1;m<index;m++){
                    if(p[l]==p[m]){
                        ansx=l;
                        ansy=p[l];
                        ansz=m-l;
                        flag=true;
                        break;
                    }
                }
                if(flag)break;
            }
            if(flag)break;
        }while(true);
        cout<<ansx<<" "<<ansy<<" "<<ansz<<endl;
    }

    return 0;
}


Measured memory_bytes: 3356
A,B,K = map(int,input().split())
if 2*K<B-A+1:
    S = [i for i in range(A,A+K)]+[i for i in range(B-K+1,B+1)]
else:
    S = [i for i in range(A,B+1)]
for s in S:
    print(s)

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

int main(){
	int n, a, b, c, d, up, down; bool ans = false;
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	if(c == 0) ans = abs(a - b) <= d * LL(n - 1);
	else{
		for(up = 0; up < n; ++ up){
			down = n - 1 - up;
			if(a + LL(up - down) * c - down * LL(d - c) <= b && b <= a + LL(up - down) * c + up * LL(d - c))
				ans = true;
		}
	} printf("%s\n", ans ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}

void f(bool b){
    if(b){
        cout<<"APPROVED"<<endl;
    }else{
        cout<<"DENIED"<<endl;
    }
}

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

    int n;
    cin>>n;
    bool flag=true;

    rep(i,n){
        int a;
        cin>>a;
        if(a%2==0){
            flag&=(a%3==0||a%5==0);
        }
    }

    f(flag);


}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, T, A, ans;
  cin >> N >> T >> A;
  double min=INF;
  vector<int> H(N);
  REP(i,N) {
    cin >> H[i];
    if(abs((T-H[i]*0.006)-A)<=min) {
      min=abs((T-H[i]*0.006)-A);
      ans=i+1;
    }
  }
  cout << ans << endl;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n,m;
ll val[100010][2];
bool dame=false;
ll ans=-1;
vector<P> g[100010];

void dfs(ll v,ll sgn,ll a){
  val[v][sgn]=a;
  for(P e : g[v]){
    ll nv=e.fi,s=e.se*(sgn==+1?+1:-1);
    ll nsgn=1-sgn;
    ll nval=val[v][sgn]+s;
    if(val[nv][sgn]!=-1){
      ll sum=nval+val[nv][sgn];
      if(sum>0&&sum%2==0&&(ans==-1||ans==sum/2)) ans=sum/2;
      else{
        dame=true;
      }
    }
    if(val[nv][nsgn]!=-1){
      if(val[nv][nsgn]!=nval){
        dame=true;
      }
    }else{
      dfs(nv,nsgn,a+s);
    }
  }
}

int main(){
  cin>>n>>m;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g[a].push_back(P(b,c));
    g[b].push_back(P(a,c));
  }
  memset(val,-1,sizeof(val));
  dfs(0,+1,0);
  ll l=0,r=1000000001;
  rep(i,n){
    if(val[i][0]!=-1)minch(r,val[i][0]-1);
    if(val[i][1]!=-1)maxch(l,val[i][1]+1);
  }

  if(l>r||dame||(ans!=-1&&(ans<l||r<ans))){
    cout<<0<<endl;
  }else{
    if(ans!=-1){
      cout<<1<<endl;
    }else{
      cout<<r-l+1<<endl;
    }
  }

  return 0;
}


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

int main()
{
    int n;
    int t, a;
    cin>>n>>t>>a;
    int index = 0;
    int b = 10000000;
    for(int i =  0; i < n; i++) {
        int h; cin>>h;
        if(abs(1000*a- (1000*t - h*6)) < b) {
            b = abs(1000*a- (1000*t - h*6));
            index = i;
        }
    }
    cout << index + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner =new Scanner(System.in);
        int S=scanner.nextInt();
        int h=S/3600;
        int m=S/60%60;
        int s=S%60;
        System.out.println(h+":"+m+":"+s);
        scanner.close();
    }
}


Measured memory_bytes: 26248
#include<bits/stdc++.h>
using namespace std;
int n;int a[30],b[30],c[30];
int last,sum;
int main()
{  
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
     for(int j=1;j<=n;j++)cin>>b[j];
     for(int i=1;i<n;i++)cin>>c[i];
     for(int i=1;i<=n;i++)
     {sum+=b[a[i]];if(a[i]-1==last)sum+=c[last];last=a[i];}
     cout<<sum;
    return 0;
}

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

int main() {
	int n, x,i,j,k,l,sum,count_up=0, box[100] = {};
	while(1){
	cin >> n >> x;
	if (n == 0 && x == 0) {
		break;
	}
	for (i = 0; i < n; i++) {
		box[i] = i+1;
	}
	for (j = 0; j < n-2; j++) {
		for (k = j+1; k < n - 1; k++) {
			for (l = k+1; l < n; l++) {
				sum = box[j] + box[k] + box[l];
					if(sum == x) {
						count_up += 1;
					}
			}
		
		}
	}
		cout << count_up << endl;
		count_up = 0;
	}
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=17,mod=1e9+7;
int n,m,a[N],f[N][1<<N],fac[1<<N],ifac[1<<N];
int Pow(int x,int k){
    int ret=1;
    while(k){
        if(k&1)ret=(ll)ret*x%mod;
        k>>=1;x=(ll)x*x%mod;
    }
    return ret;
}
int C(int n,int m){
    if(n<m)return 0;
    return (ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)scanf("%d",&a[i]);
    fac[0]=1;
    for(int i=1;i<=(1<<n);i++)fac[i]=(ll)fac[i-1]*i%mod;
    for(int i=0;i<=(1<<n);i++)ifac[i]=Pow(fac[i],mod-2);
    sort(a+1,a+m+1,greater<int>());
    f[0][0]=1;
    for(int i=0;i<m;i++)
        for(int j=0;j<(1<<n);j++){
            if(!f[i][j])continue;
            f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
            int res=(1<<n)-j-a[i+1];
            for(int k=0;k<n;k++){
                if(j&(1<<k))continue;
                if(res<(1<<k)-1)break;
                f[i+1][j|(1<<k)]=(f[i+1][j|(1<<k)]-(ll)f[i][j]*C(res,(1<<k)-1)%mod*fac[1<<k])%mod;
            }
        }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        ans=(ans+(ll)f[m][i]*fac[(1<<n)-1-i])%mod;
    }
    ans=((ll)ans*(1<<n)%mod+mod)%mod;
    cout<<ans<<"\n";
}

Measured memory_bytes: 7680
// ===========================================
// 20.02.25 atcoder キーエンス プログラミング コンテスト 2020, B - Robot Arms (Sort)
// 
// 
// ===========================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ET "\n"
#define CLR(arr) memset(arr, 0, sizeof(arr))
#define PAIR pair<int, int>
const ll INF = 1LL << 50;

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int N; cin >> N;
    
    vector<PAIR> Timeline(N*2);
    for(int i = 0; i < N; i++){
        int a, b; cin >> a >> b;
        Timeline[i] = {a-b, a+b};
    }
    
    sort(Timeline.begin(), Timeline.begin()+N, [](PAIR a, PAIR b){
       if(a.second == b.second){
           return a.first < b.first;
       }
       else{
           return a.second < b.second;
       }
    });
    
    int ans = 0;
    int end = -pow(10,9) - 10;
    for(int i = 0; i < N; i++){
        if(end <= Timeline[i].first){
            end = Timeline[i].second;
            ans++;
            //cout << Timeline[i].first << " " << Timeline[i].second << ET;
        }
    }
    
    cout << ans << ET;
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
ll mod=1000000007;
ll n,k,t,m,q,flag=0;
ll po(ll k ,ll n,ll ans,ll temp,ll ans1){
    if(n==0)return ans;
    while(temp<=n){
        ans*=ans1;ans%=mod;ans1=ans1*ans1;ans1%=mod;n=n-temp;temp*=2;
    }
    return po(k,n,ans,1,k)%mod;
    //eg. po(2,78,1,1,2);
}
ll min(ll a,ll b){if(a>b)return b;else return a;}
ll max(ll a,ll b){if(a>b)return a;else return b;}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    //cin>>t;
    t=1;
    while(t--){
        
        cin>>n;
        ll a[n];
        map<ll,ll>m1;
        fo(i,n)cin>>a[i],m1[a[i]]++;
        ll ans=0;
        fo(i,n+1){
            ans+=(m1[i])*(m1[i]-1)/2;
        }
        fo(i,n)cout<<ans-(m1[a[i]]-1)<<endl;
    }

    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

int main() {
    int R, G, B, K;
    cin >> R >> G >> B >> K;
    // R < G < B の大きさになればいい

    while (R >= G && K > 0) {
        G *= 2;
        // cout << "G" << G << endl;
        K--;
    }

    while (K > 0) {
        B *= 2;
        // cout << "B" << B << endl;
        K--;
    }

    if (R < G && G < B) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }

    return 0;
}


Measured memory_bytes: 3676