akhauriyash/Code-Regression huggingface dataset:
import itertools
n=int(input())
length=list(map(int,input().split()))
combination=list(itertools.combinations(length,3))
new_list=[]
for com in combination:
    a=com[0]
    b=com[1]
    c=com[2]
    if a!=b and b!=c and a!=c:
        if com[0]+com[1]>com[2] and com[1]+com[2]>com[0] and com[0]+com[2]>com[1]:
            new_list.append(com)
        else:
            continue
print(len(new_list))

Measured memory_bytes: 21420
#include<stdio.h>
 
#define MAX 101
 
int max(int a,int b)
{
    int M;
    M=a;
    if(M < b) M=b;
    return M;
}
 
int main(void)
{
    int i,j,N,W,v[MAX],w[MAX],dp[MAX][10001];
     
    scanf("%d%d",&N,&W);
    v[0]=0;
    w[0]=0;
    for(i=1;i<=N;i++)
    {
        scanf("%d%d",&v[i],&w[i]);
    }
    for(i=0;i<=W;i++)
    {
        dp[0][i]=0;
    }
    for(i=1;i<=N;i++)
    {
        for(j=0;j<=W;j++)
        {
            if(w[i]<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-w[i]]+v[i]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    printf("%d\n",dp[N][W]);
    return 0;
}

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

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

  int a = 9;
  vector<int> dr;
  dr.push_back(1);
  for (int i = 1;; i++) {
    dr.push_back(a);
    a *= 9;
    if (a > N) break;
  }
  a = 6;
  for (int i = 1;; i++) {
    dr.push_back(a);
    a *= 6;
    if (a > N) break;
  }

  sort(dr.begin(), dr.end());
  int dp[100001];
  for (int i = 0; i < 100001; i++) dp[i] = 1e9;

  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < dr.size(); j++) {
      if (i + dr[j] > N) continue;
      dp[i + dr[j]] = min(dp[i + dr[j]], dp[i] + 1);
    }
  }
  // reverse(dr.begin(), dr.end());
  // int cnt = 0;
  // while (N > 6) {
  //   cerr << N << endl;
  //   for (int i = 0; i < dr.size(); i++) {
  //     if (N >= dr[i]) {
  //       N -= dr[i];
  //       cerr << dr[i] << endl;
  //       cnt++;
  //       break;
  //     }
  //   }
  // }
  cout << dp[N] << endl;

  return 0;
}

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

using namespace std;


int main(){

    int n,m; cin >> n >> m;
    int k,p[m];
    vector<vector<int>> s(m);
    for (int i = 0; i < m; ++i)
    {
       cin >> k;
       for (int j = 0; j < k; ++j)
       {    int a;
           cin >> a;a--;
           s[i].push_back(a);
       }
    }

    for (int i = 0; i < m; ++i)
    {
       cin >> p[i];
    }
int cnt=0,fl=0,flag=0;

for (int bit = 0; bit <(1 << n); ++bit)
{
   flag = 0;
   for (int j = 0; j <m ; ++j)
   {
     fl = 0;
     for (auto l : s[j])
     {
        if (bit & (1 << l))
        {
            fl++;
        }
     }
     
     if (fl%2!=p[j])
     {
         flag=1;
     }
   }
   if (flag ==0)
   {
       cnt++;

   }
}

cout << cnt;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    char tab[a][b];
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++)
            tab[i][j] = '+';
    }
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++){
            cin >> tab[i][j];
        }
    }
    int tab2[a][b];
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++){
            if(tab[i][j] == '.'){
                int tot = 0;
                if(j > 0){
                    if(tab[i][j-1] == '#') tot++;
                    if(i > 0)
                        if(tab[i-1][j-1] == '#') tot++;
                    if(i+1 < a)
                        if(tab[i+1][j-1] == '#') tot++;
                }
                if(i > 0){
                    if(tab[i-1][j] == '#') tot++;
                    if(j+1 < b)
                        if(tab[i-1][j+1] == '#') tot++;
                }
                if(j+1 < b){
                    if(tab[i][j+1] == '#') tot++;
                    if(i+1 < a)
                        if(tab[i+1][j+1] == '#') tot++;
                }
                if(i+1 < a)
                    if(tab[i+1][j] == '#') tot++;
                tab2[i][j] = tot;
            }
        }
    }
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++){
            if(tab[i][j] == '#')
                cout << '#';
            else cout << tab2[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int w[n];
  int sum[n];
  sum[0] = 0;
  for(int i = 0;i < n;i++){
    cin >> w[i];
    if(i == 0)sum[i] = w[i];
    else sum[i] = sum[i-1] + w[i];
  }
  int ans = 1000000;
  for(int i = 0;i < n;i++){
    ans = min(abs(sum[n-1]-2*sum[i]),ans);
  }
  cout << ans << endl;
}

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MAXN 200005
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define endl '\n'
#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto timer_start = chrono::steady_clock::now().time_since_epoch().count();

int a, b, c, n, m, k;
string s, t, u;

int32_t main(){
    fastio
    cin >> s;
    if(s == "Sunny") cout << "Cloudy";
    else if(s == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  ll N,W;
  cin>>N>>W;
  vector<ll> w(N),v(N);
  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  ll dp[N+1][W+1];dp[0][0]=0;
  for(int i=1;i<=W;i++)dp[0][i]=-1;
  dp[0][w[0]]=v[0];
  for(int i=1;i<N;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i]){
        dp[i][j]=dp[i-1][j];
      }else{
        dp[i][j]=(dp[i-1][j-w[i]]==-1?dp[i-1][j]:max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]));
      }
    }
  }
  ll m=0;
  for(int i=0;i<=W;i++){
    m=max(m,dp[N-1][i]);
  }
  cout<<m;
}

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

