akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

void putQueen(int);
void printBoard(void);
void initialize(void);

int Q[N][N];
int row[N]; //row[x]がNOT_FREE(FREEじゃない)ならば、行xは襲撃されている
int col[N]; //col[x]がNOT_FREEならば、列xは襲撃されている
int dpos[2*N-1]; //dpos[x]がNOT_FREEならば、左下方向の列xは襲撃されている
int dneg[2*N-1]; //dneg[x]がNOT_FREEならば、右下方向の列xは襲撃されている

int main()
{
  int n,i,j,r,c;

  initialize();
  
  scanf("%d",&n);
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      Q[i][j] = 0; //0=Qなし、if文で判断するための0
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&r,&c);
    Q[r][c] = 1; //1=Qあり、if文で判断するための1
  }

  putQueen(0);
    
  return 0;
}

void putQueen(int i)
{
  int j;
  
  if(i==N){ //Qの配置に成功
    printBoard(); //print
    return ;
  }

  for(j=0;j<N;j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE)
      continue; //横、右下方向、左下方向どれかが埋まっていたらやり直し
    row[i] = j; //row[i] != FREE にしといて(Qが入っているということ)かつ、print回数を制限するためにjを入れる 
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE; 
    putQueen(i+1); //次
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE; //Qが配置しきれなかったから全部消去
  }
}

void printBoard()
{
  int i,j;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Q[i][j] && row[i] != j) return; //最初に入力した場所のrow[]がj以外なら出力しない
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j) printf("Q"); //row[i]がjならQがあるので出力
      else printf("."); //それ以外は.
    }
    printf("\n");
  }
}
  