int main(){
    char inp[10000];
    while (1){
	int joi = 0, ioi = 0;
	cin >> inp;
	if (cin.eof()) break;

	for (int i = 0; inp[i+2] != '\0'; i++){
	    if (inp[i] == 'J' && inp[i+1] == 'O' && inp[i+2] == 'I') joi++;
	    if (inp[i] == 'I' && inp[i+1] == 'O' && inp[i+2] == 'I') ioi++;
	}
	
	cout << joi << endl;
	cout << ioi << endl;
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
  int n,m,a[110],b[110],g,max,i,j;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)scanf("%d %d",&a[i],&b[i]);
  g=0;
  for(i=0;i<n;i++){
    for(j=max=0;j<m;j++){
      if(g+1<a[j]||b[j]<g+1)continue;
      if(max<b[j])max=b[j];
    }
    if(max==0){
      printf("Impossible\n");
      return 0;
    }
    g=max;
    if(g==n)break;
  }
  printf("%d\n",i+1);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include<set>
#include<math.h>
#include<iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
#define _USE_MATH_DEFINES

int main() {
	long double a,b,h,m,x,y,z,f;
	cin>>a>>b>>h>>m;
	x=30*h+m/2;
	y=6*m;
	if(x<y)
	{
		z=y-x;
	}
	else{
		z=x-y;
	}
    if(z>180)
    {
    	z=360-z;
	}
	z*=3.141592653589/180;

	f=sqrt(a*a+b*b-2*a*b*cos(z));


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

Measured memory_bytes: 3540
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K=mis()
    R,S,P=mis()
    T=input()
    #
    ans = 0
    for i in range(K):
        r,s,p = 0,0,0
        for t in T[i::K]:
            r,s,p = max(s, p), max(r, p), max(r, s)
            if t=='r':
                p += P
            elif t=='s':
                r += R
            else:
                s += S
        ans += max(r,s,p)
    print(ans)

main()


Measured memory_bytes: 5808
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  vector<bool> b(n);
  int sum=0;
  rep(i,n){
    cin >> s.at(i);
    sum += s.at(i);
  }
  sort(s.begin(),s.end());
  rep(i,n) if( s.at(i)%10 == 0 ) b.at(i) = true;
  
  for(int i=0;i<n;i++){
    if( sum%10 != 0 ) break;
    if( !b.at(i) ){
      sum -= s.at(i);
    }
  }
  
  cout << (sum%10==0 ? 0 : sum) << endl;
  
    
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        //final int []a = new int[m];
        long sum = 0;
        for (int i =0;i<m;++i) sum += sc.nextInt();

        System.out.println(n-sum >= 0 ? n-sum:-1);
        sc.close();
    }
}

Measured memory_bytes: 46376
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      if ((i + 1) % 2 == 0 || a % 2 == 0) continue;
      count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 35840
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 2e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	FIO
	ll n; cin >> n;
	ll a[n], b[n], c[n];
	FOR(i, n) cin >> a[i] >> b[i] >> c[i];
	ll dp[2][3] = {};
	dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];
	for (ll i = 1; i < n; i++) {
		dp[1][0] = a[i] + max(dp[1 - 1][1], dp[1 - 1][2]);
		dp[1][1] = b[i] + max(dp[1 - 1][0], dp[1 - 1][2]);
		dp[1][2] = c[i] + max(dp[1 - 1][0], dp[1 - 1][1]);
		dp[0][0] = dp[1][0];
		dp[0][1] = dp[1][1];
		dp[0][2] = dp[1][2];
	}
	cout << max({dp[0][0], dp[0][1], dp[0][2]}) << endl;
	return 0;
}


Measured memory_bytes: 5964
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a<=c&&c<=b?"Yes":"No")<<endl;
}


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

Measured memory_bytes: 256
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r, l;
	char s;
	cin >> r >> s >> l;
	if (s == '+') {
		cout << r+l;
		return 0;
	}
	cout << r - l;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) 
N,M,Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int, input().split())

ans = 0
def dfs(L):
    global ans
    if len(L) == N+1:
        sumnum = 0
        for i in range(Q):
            if L[b[i]] - L[a[i]]==c[i]:
                sumnum += d[i]
        ans = max(ans, sumnum)
        return 0
    A = L.copy()
    A.append(A[-1])
    while A[-1] <= M:
        dfs(A)
        A[-1]+=1

dfs([1])
print(ans)

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

using namespace std;

int S, N, a[2017];
bitset < 2000001 > maybe;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]), S += a[i];
S ++, S>>=1, maybe[0] = 1;
for (int i=1; i<=N; i++)
    maybe |= (maybe << a[i]);
while (maybe[S] == 0) S ++;
printf ("%d\n", S);
return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int> a(n);
  for (auto& x : a) std::cin >> x;
  auto err = [&] {
    std::cout << "No" << std::endl;
    exit(0);
  };
  int prv = 0;
  for (auto& x : a) {
    if (prv > x) {
      x++;
    }
    if (prv > x) err();
    prv = x;
  }
  assert(std::is_sorted(a.begin(), a.end()));
  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll n,ans=0;
   cin>>n;
  ll a[n+1]={0};
   for(ll i=1;i<=n;i++){
     for(ll j=i;j<=n;j+=i){
       a[j]++;
     }
 	
   }
  for(ll i=1;i<=n;i++){
    ans+=(i*a[i]);
  }
    cout<<ans<<endl;

}


Measured memory_bytes: 81728
a1=list(map(int, input().split()))
a2=list(map(int, input().split()))
a3=list(map(int, input().split()))
n=int(input())

for i in range(n):
    b=int(input())
    for i in range(3):
        if a1[i] == b:
            a1[i] = 0
        elif a2[i] == b:
            a2[i] = 0
        elif a3[i] == b:
            a3[i] = 0
    
if a1[0] == 0 and a1[1] == 0 and a1[2] == 0:
    print('Yes')
elif a2[0] == 0 and a2[1] == 0 and a2[2] == 0:
    print('Yes')
elif a3[0] == 0 and a3[1] == 0 and a3[2] == 0:
    print('Yes')
elif a1[0] == 0 and a2[0] == 0 and a3[0] == 0:
    print('Yes')
elif a1[1] == 0 and a2[1] == 0 and a3[1] == 0:
    print('Yes')
elif a1[2] == 0 and a2[2] == 0 and a3[2] == 0:
    print('Yes')
elif a1[0] == 0 and a2[1] == 0 and a3[2] == 0:
    print('Yes')
elif a1[2] == 0 and a2[1] == 0 and a3[0] == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n = int(input())

count=0
i = 1
A= []
for j in range(1, n+1, 2):
    while(i*i<=j):
        if(j%i==0):
            count+=1
        i+=1
    if(count==4):
        A.append(j)
    i = 1
    count=0

print(len(A))

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

void no() {
  printf("NO\n");
  exit(0);
}