void initialize()
{
  int i;

  for(i=0;i<N;i++){ //全部空にする
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0;i<2*N-1;i++){ //全部空にする
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  while(1){
    int n,m;
    cin >> m >> n;
    if(n==0 && m==0){
      return 0;
    }
    int w[110],i;
    for(i=0;i<n;i++){
      cin >> w[i];
    }
    int min=0,max=1500001;
    while(abs(min-max)>1){
      int sum=0,sum1=0,mid=(min+max)/2;
      for(i=0;i<n;i++){
        if(w[i]>mid){
          sum1=100;
          break;
        }
        else if(sum+w[i]<=mid){
          sum+=w[i];
        }
        else{
          sum=w[i],sum1++;
        }
      }
      sum1++;
      if(sum1<=m){
        max=mid;
      }
      else{
        min=mid;
      }
    }
    cout << max << endl;
  }
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>d(k);
	for (int i = 0; i < k;i++) {
		cin >> d[i];
	}

	int ans = n;
	while (true) {
		int copy = ans;
		bool not_emerge = true;
		while (copy != 0) {
			for (int i = 0;i < k;i++) {
				if (copy % 10 == d[i]) {
					not_emerge = false;
				}
			}
			copy /= 10;
		}
		if (not_emerge) {
			cout << ans << endl;
			return 0;
		}
		ans++;
	}

	return 0;
}

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

int main() {
    long long X; cin>>X;
    if(X==2){
        cout<<2<<endl;
        return 0;
    }else{
        if(X%2==0){
            X++;
        }
        for(;;){
            bool flag = true;
            double sqrtNum = sqrt(X);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (X % i == 0)
                {
                    flag = false;
                    break;
                }
            }
            if(flag){
                cout<<X<<endl;
                break;
            }
            X+=2;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<string.h>
#include<cstdio>
#include<stdio.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
int n;
const long long Mod=1e9+7;
int a[1200];
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	a[i]=i+1;
	long long ans=1;
	for(int i=2;i<=n;++i)
	{
		int cnt=0;
		for(int j=0;j<n;++j)
		{
			while(a[j]%i==0)
			a[j]/=i,++cnt;
		}
		ans=(ans*(cnt+1))%Mod;
	}
	cout<<ans;
	return 0;
 } 

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

int main() {
    string s;
    cin >> s;
    int maru = 0;
    rep(i, s.size()) {
        if (s[i] == 'o') maru++;
    }
    int rem = 15 - s.size();
    //cout << maru << " " << rem << endl;
    string ans = "YES";
    if (maru + rem < 8) ans = "NO";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
     int S, h, m, s;
     scanf( "%d" , &S );
     h = S/3600;
     m = ( S % 3600 )/60;
     s = S % 60;
     printf ("%d:%d:%d\n", h, m, s);
     return 0;
}
     


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

using ll = long long;

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

    int a,b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

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

#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back

typedef long long     ll;

//-*-*-*-*-*-*-*-*-

ll n;
ll dp[100000][3];
ll arr[100000][3];
int main()
{
    ll n,k;cin>>n;
    clr(dp,-1);
   
   for(int i=0;i<n;i++){
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    //cout<<arr[i][0];
   }  
   dp[0][0]=arr[0][0];
   dp[0][1]=arr[0][1];
   dp[0][2]=arr[0][2];

   for(int i=1;i<n;i++){
        for(ll j=0;j<=2;j++){
                
            
        
        for(ll h=0;h<=2;h++){
            
        if(j!=h){
            if(dp[i][j]!=-1){
                dp[i][j]=max(dp[i-1][h]+arr[i][j],dp[i][j]);
            }else{
   dp[i][j]=dp[i-1][h]+arr[i][j];
            }
        }
        }}
   }
cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
 }


Measured memory_bytes: 4992
#include <iostream>
#include<vector>
using namespace std;
int main() {
  int n, k,soma=0;
  cin>>n>>k;
  int V[n];
  vector<int>custo;
  for(int i=0;i<n;i++){
    cin>>V[i];
  }
custo.push_back(0);
for(int i=1;i<n;i++){
  int min = custo[i-1] + abs(V[i-1]-V[i]);
  //cout<<"Esse e o minimo: "<<min<<endl;
  for(int j=i-1;j>=i-k&&j>=0;j--){
    if(custo[j]+abs(V[j]-V[i])<min){
        min=custo[j]+abs(V[j]-V[i]);
        //cout<<"Esse e o novo minimo: "<<min<<endl;
      }
    }
    custo.push_back(min);
  }
  //for(int i=0;i<custo.size();i++)cout<<custo[i]<<" ";
  //cout<<endl;
  cout<<custo[custo.size()-1]<<endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n; cin >> n;
    vint rate(9,0);
    rep(i,n){
        int a; cin >> a;
        if(a<400) rate[0]++;
        else if(a<800) rate[1]++;
        else if(a<1200) rate[2]++;
        else if(a<1600) rate[3]++;
        else if(a<2000) rate[4]++;
        else if(a<2400) rate[5]++;
        else if(a<2800) rate[6]++;
        else if(a<3200) rate[7]++;
        else rate[8]++;
    }
    
    int cnt=0;
    rep(i,8)if(rate[i]>0)cnt++;
    
    cout<<max(cnt,1LL)<<' '<<cnt+rate[8]<<endl;
}

Measured memory_bytes: 3600
n,m=gets.split.map &:to_i
h=gets.split.map &:to_i
a=[],b=[];ans=Array.new(n,1)
m.times{|v|a[v],b[v]=gets.split.map &:to_i
  if h[a[v]-1]>h[b[v]-1]
    ans[b[v]-1]=0
  elsif h[a[v]-1]==h[b[v]-1]
    ans[b[v]-1]=0
    ans[a[v]-1]=0
  else
    ans[a[v]-1]=0
  end
}
puts ans.sum


Measured memory_bytes: 24308
import java.util.function.BiFunction;
import java.util.function.Function;
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        int[][] x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        BiFunction<Integer, Integer, Double> distance = (i, j) -> {
            double y = 0.0;
            for (int k = 0; k < D; k++) {
                y += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            return Math.sqrt(y);
        };
        
        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                if (distance.apply(i, j) % 1 == 0)  ans++;
            }
        }
        
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 28496
#include <iostream>
#include <stdio.h>
#include <numeric>

const double PI=3.14159265358979323846;

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

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

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

int main(){
  ll a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
}


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

int main() {
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;

    if (A == 0) {
        cout << 1 << endl;
    }
    if (B == 0) {
        cout << 2 << endl;
    }
    if (C == 0) {
        cout << 3 << endl;
    }
    if (D == 0) {
        cout << 4 << endl;
    }
    if (E == 0) {
        cout << 5 << endl;
    }

}


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

int main()
{
    int n;
    cin >> n;
    int num;
    if (n % 2 == 1)
    {
        num = n / 2 + 1;
    }
    else
    {
        num = n / 2;
    }
    cout << (double)num / (double)n << endl;
}


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

int main(){
    int n, q, com, x, y, *tree;
    std::scanf("%d%d", &n, &q);

    tree = new int[2 * n];
    for(x = 1; x < 2 * n; ++x) tree[x] = (1U << 31) - 1;

    while(q--){
        std::scanf("%d%d%d", &com, &x, &y);
        if(com == 0){
            tree[n + x] = y;
            for(x = (n + x) >> 1; x > 0; x >>= 1){
                tree[x] = std::min(tree[x << 1], tree[x << 1 | 1]);
            }
        }else{
            x += n;
            y += n+1;
            int v = (1U << 31) - 1;
            while(x < y){
                if(x & 1) v = std::min(v, tree[x++]);
                if(y & 1) v = std::min(tree[y - 1], v);
                x >>= 1;
                y >>= 1;
            }
            std::printf("%d\n", v);
        }
    }
    delete[] tree;

    return 0;
}


Measured memory_bytes: 3144
import sys

def happyo(n,each_point):
  for x in range(n):
    if (each_point[x] < 1):
      print("No")
    else:
      print("Yes")

inp1 = input()
n = int(inp1.split(" ")[0])
k = int(inp1.split(" ")[1])
q = int(inp1.split(" ")[2])

# if(k>100000):
#   for x in range(n):
#     print("Yes")
#   sys.exit()

each_point = []
for i in range(n):
  each_point.append(k-q)
 

for j in range(q):
  ans = int(input())
  each_point[ans-1] += 1
 
happyo(n,each_point)

Measured memory_bytes: 7848
#include <iostream>
#include <algorithm>
using namespace std;
#define N (100)

int main(void){
    int n,p[N+1],m[N+1][N+1];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i-1]>>p[i];
    }
    for(int i=0;i<=n;i++)m[i][i]=0;
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            m[i][j]=(1<<21);
            for(int k=i;k<=j-1;k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    ll n;
    while(cin>>n){
    	ll tmp=100, tmp1, cnt=0;
    	while(tmp<n){
    		tmp1=tmp/100;
    		cnt+=(min(n-tmp, (tmp/100+1)*100-tmp)+tmp1-1)/tmp1;
    		ll tmp2=(tmp1+min(n-tmp, (tmp/100+1)*100-tmp)-1)/tmp1*tmp1;
    		tmp+=tmp2;
    	}
    	cout<<cnt<<endl;
    }
  return 0;
}