vector <int> v, w;
int main(){
  int n;
  int m;
  int a, b;

  scanf("%d",&n);

  REP (i, n) {
    scanf("%d", &a);
    v.push_back(a);
  }
  sort(v.begin(), v.end());

  scanf("%d",&m);

  REP(i, m) {
    scanf("%d",&b);
    w.push_back(b);
  }
  if (n < m) no();

  sort(v.begin(), v.end());
  sort(w.begin(), w.end());

  int i = 0;
  int j = 0;
  while (i < int(w.size()) && j < int(v.size())) {
    if (w.at(i) == v.at(j)) {
      i++;
      j++;
    } else if (w.at(i) > v.at(j)) {
      j++;
    } else {
      no();
    }
  }

  if (i == int(w.size())) printf("YES\n");
  else no();
}


Measured memory_bytes: 2548
A = list(map(int,input().split()))
L = A[0]
R = A[1]
if R - L >= 673:
    print(0)
else:
    B = []
    C = []
    for _ in range(L,R + 1):
        B.append(_ % 2019)
    k,l = 0,1
    count = 0
    N = len(B)
    while k < N - 1:
        while l < N:
            C.append((B[k] * B[l]) % 2019)
            l += 1
        k += 1
        l = k + 1
    print(min(C))

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

int main(void){
  int k,a,b,ans;
  
  cin >> k >> a >> b;
  ans=0;
  for (int i=a; i<=b; i++) ans |= (i%k==0);
  cout << (ans?"OK":"NG") << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

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

    cout << N-i+1 << endl;

    return 0;
}

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

signed main() {
 	ios::sync_with_stdio(false);
  			cout.tie(nullptr);
  			cin.tie(nullptr);

  			int n,x;
  			string a = "No";
  			cin >> n;
  			x=n;
  			while (x)
  			{
  				
  				if(x%10 == 7){
  					a = "Yes";
  					break;
  				}
  				x= x/10;
  			}
cout << a;
  		}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> l(q), r(q);
  for (int i = 0; i < q; i++) cin >> l.at(i) >> r.at(i);
  vector<int> ac(n);
  ac.at(0) = 0;
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    if (s.at(i - 1) == 'A' && s.at(i) == 'C') cnt++;
    ac.at(i) = cnt;
  }
  for (int i = 0; i < q; i++)
    cout << ac.at(r.at(i) - 1) - ac.at(l.at(i) - 1) << endl;
}

Measured memory_bytes: 2176
n=int(input())

robot=[]

for _ in range(n):
    x,l=map(int,input().split())
    robot.append([x-l,x+l])
robot.sort()



RR=robot[0][0]-1
cnt=0

for item in robot:
    if RR<=item[0]:
        cnt+=1
        RR=item[1]
    elif RR>=item[1]:
        RR=item[1]

print(cnt)




Measured memory_bytes: 60032
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const int MAX_N = 1<<19;
 
/*    BIT  sum:O(logN)   add:O(logN)  */
 
//[1,n]
class BIT{
public:
  int bit[MAX_N+1],n;
  BIT(){memset(bit,0,sizeof(bit));}
  BIT(int n){this->n=n,memset(bit,0,sizeof(bit));}
 
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
   
  void add(int i,int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
};
 
 
ll n,p,Q;
PP C[MAX_N];
 
int main(){
  cin>>n>>p>>Q;
  BIT B(n);
 
  for(int i=0;i<n;i++){
    cin>>C[i].s.f;
    C[i].s.s=i+1;
    C[i].f=-(n-i-1)*p+C[i].s.f;
  }
  sort(C,C+n,greater<PP>());
 
  ll sum=n*(2*Q*p+(n-1)*p)/2,ans=sum;
  for(int i=0;i<n;i++){
    ll idx=C[i].s.s,cost=C[i].s.f;
    ll l=B.sum(idx),r=i-l;
    sum+=-(Q+(idx-1)-l*2)*p-(n-idx-r)*p*2+cost;
    B.add(idx,1);
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
   
  return 0;
}

Measured memory_bytes: 17440
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 8000
int a[N][27];
int a2[N][27];
int e[N][365];
int v[N][365];
int sz, sz2;

int main() {
	int n;
	int x, y;
	vector<pair<int, pair<int, int> > >b;
	int c[26];
	int d[365][26];
	bool dd[365][26];
	vector<int>ds;
	int ans[365];
	scanf("%d", &n);
	f(i, 26)scanf("%d", &c[i]);
	f(i, n) {
		f(j, 26)scanf("%d", &d[i][j]);
		ds.clear();
		f(j, 26)ds.push_back(-d[i][j]);
		sort(ds.begin(), ds.end());
		f(j, 26) {
			if ((d[i][j] + ds[7]) > 0)dd[i][j] = true;
			else dd[i][j] = false;
		}
	}
	sz = 1;
	f(i, 26)a[0][i] = -1;
	a[0][26] = 0;
	f(t, n) {
		b.clear();
		f(i, sz) {
			x = a[i][26];
			f(j, 26) {
				x -= ((t - a[i][j])*c[j]);
			}
			f(j, 26) {
				if (dd[t][j]) {
					y = x + d[t][j];
					y += ((t - a[i][j])*c[j]);
					b.push_back(make_pair(y, make_pair(i, j)));
				}
			}
		}
		sort(b.begin(), b.end(), greater<pair<int, pair<int, int> > >());
		sz2 = b.size();
		if (sz2 > N)sz2 = N;
		f(i, sz2) {
			x = b[i].second.first;
			y = b[i].second.second;
			a2[i][26] = b[i].first;
			f(j, 26)a2[i][j] = a[x][j];
			a2[i][y] = t;
			e[i][t] = x;
			v[i][t] = y;
		}
		f(i, sz2) {
			f(j, 27)a[i][j] = a2[i][j];
		}
		sz = sz2;
	}
	x = 0;
	for (int i = n - 1; i >= 0; i--) {
		ans[i] = v[x][i];
		x = e[x][i];
	}
	f(i, n)printf("%d\n", ans[i] + 1);

	return 0;
}


Measured memory_bytes: 28312
/*
*  author: mkbaloch
*  time:   2020-01-13 15:40:39
*/

#include<bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define repn(i, n) for(int i=0; i<(int)n; i++)

using namespace std;

int main()
{
 ll n, x;
 cin >> n >> x;
 if(n * 500 >= x) cout << "Yes" << endl;
 else cout << "No" << endl;
 return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
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; }

long N,i,ans;
vector<long> A,B;
vector<pair<long,long> > v;

inline void solve(){
  IN(N);
  A.resize(N);
  B.resize(N);
  REP(i,N){
    IN2(A[i],B[i]);
    v.pb(mp(A[i]+B[i],i));
  }
  sort(RALL(v));
  REP(i,N){
    if(i&1)ans-=B[v[i].second];
    else ans+=A[v[i].second];
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0,inf=1e9+7;cin>>n;
  ll powsix=1,pownine=1;
  lvector v{1,1,1,1,1};
  while(powsix*6<=n) {
    powsix*=6;
    rep(i,20) v.emplace_back(powsix);
  }
  while(pownine*9<=n) {
    pownine*=9;
    rep(i,20) v.emplace_back(pownine);
  }
  sort(v.begin(),v.end());
  ll l=v.size();
  lvector dp_(n+10,inf);
  vector<lvector> dp(l+10,dp_);
  dp[0][0]=0;
  for(ll i=0;i<l;++i) {
    for(ll j=0;j<=n;++j) {
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      if(j>=v[i]) dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+1);
    }
  }
  print(dp[l][n]);
  return 0;
}

Measured memory_bytes: 185344
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> friendly(n);
    for(int i=0; i<n; i++){
        cin >> friendly.at(i);
    }
    sort(friendly.begin(), friendly.end());
    reverse(friendly.begin(), friendly.end());
    int64_t ans=0;
    for(int i=0; i<n; i++){
        ans += friendly.at(i/2);
    }
    cout << ans - friendly.at(0) << endl;
}

Measured memory_bytes: 4048
import Control.Monad

data Card = Card {  suit :: [Char]
                  , number :: Int
                 }

instance Eq Card where
  x == y = suit x == suit y && number x == number y

cardToStr :: Card -> String
cardToStr (Card s n) = s ++ " " ++ show n ++ "\n"

creationCardByNumbers :: [Card] -> [Char] -> Int -> Int -> [Card]
creationCardByNumbers ec s n nn
  | n > nn = []
  | otherwise = findExistCard [Card s n] ec ++ creationCardByNumbers ec s (n + 1) nn

creationCardBySuits ec [] = []
creationCardBySuits ec (x:xs) = creationCardByNumbers ec x 1 13 ++ creationCardBySuits ec xs

findExistCard :: [Card] -> [Card] -> [Card]
findExistCard c [] = c
findExistCard c (x:xs)
  | c == [x] = []
  | otherwise = findExistCard c xs

enumExCd [] = []
enumExCd (x:xs) = [Card ta tb] ++ enumExCd xs
  where
    ta = words x !! 0
    tb = (read :: String -> Int) $ words x !! 1

ft _ [] = []
ft f (x:xs) = f x ++ ft f xs

main = do
  n <- readLn :: IO Int
  ss <- replicateM n getLine
  let exCd = enumExCd ss
  let suits = ["S","H","C","D"]
  putStr $ ft cardToStr $ creationCardBySuits exCd suits

Measured memory_bytes: 4128
using System;
class Program{
static void Main(string[] args){
var N = int.Parse(Console.ReadLine());
var min = 99999;
for(int i=1;i<N;i++){
var A = i;
var B = N-i;
A = CalcDigitSum(A);
B = CalcDigitSum(B);
if(A + B < min){
min = A + B;
}
}
Console.WriteLine(min);
}
static int CalcDigitSum(int num){
var txt = num.ToString();
var res = 0;
foreach(char c in txt){
res += int.Parse(c.ToString());
}
return res;
}
}

Measured memory_bytes: 17352
def win(N, n, K):
  cnt = n
  inc = 0
  while cnt<K:
    cnt *= 2
    inc += 1
  return (1/N)*0.5**inc
  

N, K = [int(i) for i in input().strip().split()]

total = 0
for n in range(1, N+1): 
  total += win(N, n, K)
print(total)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
import itertools

N=int(input())
x = []
y = []
for _ in range(N):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
ls = []
for arr in itertools.permutations(list(range(N))):
    l = 0
    for ii in range(len(arr)-1):
        i = arr[ii]
        j = arr[ii+1]
        d = ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
        l += d
    ls.append(l)

print(sum(ls)/len(ls))





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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;

int main(){
    int N ,M;
    double A[101],sum=0.0,ans;
    string s;
    cin >>N;
    rep(i,N){
        cin >> A[i];
        sum += (1.00/A[i]);
    } 
    ans = (1.0/sum);

    cout << ans << endl;
    
    
    return 0;
    

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int A = input.nextInt();
        int B = input.nextInt();
      	int K = input.nextInt();
      
      	if (A > B) {
        	int tmp = A;
          	A = B;
          	B = tmp;
        }
      	int[] ab = new int[A];
      	int index = 0;
      
      	for (int i = 1; i <= A; i++) {
        	if (A % i == 0 && B % i == 0) {
              	ab[index] = i;
              	index++;
            }
        }
      
      System.out.print(ab[index - K]);

    }
}


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

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

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

	vector<string> arr(N);
	rep(i, N) {
		cin >> arr[i];
	}

	sort(arr.begin(), arr.end());

	int max_cnt = 0;
	string current;
	int cnt = 0;
	rep(i, N) {
		if (current != arr[i]) {
			cnt = 0;
		}
		current = arr[i];
		++cnt;
		if (max_cnt < cnt) max_cnt = cnt;
	}

	current = "";
	rep(i, N) {
		if (current != arr[i]) {
			cnt = 0;
		}
		current = arr[i];
		++cnt;
		if (max_cnt == cnt)
			cout << current << endl;
	}
}

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

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, m = 1, d = 1;