Measured memory_bytes: 3652
N, K = map(int, input().split())
H = list(map(int, input().split()))

DP = [10**8] * (N+1)
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])


Measured memory_bytes: 53216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n , d;
    cin >> n >> d;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        if(a*a+b*b <= d*d){ans++;}
    }

    cout << ans << endl;


}


Measured memory_bytes: 3608
import sys
input = sys.stdin.readline

n = int(input())
h = list(map(int, input().split()))

flag = True
h[0] -= 1

if n >= 2:
    for i in reversed(range(0, n-1)):
        diff = h[i+1] - h[i]

        if diff <= -2:
            flag = False
            break
        elif diff == -1:
            h[i] -= 1

print('Yes') if flag else print('No')

Measured memory_bytes: 14252
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		Arrays.sort(s);
		int result = 0;
		for(int i = 0; i < s.length-1;i++) {
			if(s[i]==s[i+1])result=1;
		}
		if(result == 0)System.out.print("yes");
		else System.out.print("no");
	}

}

Measured memory_bytes: 23764
let id x = x

let sum x =
  let c = (float_of_int (81+2*81+2*27+4*27+4*9+8*9+3*8+3*16+16+32)) /. 81.0 in c *. x
  
let _ =
  try
    while true do
      let x = Scanf.scanf "%f\n" id in
      Printf.printf "%.10f\n" (sum x)
    done
  with
    End_of_file -> ()

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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> a(n, 0);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int A;
      cin >> A;
      a.at(A - 1)++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC, task b, 2020/04/19