double f(ll x) {
	ll s = 0, t = x;
	while (t) s += t%10, t /= 10;
	return 1.*x/s;
}

signed main() {
	cin >> n;
	reps(i,1,n+1) {
		cout << m << endl;
		double l = f(m+d), r = f(m+d*10);
		if (l>r) d *= 10;
		m += d;
	}
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int h=scanner.nextInt();
		int w=scanner.nextInt();
		int cnt=0;
		for(int i=0;i<n;i++) {
			int a=scanner.nextInt();
			int b=scanner.nextInt();
			if(a>=h&&b>=w)cnt++;
		}
		System.out.println(cnt);
	}
}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int64_t res = 0;
  unordered_map<string, int64_t> mp;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    res += mp[s]++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 10660
<?php
  
fscanf(STDIN,"%s", $S);

$count = array("a" => 0, "b" => 0, "c" => 0);

for($i=0; $i<3; $i++){
  $char=$S[$i];
  if(array_key_exists($char,$count)){
    $count[$char] ++;
  }
}
if($count["a"] == 1 && $count["b"] == 1 && $count["c"] == 1){
 echo "Yes";
}else{
 echo "No";
}



Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    int count = 0;
    cin >> N;
    vector<int> p(N);
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    for(int i=0; i<N; i++){
        if(p[i] == i+1){
            swap(p[i], p[i+1]);
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
x=int(input())
A=10**6
pn=[2]
for L in range(3, A, 2):
    if x==2:
        print(2)
        exit()
    if all(L % L2 != 0 for L2 in pn):
        pn.append(L)
        if L>=x:
            k=L
            break
print(k)

Measured memory_bytes: 43740
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node {int parent, left, right;};  // 木の構造体，親，左の子，右の子を設定

Node T[MAX];
int n, D[MAX], H[MAX];  // D, Hはそれぞれ深さと高さの配列

void setDepth(int u, int d)
{
    if (u == NIL) return;  // 端点まで行ったら終了
    D[u] = d;  // D[u]を節点uの深さとする
    // 左右の子を探索して端点までの距離を探る
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
    int h1 = 0, h2 = 0;  // 高さの初期値を0とする
    if (T[u].left != NIL) {  // 左端まで探索して，探索するごとに高さをインクリメントする
        h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {  // 右端まで探索して，探索するごとに高さをインクリメントする
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = (h1 > h2 ? h1 : h2);  // 最も高くなるleafを出力する
}

// 節点uの兄弟を返す
int getSibling(int u)
{
    if (T[u].parent == NIL) {  // 親がいなければ0
        return NIL;
    }
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {  // 自分が親の左の子でなく，左の子が入れば左を返す
        return T[T[u].parent].left;
    }
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {  // 自分が親の右の子でなく，左の子が入れば左を返す
        return T[T[u].parent].right;
    }
    return NIL;  // 上記以外ならば0
}

void print(int u)
{
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) {  // もし左の子がいれば次数をインクリメント
        deg++;
    }
    if (T[u].right != NIL) {  // もし右の子がいれば次数をインクリメント
        deg++;
    }
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if (T[u].parent == NIL) {  // 親がいなければroot
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL) {  // 子どもがいなければleaf
        printf("leaf\n");
    } else {  // 上記以外なら内部節点
        printf("internal node\n");
    }
}

int main()
{
    int v, l, r, root = 0;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        T[i].parent = NIL;
    }

    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) {
            T[l].parent = v;
        }
        if (r != NIL) {
            T[r].parent = v;
        }
    }

    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) {
            root = i;
        }
    }

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++) {
        print(i);
    }

    return 0;
}


Measured memory_bytes: 2708
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

vector<int> g[256];
int dist[256];
int couleur[256];

void init(){
	for( int i = 0; i < 256; ++i ) dist[i] = -1;
}

bool dfs( int p, int f ){
	couleur[p] = f;
	for( auto nextp : g[p] ){
		if( couleur[nextp] == f ) return false;
		if( couleur[nextp] == 0 && !dfs(nextp, (-1)*f) ) return false;
	}
	return true;
}

int main(){
	init();
	int n; cin >> n;
	for( int i = 0; i < n; ++i ){
		string s; cin >> s;
		for( int j = i; j < n; ++j ){
			if( s[j] == '1' ){
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
	}
	if( !dfs(0, 1) ){
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	for( int s = 0; s < n; ++s ){
		queue<int> q;
		q.push(s);
		dist[s] = 1;
		while( !q.empty() ){
			int p = q.front(); q.pop();
			for( auto nextp : g[p] ){
				if( dist[nextp] == -1 ){
					q.push(nextp);
					dist[nextp] = dist[p]+1;
				}
			}
		}
		for( int i = 0; i < n; ++i ) ans = max(ans, dist[i]);
		init();
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <numeric>//iota头文件
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int N;
int arr[100];
int main(){
    int coun = 0;
    cin>>N;
    for(int i = 0;i<N;i++){
        scanf("%d",&arr[i]);
    }
    for(int i = 2;i<N;i++){
        if(arr[i-2]< arr[i-1] && arr[i-1]< arr[i]){
            coun++;
        } else if(arr[i-2] > arr[i-1] && arr[i-1] > arr[i]){
            coun++;
        }
    }
    cout<<coun<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<sstream>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>
#include<iomanip>
#define LL long long
using namespace std;

int n,m,a[15][10010],b[10010];

int qp(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}

int main(void){
    while(scanf("%d %d",&n,&m)!=EOF && (n+m)){
      int i,j,k;
      for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
      }
      memset(b,0,sizeof(b));
      for(j=0;j<m;j++){
        for(i=0;i<n;i++){
            if(a[i][j]==1) b[j]++;
        }
      }
      int ans=0,maxi=qp(2,n);
      for(i=0;i<maxi;i++){
        int now=0;
        for(j=0;j<m;j++){
          int x=b[j];
          for(k=0;(1<<k)<=i;k++){
            if((1<<k)&i){
              if(a[k][j]==1) x--;
              else x++;
            }
          }
          now+=max(x,n-x);
        }
        ans=max(ans,now);
      }
      printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void mysort(vs &a) {sort(a.begin(), a.end());}

int main() {
  int n;
  cin >> n;
  vs w(n), v(n);
  for (int i = 0; i < n; i++) cin >> w[i];
  v = w;
  mysort(v);
  for (int i = 1; i < n; i++) {
    if (v[i - 1] == v[i]) {
      No();
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (w[i - 1].back() != w[i].front()) {
      No();
      return 0;
    }
  }
  Yes();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U>
void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define OUTPUT(...) ostream& operator<<(ostream& os, __VA_ARGS__ const& v) { os << "{"; for (auto const& x : v) os << " " << x; return os << " }"; }
template <class T> OUTPUT(vector<T>)
template <class T> OUTPUT(deque<T>)
template <class T> OUTPUT(set<T>)
template <class T> OUTPUT(multiset<T>)
template <class T, class U> OUTPUT(map<T,U>)
#undef OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } my_init;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
////////////////////////////////

int32_t main() {
    int n; cin >> n;
    vector<int> s(n); cin >> s;

    int ma = 0;
    loop (ab,1,<n) {
        int sum = 0, i = 0, j = n-1;
        for ( ; i+ab < n-1; i += ab, j -= ab) {
            if ((n-1)%ab == 0 && i >= j) break;
            sum += s[i] + s[j];
            chmax(ma,sum);
        }
    }
    cout << ma << "\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int n,H,W;
int memo[65536];
int visi[65536];
vector<int> mask1,mask2;

vector< vector<char> > goal(4,vector<char>(4));

int w[20],h[20];

int gen(int s,int x,int y){
	rep(k,3){
		int a=0,b=0;
		rep(i,h[s]){
			rep(j,w[s]){
				int tx = x + j;
				int ty = y + i;
				if(tx >= 0 && tx < 4 && ty < 4 && ty >= 0){
						a |= 1<<(ty*4+tx);
						b |= (goal[ty][tx] == k)<<(ty*4+tx);
				}
			}
		}
		mask1.push_back(a);
		mask2.push_back(b);
	}
}
int f(int init){
	queue<int> Q;
	Q.push(init);
	memo[init] = 0;
	int good = (1<<16)-1;
	while(Q.size()){
		int q = Q.front(); Q.pop();
		int cost = memo[q];
		if(good == q) return cost;
		
		rep(i,mask1.size()){
			int bit = (q & ~mask1[i]) | mask2[i];
			if(!visi[bit]){
				visi[bit] = 1;
				memo[bit] = cost + 1;
				Q.push(bit);
			}
		}
	}
	

}

int main(){
	cin >> n;
	rep(i,n) cin >> h[i] >> w[i];
	rep(i,4)rep(j,4){
		char c;cin >> c;
		if(c=='R')c = 0;
		if(c=='G')c = 1;
		if(c=='B')c = 2;
		goal[i][j] = c;
	}
	
	rep(k,n){
		rep(i,7)rep(j,7){
			gen(k,i-3,j-3);
		}
	}

	
	cout << f(0) << endl;
	
	
}

Measured memory_bytes: 1544