//ms, ac
/*
*/

int main(void){
  int64_t N;
  int64_t M;
  vector<int> A(10001);
  int ans;


  cin >>N >>M;
  ans = N;
  for(int i=0;i<M;i++){
    cin >>A.at(i);
    ans -=A.at(i);
  }

  if(ans<0) ans=-1;
  cout <<ans <<endl;
  return 0;
}
/*
*/

Measured memory_bytes: 3668
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <cassert>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

string s;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("memory.in", "r", stdin);
	//freopen("memory.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;
	bool ch = true;
	for (int i = 0; i < s.length(); i+=2)
		ch &= (s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
	for (int i = 1; i < s.length(); i+=2)
		ch &= (s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
	if (ch)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

aa = [int(input()) for _ in range(5)]
ans = 0
tmp = INF
for a in aa:
    ans += (a-1)//10 * 10 + 10
    tmp = min(tmp,(a-1)%10+1)

print(ans+tmp-10)


Measured memory_bytes: 5728
package main

import "fmt"

func pow(n, x int64) int64 {
	if n == 1 {
		return 1
	}
	if x == 0 {
		return 1
	}
	r := n * pow(n, x-1)
	return r
}
func main() {
	var b, p, X int64
	fmt.Scan(&X)
	var max int64 = 1
	for b = 1; b <= 40; b++ { // 30^2 < 1000 < 40*2
		for p = 2; p <= 10; p++ { // 1000 < 2^10 == 1024
			s := pow(b, p)
			if s > X {
				break
			}
			if s > max {
				max = s
			}
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(string, s);
  int n = sz(s);

  ll ans = 0;
  int cnt = 0;
  rep(i, n) {
    if (s[i] == 'B') cnt++;
    if (s[i] == 'W') ans += cnt;
  }
  cout << ans << endl;
}

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

//あるi,jについて、i>jでHi>Hjかつその差が2以上であるようなi,jの組が存在すれば単調非現象にできない
//頭から、区間における最大値を計算する。
//後ろから順に見ていく。区間の最大値と比較し、2以上小さかったら達成できないことがわかる。
// h1, h2, ..., hi-1の最大値と、hiを比較する

void solve(){
    int n;
    cin >> n;
    int h[n+10];
    rep(i,n){
        cin >> h[i];
    }

    //区間最大値を計算する
    int maximum[n+10];
    maximum[0]=h[0];
    for(int i=1; i<n; i++){
        maximum[i]=max(maximum[i-1], h[i]);
    }
    string s = "Yes";
    for(int i=1; i<n; i++){
        if(maximum[i-1] - h[i] >= 2){
            s = "No";
            break;
        }
    }
    cout << s << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
main = do
  li <- getLine
  let [a,b,c] = map read $ words li
  let ans = compute a b c
  putStrLn $ if ans then "Yes" else "No"

{-
なんか精度がクリティカルなところを突いているのかしら。
a+2sqrt(ab)+b < c
2sqrt(ab) < c-a-b
4ab < (c-a-b)^2
-}

compute :: Int -> Int -> Int -> Bool
compute a b c = cab > 0 && 4 * a * b < cab * cab
  where
    cab = c - a - b

Measured memory_bytes: 508
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    int i;
    scanf("%lld",&n);
    for(i=sqrt(n);i>=1;i--)
    {
        if(n%i==0)
        {
            break;
        }
    }
    ll ans=i+n/i-2;
    printf("%lld\n",ans);
    return 0;

}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    vector<int> A;
    int q; cin >> q;
    rep(i,q){
        int query; cin >> query;
        if(query == 0){
            int x; cin >> x;
            A.push_back(x);
        }else if(query == 1){
            int p; cin >> p;
            cout << A[p] << endl;
        }else if(query == 2){
            A.pop_back();
        }
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    int res = 0;
    int mn = INF;
    for (int i = 0; i < n; ++i) {
        if(mn >= p[i]) res++;
        mn = min(mn, p[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
#define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


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

const int N = 100005; 

void selfadd(int& a, int b){
    a = (a+b)%mod;
}

int dp[22][1<<21];

void solve(){
    int n;
    cin>>n;
    int a[n][n];

    forn(i,0,n-1){
        forn(j,0,n-1)
            cin>>a[i][j];
    }    
    // int dp[n+1][1<<n];

    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;

    for(int mask=0;mask<(1<<n);mask++){

        int i = bits(mask);
        for(int j = 0;j<n;j++){
            if( ( (mask &(1<<j))) || a[i][j]!=1 ) continue;
            selfadd(dp[i+1][mask|(1<<j)], dp[i][mask]);
        }
    }
    cout<<dp[n][(1<<n)-1];


}
 
int32_t main()
{
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 360704
N=int(input())

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

flg=True
for i in A:
    if i%2==0:
        if i%3==0 or i%5==0:
            pass
        else:
            flg=False
            break
    else:
        pass

if flg:
    print("APPROVED")
else:
    print("DENIED")    

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

int main(void)
{
  char S[3];
  char *S1="ABC";

  scanf("%s",S);
  
  //printf("%s",S);

  if(strcmp(S,S1)==0)
  {
    printf("ARC");
    return 0;
  }

  printf("ABC");

  return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int n, m;
double dp[101][101];

double solve(int prev, int cnt, const vector<vector<double> >& manure)
{
  if (cnt >= m)
    return 1.0;

  if (dp[prev][cnt] != -1.0)
    return dp[prev][cnt];

  double res = 0.0;
  for (int i = 0; i < n; ++i)
    res = max(res, solve(i, cnt+1, manure) * manure[prev][i]);

  return dp[prev][cnt] = res;
}

int main()
{

  while (cin >> n >> m) {
    if ((n|m) == 0)
      break;

    vector<vector<double> > manure(n+1, vector<double>(n+1, 1.0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
	cin >> manure[i][j];
    }

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

    printf("%.2f\n", solve(n, 0, manure));
  }
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),M=in();
	priority_queue<ll,vector<ll>,greater<ll>> A;
	ll sum=0;
	REP(i,N){
		ll x=in<ll>();
		A.push(x);
		sum += x;
	}
	vector<pair<ll,ll>> BC(M);
	REP(i,M){
		ll B=in<ll>(),C=in<ll>();
		BC[i] = make_pair(B,C);
	}
	sort(ALL(BC),[&](pair<ll,ll>& lhs,pair<ll,ll>& rhs){return lhs.first>rhs.first;});
	REP(i,M){
		A.top();
		ll B=BC[i].first,C=BC[i].second;
		REP(j,B){
			ll D = A.top();
			if(D<C){
				sum -= D;
				A.pop();
				A.push(C);
				sum += C;
			}
			else break;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t n;
  int64_t ans=0;
  cin >> n;
  for(int i=1; i<=n; i++){
    if(i%3 != 0 and i%5 != 0){
      ans += i;
    }
  }
  cout << ans << endl;
}

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int x;
	cin >> x;
	if(x == 7 || x == 5 || x == 3)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b ,c;
    cin >> a >> b >> c;
    if(b/a>=c){
        cout << c <<endl;
    }else{
        cout << b/a <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int dp[50'001];
int c[20];

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m)
    {
        cin >> c[i];
    }

    irep(i, n)
    {
        if (i == 0) {
            dp[i] = 0;
        } else {
            dp[i] = i;
            rep(j, m)
            {
                int p = i - c[j];
                if (p >= 0) {
                    dp[i] = min(dp[i], dp[p] + 1);
                }
            }
        }
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3280
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int x;
int main(){
    I(x);
    x += 1;
    int ret = 0;
    while(x){
        ret++;
        x /= 2;
    }
    cout << ret-1 << endl;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

ll co[100005];

int main() 
{
    FAST;
    ll n;
    cin>>n;
    ll a[n];
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        co[a[i]]++;
    }
    ll q;
    cin>>q;
    while(q-->0)
    {
        ll b,c;
        cin>>b>>c;
        ll x=co[b];
        co[b]=0;
        co[c]+=x;
        sum-=(b*x);
        sum+=(c*x);
        cout<<sum<<'\n';
    }
    subt;
    return 0;
}

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

using namespace std;



typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
#define rep(i,m,n) for(ll i=m;i<n;i++)
const ll nmax=100005,mod=1000000007;
vector<vll> G(nmax);
vb flag(nmax,false);




ll dfs(vector<vll> &g, ll v, ll k){
 
  ll num=k-2;
  if(v==0) num++;
 
  
  if(k<g[v].size()) return 0;
  flag[v]=true;
  ll ans=1;
  for(auto next_v:g[v]){
  if(flag[next_v]) continue;
  
   ans*=num;
   ans%=mod;
   num--;
  ans*=dfs(g,next_v,k);
  ans%=mod;
}
  return ans;
}


int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
 ll n,k;
  cin >> n >> k;
  rep(i,0,n-1){
   ll a,b;
   cin >> a >> b;
    a--;
    b--;
   G[a].push_back(b);
   G[b].push_back(a);
  }

ll res=k*dfs(G,0,k);
  res%=mod;
  
  
 cout << res << endl;
}


Measured memory_bytes: 11648
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))
ans = 0
temp = 10000
for k in range(N):
    if abs(A-(T-H[k]*0.006)) < temp:
        temp = abs(A-(T-H[k]*0.006))
        ans = k+1
print(ans)

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

using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = (1 << 17) + 100;
const int mod = 1e9 + 7;

int n, pow2n;
int answer[maxn], ptr = 0;
int mark;

void find_answer(int a, int b, int m){
	if (m == 1){
		answer[ptr ++] = a;
		answer[ptr ++] = b;
		return;
	}
	int k = a ^ b;
	if ((mark | k) < pow2n){
		int x = (mark | k) ^ (pow2n);
		int i = log2(x & -x);
		mark |= (1 << i);
		int vis = mark;
		find_answer(a, b, m - 1);
		int pre = answer[ptr - 2];
		ptr --;
		mark = vis;
		find_answer(pre ^ (1 << i), b ^ (1 << i), m - 1);
		answer[ptr ++] = b;
		return;
	}
	int i = log2(k & -k);
	k -= (k & -k);
	int j = log2(k & -k);
	k -= (k & -k);
	mark |= (1 << j);
	int vis = mark;
	find_answer(a, a ^ (1 << i), m - 1);
	mark = vis;
	find_answer(a ^ (1 << i) ^ (1 << j), b, m - 1);
	mark |= (1 << i);
}

int main(){
	int a, b;
	scanf("%d%d%d", &n, &a, &b);
	pow2n = (1 << n) - 1;
	int cnt = 0;
	for (int i = 0; i < n; i++)
		if ((a ^ b) & (1 << i))
			cnt ++;
	if (!(cnt & 1)){
		printf("NO\n");
		return 0;
	}
	find_answer(a, b, n);
	printf("YES\n");
	for (int i = 0; i < ptr; i++)
		printf("%d ", answer[i]);
}


Measured memory_bytes: 1536
N,T = map(int,input().split())
t = [int(x) for x in input().split()]
p=0
s=t[0]
for i in range(1,N):
  if t[i] - t[i-1] >= T:
    s += t[i]-t[i-1]-T
print(t[-1]+T-s)

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

int main() {
    int n;
    char c;
    bool flag=false;
    cin >> n ;
    for(int i = 0; i < n; i++){
        cin >> c;
        if(c == 'Y')flag=true; 
    }
    if(flag) cout << "Four";
    else cout << "Three";
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jul 11 21:00:41 JST 2020
 **/

signed main() {
    Int L, R, d;
    std::cin >> L >> R >> d;
    std::cout << R / d - (L - 1) / d << std::endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;
 
int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1; i<=n; i++){
      ans += i;
  }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
#define MAX 100005
#define NIL -1
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  int n;
  cin>>n;
  set<int> s;
  rep(i,n){
    int a;
    cin>>a;
    if(s.find(a)!=s.end())s.erase(a);
    else s.insert(a);
  }
  cout<<s.size()<<endl;
  return 0;
}


Measured memory_bytes: 4864
from collections import deque
K = int(input())
INF = 10 ** 6
dist = [INF] * K

deq = deque()
deq.append((1, 0))
while True:
    v, d = deq.popleft()
    if dist[v] != INF:
        continue
    if v == 0:
        print(d + 1)
        break
    dist[v] = d
    if dist[(v + 1) % K] == INF:
        deq.append(((v + 1) % K, d + 1))
    if dist[v * 10 % K] == INF:
        deq.appendleft((v * 10 % K, d))


Measured memory_bytes: 9784
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef pair<ll, ll> P;
typedef vector<ll> vll;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll x, y, z, k;
        cin >> x >> y >> z >> k;
        vll a(x), b(y), c(z);
        ll tmp;
        rep(i, x) {
            scanf("%lli", &tmp);
            a[i] = tmp;
        }
        rep(i, y) {
            scanf("%lli", &tmp);
            b[i] = tmp;
        }
        rep(i, z) {
            scanf("%lli", &tmp);
            c[i] = tmp;
        }

        priority_queue<ll, vector<ll>, greater<>> que;
        sort(a.begin(), a.end(), greater<>());
        sort(b.begin(), b.end(), greater<>());
        sort(c.begin(), c.end(), greater<>());

        rep(i, x) {
            rep(j, y) {
                rep(l, z) {
                    if (que.size() < k) que.push(a[i] + b[j] + c[l]);
                    else if (a[i] + b[j] + c[l] > que.top()) {
                        que.pop();
                        que.push(a[i] + b[j] + c[l]);
                    }
                }
            }
        }
        vll ans(k);
        rep(i, k) {
            ans[k - i - 1] = que.top();
            que.pop();
        }
        rep(i, k) printf("%lli\n", ans[i]);

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 384
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <double> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    double l = 0, r = 1000;
    while (r - l > 1e-10) {
        double R = (l + r) / 2;

        bool ok = false;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double distance = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) / 2;
                if (R < distance) continue;

                double h = sqrt(R * R - distance * distance);
                double x_vector = y[j] - y[i];
                double y_vector = x[i] - x[j];
                double vector_length = sqrt(x_vector * x_vector + y_vector * y_vector);

                for (int dir = 1; dir > -2; dir -= 2) {
                    double X = (x[i] + x[j]) / 2 + dir * x_vector * h / vector_length;
                    double Y = (y[i] + y[j]) / 2 + dir * y_vector * h / vector_length;

                    bool all_in = true;
                    for (int k = 0; k < n; k++) {
                        if ((X - x[k]) * (X - x[k]) + (Y - y[k]) * (Y - y[k]) > R * R + 1e-8) {
                            all_in = false;
                            break;
                        }
                    }

                    if (all_in) {
                        ok = true;
                        break;
                    }
                }

                if (ok) break;
            }

            if (ok) break;
        }

        if (ok) {
            r = R;
        } else {
            l = R;
        }
    }

    cout << fixed << setprecision(10) << l << "\n";
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VVL grid(101,VL(101));
	VL x(n),y(n),h(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for (int cx = 0; cx <= 100; cx++) {
		for (int cy = 0; cy <= 100; cy++) {
			////x[0],y[0],h[0]を使ってcx,cyの時の高さを計算
			//int H = h[0] + abs(x[0] - cx) + abs(y[0] - cy);
			////他のも適するか検査
			bool ok = true;
			int H;
			for (int i = 0; i < n; i++) {
				if (h[i] != 0) {
					H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
				}
			}
			for (int i = 0; i < n; i++) {
				if (h[i] != max(int(H - abs(cx - x[i]) - abs(cy - y[i])),0)) {
					ok = false;
					break;
				}
			}
			if (ok) {
				printf("%d %d %d\n", cx,cy,H);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
N = int(input().strip())

S = input()

count = [[0,0,0] for i in range(N)]
for i in range(N-1, 0, -1):
    for j in range(3):
        count[i-1][j] = count[i][j]
    if S[i] == "R":
        count[i-1][0] += 1
    elif S[i] == "G":
        count[i-1][1] += 1
    elif S[i] == "B":
        count[i-1][2] += 1
"""
for j in range(3):
    for i in range(N):
        print(count[i][j], end = " ")
    print()
"""
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            continue
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += count[j][2]
            diff = j-i
            if j+diff < N and S[j+diff] == "B":
                ans -= 1
        elif (S[i] == "B" and S[j] == "R") or (S[i] == "R" and S[j] == "B"):
            ans += count[j][1]
            diff = j-i
            if j+diff < N and S[j+diff] == "G":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += count[j][0]
            diff = j-i
            if j+diff < N and S[j+diff] == "R":
                ans -= 1
print(ans)

Measured memory_bytes: 69460
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,x,a,f[101],i,c1,c2;
	scanf("%d %d %d",&n,&m,&x);
	for(i=0;i<=n;i++)	f[i]=0;
	for(i=0;i<m;i++)	{
		scanf("%d",&a);
		f[a]=1;
	}
	c1=0;
	for(i=0;i<=x;i++)	{
		c1+=f[i];
	}
	c2=0;
	for(i=x;i<=n;i++)	{
		c2+=f[i];
	}
	if(c1<c2)	printf("%d\n",c1);
	else printf("%d\n",c2);
	return 0;
}

Measured memory_bytes: 128
#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;
    cin >> a >> b;
    if(a+b<24){
        cout << a+b << endl;
    }else{
        cout << a+b-24 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int H=sc.nextInt(),W=sc.nextInt();
	 char[][] s=new char[H][W];
	 for(int i=0;i<H;i++) {
		 String tmp=sc.next();
		 s[i]=tmp.toCharArray();
		 
	 }
	 
	 boolean flag=false;
	 for(int i=0;i<H;i++) {
		 for(int j=0;j<W;j++) {
			 if(s[i][j]=='#') {
				flag=false;
				 if(j+1<=W-1) {
					 if(s[i][j+1]=='#') {
						 flag=true;
					 }
				 }
				 if(j-1>=0) {
					 if(s[i][j-1]=='#') {
						 flag=true;
					 }
				 }
				 if(i+1<=H-1) {
					 if(s[i+1][j]=='#') {
						 flag=true;
					 }
				 }
				 if(i-1>=0) {
					 if(s[i-1][j]=='#') {
						 flag=true;
					 }
				 }
				 if(!flag) {
					 System.out.println("No");
					 return;
				 }
			 }
		 }
		 
	 }
	
		 System.out.println("Yes");
	
	 
 }
	
 
 
}
 

Measured memory_bytes: 22736
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int[] count = new int[n];
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (a[i] < a[j]) {
                    count[i]++;
                }
            }
        }
        long sum = Arrays.stream(count).sum(); // 転倒数

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i] < a[j]) {
                    count[i]++;
                }
            }
        }
        long sum2 = Arrays.stream(count).sum(); // ２周目の転倒数
        long diff = sum2 - sum; // 転倒数の増分

        final long MOD = 1000000007;
        long base = sum * k;
        long diffCount = diff * (sum(k - 1) % MOD);
        long result = (base + diffCount) % MOD;

        // 出力
        System.out.println(result);
    }

    public static long sum(long num) {
        long sum = 0;
        while (0 < num) {
            sum += num;
            num--;
        }
        return sum;
    }
}


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

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

int main()
{
    //cout << "Hello World!" << endl;
    long long a,b;
    
    cin>>a>>b;
    unsigned long long m=a*b;
    int j=gcd(a,b);
    
    cout<<m/j;
    
    
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc072/tasks/arc082_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int N, ai;
vector<int> a;

int main()
{
  REP(i, 100003)
  {
    a.push_back(0);
  }

  cin >> N;
  REP(i, N)
  {
    cin >> ai;
    a[ai]++;
    a[ai + 1]++;
    a[ai + 2]++;
  }

  sort(ALL(a));

  cout << a.back() << '\n';

  return 0;
}


Measured memory_bytes: 892
#include<iostream>

using namespace std;
int main(){
    int i, l, H=0, W=0;
    while(1){
        cin >> H >>  W;
        if(H == 0 && W == 0) {
            return 0;
        } else {
            for(i = 0; i < H; i++) {
                for(l = 0; l < W; l++) {
                    cout << '#';
                }
                cout << endl;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
/**
 *    author:  FromDihPout
 *    created: 2020-08-08
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9) {
        cout << a * b << '\n';
    }
    else {
        cout << -1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 3640