akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<array>
#include<algorithm>
using namespace std;


array<array<bool, 17>, 17> temp;

int func(int x, int y) {
	if (x == 1 && y == 1 && temp[x - 1][y - 1] == false) {
		return 1;
	}
	else if (x == 0 || y == 0) {
		return 0;
	}
	else if (temp[x - 1][y - 1] != false) {
		return 0;
	}
	else {
		return func(x - 1, y) + func(x, y - 1);
	}
}

int main() {

	while (true) {
		int a, b, n;
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			break;
		}
		scanf("%d", &n);

		fill(temp.begin(), temp.end(), array<bool, 17>{});

		for (int i = 0; i < n; ++i) {
			int x, y;
			scanf("%d %d", &x, &y);
			temp[x - 1][y - 1] = true;
		}
		int temp3 = func(a, b);
		printf("%d\n", temp3);
	}

	return 0;
}

Measured memory_bytes: 2696
import sys

n = int(input())
  
f = sum(range(0, n+1, 3))
b = sum(range(0, n+1, 5))
fb = sum(range(0, n+1, 15))
total = (n * (n + 1)) / 2

# print(f, b, fb)
# print(total)
print(int(total - f -b + fb))

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

using namespace std;


int main(){
    int N,Q;
    char a;
    int count = 0;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q),r(Q);
    for(int i=0;i<Q;i++){
        cin >> l.at(i) >> r.at(i);
    }

    for(int i=0;i<N-1;i++){
        if(S.at(i)=='A' && S.at(i+1)=='C'){
            S.at(i) = 'a';
        }
    }
    vector<int> sum(N,0);
    int o = 0;
    for(int i=0;i<N;i++){

        if(S.at(i)=='a') {
            sum.at(i) = o;
            o++;
        }
        else sum.at(i) = o;
    }

    for(int i=0;i<Q;i++){
        cout << sum.at(r.at(i)-1) - sum.at(l.at(i)-1) << endl;
    }

    
}


Measured memory_bytes: 2176
N = int(input())
c = input()

x =[0] * N

ww = 0
rr = 0
for i, cc in enumerate(c):
    if cc == "R":
        x[i] = 1
        rr += 1
    else:
        ww += 1

cmd = 0
for i in range(rr):
    if x[i] == 0:
        cmd += 1

cmd2 = 0
for j in range(rr+1, len(x)):
    if x[j] == 1:
        cmd2 += 1


print(max(cmd, cmd2))




Measured memory_bytes: 69692
#include <stdio.h>

int main(void){
	int i,j,ans=0;

  int n;

  scanf("%d",&n);

  int p[n+1];

  for(i=1;i<=n;i++){
    scanf("%d",&p[i]);
  }

  for(i=1;i<n-1;i++){
    if(p[i]<p[i+1]&&p[i+1]<p[i+2]){
      ans++;
    }else if(p[i]>p[i+1]&&p[i+1]>p[i+2]){
      ans++;
    }
  }

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

	return 0;
}


Measured memory_bytes: 128
# Tenka1 2017 C

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    for h in range(1, 3501):
        for w in range(1, 3501):
            upper = N * h * w
            lower = 4 * h * w - N * w - N * h
            if lower == 0 or upper % lower != 0:
                continue

            n = int(upper / lower)
            if n > 0:
                print(h, n, w)
                return


main()

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

ll rec (ll i, ll j) {
    if (i == 1) return 1;
    else return rec(i / 2, j + 1) * 2 + 1;
}

int main(){
    ll h;
    cin >> h;

    cout << rec(h, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	int H,W;
	cin>>H>>W;
	int A[H][W];
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			A[i][j]=0;
		}
	}
	char P[H][W];
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cin>>P[i][j];
		}
	}
	A[0][0]=1;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if(P[i][j]=='#')
			{
				A[i][j]=0;
			}
			else
			{
				if(i-1>=0)
				{
					A[i][j]=(A[i][j]+A[i-1][j])%MOD;
				}
				if(j-1>=0)
				{
					A[i][j]=(A[i][j]+A[i][j-1])%MOD;
				}
			}
		}
	}
	cout<<A[H-1][W-1]<<endl;
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

Measured memory_bytes: 5120
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s = gete()

    a = (1 <= int(s[:2]) <= 12)
    b = (1 <= int(s[2:]) <= 12)

    if a:
        if b:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if b:
            print("YYMM")
        else:
            print("NA")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let N = input[0].split(' ')[0]
	let S = input[1].split(' ')[0]
	let Xs = []
	let x = 0
	Xs.push(x)
	for(let i = 0; i < N; i++) {
		if(S[i] === 'D') {
			Xs.push(--x)
		} else {
			Xs.push(++x)
		}
	}
	console.log(Math.max(...Xs))
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
check = [1,9,7,4]

n1,n2,n3,n4 = map(int,input().split())

if n1 in check:
    check.remove(n1)
if n2 in check:
    check.remove(n2)
if n3 in check:
    check.remove(n3)
if n4 in check:
    check.remove(n4)

if len(check) == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	int cnt = 1;
	int max = h[0];
	for (int i = 1; i < n; i++) {
		if (max <= h[i]) {
			max = h[i];
			cnt++;
		}
	}
	cout << cnt;

	return 0;
}

Measured memory_bytes: 256
input_first = input().split()
input_first_int = [int(i) for  i in input_first]

check_lst =[]

sorted_lst = sorted(input_first_int)


flag = 0
cnt  =0
for i in range(2):
    if sorted_lst[i] == sorted_lst[i+1]:
        cnt +=1

    
if cnt ==1:
    print('Yes')
else :

    print('No')


Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        ArrayList<Integer> l = new ArrayList<Integer>();
        for (int i=0; i<n; i++) {
            int s = sc.nextInt();
            if (s%10!=0) l.add(s);
            sum += s;
        }
        
        Collections.sort(l);

        if (sum%10==0){
            if (l == null || l.size()==0){
                System.out.println(0);
            }
            else {
                System.out.println(sum-l.get(0));
            }
        }
        else {
            System.out.println(sum);
        }
        //System.out.println("yes");
        sc.close();
    }
}

Measured memory_bytes: 35916
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    map<pair<int, int>, int> m;
    vector<pair<int, int>> b;
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        b.push_back({x, y});
    }
    sort(b.begin(), b.end());

    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int dx = b[j].first - b[i].first;
            int dy = b[j].second - b[i].second;
            pair<int, int> p = {dx, dy};
            m[p]++;
        }
    }
    int ma = 0;
    for (auto itr : m) {
        ma = max(ma, itr.second);
    }
    cout << N-ma << endl;
}   


Measured memory_bytes: 384
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
//--Container
//
typedef long long ll;
typedef pair<int,int> pi;

int n,dy;

void cl(){
	int i,j,k,rs[3]={-1,-1,-1};scanf("%d %d",&n,&dy);dy/=1000;
	for(k=0;k<=n&&k<=dy;++k)if(!((dy-k)%5)){
		int dx=(dy-k)/5;for(j=0;j+k<=n&&dx>=j;++j)if(!((dx-j)&1)){
			if((n-j-k)*2==(dx-j))
				rs[0]=n-j-k,rs[1]=j,rs[2]=k;
		}
	}
	printf("%d %d %d\n",rs[0],rs[1],rs[2]);
};

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

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,t;

int main() {
    cin >> n >> t;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    Rep(i,n){
        cin >> a[i];
    }
    b[n-1]=a[n-1];
    for(int i=n-1;0<i;--i){
        b[i-1] = max(b[i],a[i-1]);
    }
    Rep(i,n){
        c[i] = b[i]-a[i];
    }
    int m = *max_element(all(c));
    put(count(all(c),m));
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{

    string arr[]={ "SUN", "MON", "TUE", "WED", "THU", "FRI",  "SAT"};
    string x;
    cin>>x;
    int pos,counter =0;

    for (int i=0; i<7; i++){
        if (arr[i] ==x)
            pos =i;
    }

    while (true){
        if (arr[pos] == "SUN"){
            break;
        }
        counter++;
        pos = (pos+1)%7;
    }
    if (counter)
        cout<<counter;
    else
        cout <<7;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> h(n+1),cost(n+1,1000000000);
    rep(i,0,n-1)cin >> h[i];
    h[n] = 1000000000;

    cost[0] = 0;
    rep(i,0,n-2){
        cost[i+1] = min(cost[i+1],cost[i]+abs(h[i]-h[i+1]));
        cost[i+2] = min(cost[i+2],cost[i]+abs(h[i]-h[i+2]));
    }

    int ans = cost[n-1];

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cctype>

using namespace std;

string revJ(string t){
  string ret = t;
  ret.insert(ret.begin(),t[t.length()-1]);
  ret.erase(ret.end()-1);
  return ret;
}
string revC(string t){
  string ret = t;
  ret += t[0];
  ret.erase(ret.begin());
  return ret;
}
string revE(string t){
  char c=0;
  if(t.length()==1)return t;
  if(t.length()%2){
    c = t[t.length()/2];
    t.erase(t.begin()+t.length()/2);
  }
  string l = t.substr(0,t.length()/2);
  string r = t.substr(t.length()/2,t.length()-t.length()/2);
  if(c){
    return r+c+l;
  }else return r+l;
}
string revA(string t){
  string ret = t;
  reverse(ret.begin(),ret.end());
  return ret;
}
string revP(string t){
  //dec
  string ret = t;
  for(int i = 0; i < (signed)ret.length(); ++i){
    if( isdigit(ret[i]) ){
      ret[i]--;
      if(ret[i]<'0')ret[i]='9';
    }
  }
  return ret;
}
string revM(string t){
  //inc
  string ret = t;
  for(int i = 0; i < (signed)ret.length(); ++i){
    if( isdigit(ret[i]) ){
      ret[i]++;
      if(ret[i]>'9')ret[i]='0';
    }
  }
  return ret;
}

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i){
    string order;
    string msg;
    cin >> order >> msg;
    for(int i = (int)order.length()-1; i>=0; --i){
      if( order[i] == 'J' ){
	msg = revJ( msg );
      }
      if( order[i] == 'C' ){
	msg = revC( msg );
      }
      if( order[i] == 'E' ){
	msg = revE( msg );
      }
      if( order[i] == 'A' ){
	msg = revA( msg );
      }
      if( order[i] == 'P' ){
	msg = revP( msg );
      }
      if( order[i] == 'M' ){
	msg = revM( msg );
      }
    }
    cout << msg << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, m;
    cin >> n >> m;
    ll sx[n], sy[n], cx[m], cy[m];
    for (int i = 0; i < n; i++) {
        cin >> sx[i] >> sy[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> cx[i] >> cy[i];
    }
    ll d, min, min_num;
    for (int i = 0; i < n; i++) {
        min = LLMAX;
        for (int j = 0; j < m; j++) {
            d = abs(sx[i] - cx[j]) + abs(sy[i] - cy[j]);
            if (min > d) {
                min = d;
                min_num = j;
            }
        }
        cout << min_num + 1 << endl;
    }
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	long long int a[n][3];
	long long int dp[n][3];
	for(int i=0;i<n;i++)
	{
	    for(int j=0;j<3;j++)
	    cin>>a[i][j];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++)
	{
	    int j=0;
	    if(j==0)
	    {
	        dp[i][j] = max(dp[i-1][1],dp[i-1][2]) + a[i][j];
	    }
	    j++;
	    if(j==1)
	    {
	        dp[i][j] = max(dp[i-1][0],dp[i-1][2]) + a[i][j];
	    }
	    j++;
	    if(j==2)
	    {
	        dp[i][j] = max(dp[i-1][1],dp[i-1][0]) + a[i][j];
	    }
	}
	    long long int x=0;
	    for(int j=0;j<3;j++)
	    {
	     x= max(x,dp[n-1][j]);  
	    }
	    cout<<x;
	return 0;
}

Measured memory_bytes: 4992
s = input()
t = input()
s = s[::-1]
t = t[::-1]
s_size, t_size = len(s), len(t)
result = "UNRESTORABLE"

for i in range(s_size - t_size + 1):
    for j in range(t_size):
        if s[i + j] != t[j] and s[i + j] != '?':
            break
    else:
        break
else:
    print(result)
    exit()
s = (s[:i] + t + s[i + t_size :]).replace('?', 'a')
result = s[::-1]
print(result)


Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <iostream>
#include <array>

using namespace std;

int main() {
	string S;
	int s0 = 0;
	int s1 = 0;
	int ans = 0;
	int t;
	
	// 入力
	cin >> S;
	
	for(int i=0; i<S.length(); i++){
		t = (S[i] == '0') ? 0 : 1;
		if(t == i%2){
			s1++;
		}else{
			s0++;
		}
	}
	
	ans = (s0 < s1) ? s0 : s1;
	
	// 出力
	printf("%d\n", ans);
	return 0;
	
}

Measured memory_bytes: 512
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
    exit()

c = {}
for i in D:
    if i in c:
        c[i] += 1
    else:
        c[i] = 1

if c[0] != 1:
    print(0)
    exit()

result = 1
for i in range(1, max(D) + 1):
    if i not in c:
        print(0)
        exit()
    result *= pow(c[i - 1], c[i], 998244353)
    result %= 998244353
print(result)

Measured memory_bytes: 19552
s = input()
cnt = 0
if s.count('R') == 3:
  print(3)
  exit()
elif s[1] == 'R' and (s[0] == s[1] or s[1] == s[2]):
  print(2)
  exit()
elif s.count('R') >= 1:
  print(1)
  exit()
else:
  print(0)

Measured memory_bytes: 9080
# グループ分けの数を最初に分かっていれば、いい
n, k = map(int, input().split())
a_tmp = input().split()
a = []
for _ in a_tmp:
    a.append(int(_))
g = 1
while n > (k + (k-1)*(g-1)):
    g += 1
print(g)


Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b;
  in2(a, b);
  if(a > b)
    out(2 * a - 1);
  else if(a == b)
    out(2 * a);
  else
    out(2 * b - 1);
  memi;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s[55];

string solve() {
    stringstream ss;
    for (char c = 'a'; c <= 'z'; c++) {
        int t = inf, cnt;
        for (int i = 0; i < n; i++) {
            cnt = 0;
            for (int j = 0; j < s[i].size(); j++) {
                if (s[i][j] == c)
                    cnt++;
            }
            t = min(t, cnt);
        }
        for (int i = 0; i < t; i++) ss << c;
    }
    return ss.str();
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];
}

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

    input();
    cout << solve() << endl;
}


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

int main() {
  int a,b;
  int k;
  cin >> a >> b;
  cin >> k;
  int cnt = 0;
  for(int ans = max(a,b); ans > 0; ans--){
    if(a % ans == 0 && b % ans == 0){
      cnt++;
    }
    if(k == cnt){
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {

    int n;
    cin >> n;
    Vec<int> d(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int m;
    cin >> m;
    Vec<int> t(m, 0);
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());

    bool ans = true;
    int i = 0;
    int j = 0;
    while (1) {
        if (i == m) {
            break;
        } else if (j == n) {
            ans = false;
            break;
        }
        if (t[i] > d[j]) {
            j++;
        } else if (t[i] == d[j]) {
            i++;
            j++;
        } else {
            ans = false;
            break;
        }
    }

    if (ans == true) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,ans=0,tmp,d;
    cin>>n>>m;
    vector<int> freq(n+1);
    for(int i=0;i<m&&cin>>d;i++)
        for(int j=0;j<d&&cin>>tmp;j++)
            freq[tmp]++;
    for(int i=1;i<=n;i++)
        if(!freq[i])
            ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
  #include <iostream>
  #include <string.h>
  #include <cstring>
  #include <cmath>
  #include <math.h>
  #include <algorithm>
  #include <iomanip>
  #include <map>
  #include <set>
  #include <vector>
  #include <sstream>
  #include <queue>  
  #include <bitset>
#define MAX 100005
#define INF 9999999999999
#define pb push_back
using namespace std;
typedef long long int ll;
 typedef pair<ll,ll> ii;
 typedef vector<ii> vii;
 typedef vector <ll > vi;
vector <vii> adj(MAX);
ll arr[200005];
int main()
{
 // freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll arr[200005],n;
  cin>>n;
  ll minn=99999,maxx=0,ans=999999999;
  for(ll i=0;i<n;i++)
  {
    cin>>arr[i];
   
  }
  sort(arr,arr+n);
  cout<<arr[n-1]-arr[0]<<endl;

 return 0;
}

Measured memory_bytes: 2688
N=int(input())
L=[0]*N
for i in range(N):
    L[i]=int(input())
L.sort()
ans=0
count=0
past=L[0]
for i in range(0,N):
    if L[i]==past:
        count+=1
    else:
        past=L[i]
        ans+=count%2
        count=1

print(ans+count%2)

Measured memory_bytes: 7472
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<int,int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;


void solve(){
    
  ll a , b ,c , k;
  cin>>a>>b>>c>>k;


  ll ans = 0;
  a = min(a,k);

  ans = a;

  k = k-a-b;

  if(k>0) {
    ans = ans - k;
  }

  cout<<ans;

 
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int n,k,a[2009],ans;
int main() {
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",a+i);
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++) {
			if(a[i]>a[j]) ans=(1ll*(k+1)*k/2+1ll*ans)%MOD;
			if(a[i]<a[j]) ans=(1ll*(k-1)*k/2+1ll*ans)%MOD;
		}
	printf("%d\n",ans);
	return 0;
}

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

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

    double l = L / 3.0;
    double ans = l * l * l;
    cout << fixed << setprecision(6);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}


enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto a = iota(N).map!(i => readln.split.to!(int[])).array;

    foreach (k ; 0 .. N) {
        foreach (i ; 0 .. N) {
            foreach (j ; i + 1 .. N) {
                if (a[i][j] > a[i][k] + a[k][j]) {
                    writeln(-1);
                    return;
                }
            }
        }
    }

    long ans;

    foreach (i ; 0 .. N) {
        foreach (j ; i + 1 .. N) {
            bool used = true;
            foreach (k ; 0 .. N) {
                if (k == i || k == j) continue;
                if (a[i][j] == a[i][k] + a[k][j]) {
                    used = false;
                    break;
                }
            }
            if (used) ans += a[i][j];
        }
    }

    writeln(ans);
}


Measured memory_bytes: 6652
#pypyと実行時間比較
#最大要素の相手は一意?

from collections import Counter
n = int(input())
a = list(map(int, input().split( )))
a_c = Counter(a)

a.sort(reverse = True)
ans = 0
for i in range(n):
    if not a_c[a[i]]:
        continue
    a_c[a[i]] -= 1
    t = (1<<a[i].bit_length()) - a[i]
    if t in a_c:#1つしか残っていないときに誤ってペアができていた
        if a_c[t]:
            a_c[t] -= 1
            #a_c[a[i]] -= 1#こっちも減らす
            ans += 1

print(ans)
            

Measured memory_bytes: 33296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    vl cnt(26);
    string s;
    while(cin>>s){
        ll n=s.size();
        rep(i,n){
            if('a'<=s[i]&&s[i]<='z')cnt[s[i]-'a']++;
            else if('A'<=s[i]&&s[i]<='Z')cnt[s[i]-'A']++;
        }
    }
    rep(i,26){
        cout<<(char)('a'+i)<<" : "<<cnt[i]<<endl;
    }
}

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



Measured memory_bytes: 3208
#include <stdio.h>

int main() {
	int a,ans = 0,re;
	int min = 0,re_min = 10;
	for (int i = 0; i < 5; i++) {
		scanf("%d",&a);
		re = a%10;
		if (re_min <= re) {
			for (;;) {
				int b = a%10;
				if (b == 0) break;
				a++;
			}
			ans += a;
		}
		if (re_min > re && re != 0) {
			re_min = re;
			for (;;) {
				int b = min%10;
				if (b == 0) break;
				min++;
			}
			ans += min;
			min = a;
		}
		if (re == 0) ans += a;
	}
	ans += min;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
N=int(input())
c=sorted([int(i) for i in input().split()])
mod=10**9+7
ans=0
for i in range(N):
    ans+=(c[i]*(((N-i+1)*pow(2,(N-2)%(mod-1),mod))%mod))%mod
    ans%=mod
print((ans*pow(2,N,mod))%mod)

Measured memory_bytes: 25508
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n;
string str;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int out=0,ans=0;
		vector<bool> base(3);
		while(out<3){
			cin>>str;
			if(str=="OUT") out++;
			else if(str=="HIT"){
				for(int j=2;j>=0;j--){
					if(base[j]){
						if(j+1>2) ans++;
						else base[j+1]=1;
						base[j]=0;
					}
				}
				base[0]=1;
			}
			else{
				for(int j=0;j<3;j++){
					if(base[j]) ans++;
					base[j]=0;
				}
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807

int main()
{
ll n , m ;
cin >> n >> m ;
vector<ll> a(n);
bool sa=1;
rep(i, n){
  cin >> a[i];
  if(i>0&&a[i-1]!=a[i])sa=0;
}
rep(i,n)a[i]/=2;
if(sa){
cout << ((m/a[0])+1)/2 << endl;
return 0;
}
bool aa=1;
auto b=a;
while(aa){
  aa=0;
  bool bb=0;
  rep(i,n){
    if(a[i]%2==0){
      bb=1;
      aa=1;
      a[i]/=2;
    }
    else{
      if(bb){
        cout << 0 << endl;
        return 0;
      }
    }
  }
}
ll r=b[0];
ll an=b[0];
rep(i,n-1){
  r=__gcd(an,b[i+1]);
  an*=b[i+1]/r;
  if(an >m){
cout << 0 << endl;
return 0;
  }
}
ans=((m/an)+1)/2;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n], y = new int[n], h = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
        }

        for (int xx = 0; xx <= 100; xx++) {
            loop:
            for (int yy = 0; yy <= 100; yy++) {
                int hh = 0;
                for (int j = 0; j < n; j++) {
                    if (h[j] == 0) continue;
                    hh = h[j] + Math.abs(x[j] - xx) + Math.abs(y[j] - yy);
                    break;
                }

                for (int i = 0; i < n; i++) {
                    if(h[i] != Math.max(0, hh - Math.abs(x[i] - xx) - Math.abs(y[i] - yy))) {
                        continue loop;
                    }
                }

                System.out.println(xx + " " + yy + " " +hh);
                return;
            }
        }
    }
}

Measured memory_bytes: 23764
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static final String WALL = "####################";
    
    public static void main(String[] args) {
        int[][][] tbl = new int[4][3][10];
        for(int n = scn.nextInt(); n > 0; n--) {
            int b = load(), f = load(), r = load();
            tbl[b][f][r] += scn.nextInt();
        }
        for(int i = 0; i < 4; i++) {
            if(i > 0) {
                System.out.println(WALL);
            }
            print(tbl[i]);
        }
    }
    
    private static int load() {
        return scn.nextInt() - 1;
    }
    
    private static void print(int[][] tbl) {
        for(int[] ary : tbl) {
            for(int elm : ary) {
                System.out.format("%2d", elm);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 30192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) {
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

struct inputData {
	int p;
	int x;
};

int main() {
	int n, i, j, m;
	cin >> n;
	vector<int> t(n+1);
	for (i = 1; i <= n; i++) {
		cin >> t[i];
	}
	cin >> m;
	vector<inputData> q(m+1);
	for (i = 1; i <= m; i++) {
		cin >> q[i].p >> q[i].x;
	}

	for (i = 1; i <= m; i++) {
		int ans = 0;
		for (j = 1; j <= n; j++) {
			if (q[i].p == j) {
				ans += q[i].x;
			} else {
				ans += t[j];
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

#define ll long long

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

    int n,k;
    ll sum=0;
    cin>>n>>k;

    int a[k];
    for(int i=0;i<k;i++)
    	{
    		cin>>a[i];
    		sum += a[i];
    	}

    if(sum >= n)
    	cout<<"Yes";
    else
    	cout<<"No";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,x,y,ans[10000];
int mmin(int x,int y){
	if(x>y) return y;
	else return x;
}
int aabs(int x){
	if(x<0) return -x;
	else return x;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>x>>y;
	for(register int i=1;i<=n;i++){
		for(register int j=i+1;j<=n;j++){
			ans[mmin(j-i,aabs(i-x)+aabs(j-y)+1)]++;
		}
	}
	for(register int i=1;i<=n-1;i++) cout<<ans[i]<<'\n';
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P, X = [], []
for i in range(M):
    _p, _x = map(int, input().split())
    P.append(_p)
    X.append(_x)

sm = sum(T)

for i in range(M):
    print(sm + X[i] - T[P[i]-1])


Measured memory_bytes: 3060
public class Main{
	static int dp[][][];
	static String s;
	public static int solve(int i,int j,int k) {
		if(dp[i][j][k]>=0)
			return dp[i][j][k];
		else {
			int ans;
			if(i>j)
				ans=0;
			else if(i==j)
				ans=1;
			else if(s.charAt(i)==s.charAt(j))
				ans=solve(i+1,j-1,k)+2;
			else {
				ans=solve(i+1,j,k);
				ans=Math.max(ans, solve(i,j-1,k));
				if(k>0)
				ans=Math.max(ans, solve(i+1,j-1,k-1)+2);
			}
			dp[i][j][k]=ans;
			return ans;
		}
	}
	public static void main(String[] args) {
		java.util.Scanner scan=new java.util.Scanner(System.in);
		s=scan.next();
		int t=scan.nextInt();
		dp=new int[s.length()][s.length()][t+1];
		for(int i=0;i<s.length();i++) {
			for(int j=0;j<s.length();j++) {
				for(int k=0;k<=t;k++)
					dp[i][j][k]=-1;
			}
		}
		System.out.println(solve(0,s.length()-1,t));
	}
}

Measured memory_bytes: 166004
#include <iostream>
#include <functional>
#include <vector>
using namespace std;
typedef long long ll;

// 1-indexed
// 親nodeはk/2, 子nodeは2kと2k+1
// update(k,x): k番目の要素をxに更新
// query(a,b): 区間[a:b)に対して二項演算した結果を返す
// operator[k]: k番目の要素を返す

template <typename T>
class SegmentTree {
    using F = function<T(T, T)>;
    int n;
    F f;
    T t;
    vector <T> dat;

public:
    SegmentTree() {};
    SegmentTree(F f, T t) : f(f), t(t) {}

    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        dat.assign(n << 1, t);
    }

    void build(const vector <T> &v) {
        auto n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; i++) dat[n + i] = v[i];
        for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }

    void set_val(int k, T x) {
        dat[k += n] = x;
        while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }

    T query(int a, int b) {
        T vl = t, vr = t;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) vl = f(vl, dat[l++]);
            if (r & 1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};


// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
void AOJ_DSL_2_A() {
    ll n, q, c, x, y;
    cin >> n >> q;

    // 1点更新、区間min
    auto f = [](int a, int b) { return min(a, b); };
    SegmentTree<int> seg(f, 2147483647);
    seg.build(vector<int>(n, 2147483647));
    while (q--) {
        cin >> c >> x >> y;
        if (c) cout << seg.query(x, y + 1) << "\n";
        else seg.set_val(x, y);
    }
}


// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
void AOJ_DSL_2_B() {
    ll n, q, c, x, y;
    cin >> n >> q;

    // 1点加算、区間sum
    auto f = [](ll a, ll b) { return a + b; };
    SegmentTree<ll> seg(f, 0LL);
    seg.build(vector<ll>(n, 0LL));
    while (q--) {
        cin >> c >> x >> y;
        if (c) cout << seg.query(x - 1, y) << "\n";
        else seg.set_val(x - 1, seg.query(x - 1, x) + y);
    }
}


// verified
//   https://atcoder.jp/contests/abc125/tasks/abc125_c
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }
void AtCoder_2019_4_27_C() {
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    // 更新なし、区間gcd
    SegmentTree<int> seg(gcd, 0);
    seg.build(a);
    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans = max(ans, gcd(seg.query(0, i), seg.query(i + 1, n)));
    }
    cout << ans << "\n";
}

int main() {
    // AOJ_DSL_2_A();
    // AOJ_DSL_2_B();
    AtCoder_2019_4_27_C();
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<int> a(N, 0);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	vector<int> range_count(1e5 + 2, 0);
	for (int i = 0; i < N; i++)
	{
		range_count[a[i]]++;
		range_count[a[i] + 1]++;
		range_count[a[i] + 2]++;
	}

	int result = 0;
	for (int i = 0; i < 1e5 + 2; i++)
	{
		result = max(result, range_count[i]);
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream> 
using namespace std; 
int main(){
   int N; int c1=0;int c2=0;
   int c3=0;int c4=0;
   cin>>N; 
   for (int i=0; i<N;++i){ 
      string s; 
      cin>>s;
      if(s == "AC")c1++; 
      if(s == "WA")c2++; 
      if(s == "TLE")c3++; 
      if(s == "RE")c4++; 
    } 
   cout<<"AC"<<" "<<"x"<<" "<<c1<<endl; 
   cout<<"WA"<<" "<<"x"<<" "<<c2<<endl;
   cout<<"TLE"<<" "<<"x"<<" "<<c3<<endl;
   cout<<"RE"<<" "<<"x"<<" "<<c4<<endl; 
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    int N,M;

    cin >> N >> M;

    vi H(N);

    REP(i,N)cin >> H[i];

    vector<vi> E(100000);

    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    bool flag = true;
    int ans = 0;

    REP(i,N){
        for(auto& e:E[i]){
            if(H[e] >= H[i])flag = false;
        }

        if(flag)ans++;
        flag = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8804
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int ans = 0;
  map<int, int> A{};
  REP(i, 3) { int t;
    cin >> t;
    if(A[t]==0){
      ans++;
    }
    A[t] = 1;
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
A = input().split()

ans = deque()
if len(A) % 2 == 0:
    for i in range(N):
        if i % 2 == 0:
            ans.append(A[i])
        else:
            ans.appendleft(A[i])
else:
    for i in range(N):
        if i % 2 == 0:
            ans.appendleft(A[i])
        else:
            ans.append(A[i])

print(' '.join(ans))


Measured memory_bytes: 26568
//#pragma comment(linker, "/stack:100000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(15)
#define fst ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=998244353;
int a[N],n,k,q;
int ans=1e9+9;

void cul(int mn){
    int l=1,r=1;
    int c[5000];
    int cnt=0;
//    cout <<mn<<endl;
    while(l<=n){

        while(l<=n&&a[l]<mn)    l++;
        r=l;
        while(r<=n&&a[r]>=mn)   r++;
        r--;
        if(r-l+1>=k){
//            cout <<l<<"~"<<r<<endl;
            int t[5000];int j=0;
            for(int i=l;i<=r;++i) t[++j]=a[i];
            sort(t+1,t+1+j);
            j=1;
            for(int i=cnt+1;j<=r-l+1-k+1;i++,j++){
                c[i]=t[j];
//                cout <<c[i]<<",";
            }
//            cout << endl;
            cnt+=r-l+1-k+1;
        }
        l=++r;
    }
//    cout <<"cnt="<<cnt<<endl;
    if(cnt>=q){
        sort(c+1,c+1+cnt);
//        cout << c[q]-mn << endl;
        if(c[1]==mn){
            ans=min(ans,c[q]-mn);
        }
    }
//     puts("********");

}

int main(void){
    fst;
    cin >>n >>k >>q;
    for(int i=1;i<=n;i++)   cin >>a[i];
    for(int i=1;i<=n;i++)
        cul(a[i]);
    cout << ans << endl;

    return 0;
}
void bef0re_submit(){
    debug("Make sure the algorithm is right!");
    debug("LONG LONG!!!");
    debug("n==0?1?2?3?");
    debug("Make sure output format is right/// Yes??YES  (%.20LF)???");
    debug("if all meet,run with special situation!!!");
    debug("I confirm that I have done all above");

    debug("If u know brute,consider fast,binary(log) or tree?");
}


Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int n;
    if(c%b==0)
        n=c/b;
        else
            n=c/b+1;
    if(a-(n-1)*d>0)
        cout << "Yes";
        else
            cout << "No";
            
            return 0;
}

Measured memory_bytes: 3624
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = [int(i) for i in input().split()]

if x not in p:
  print(x)
  exit()
l = x - 1
r = x + 1

while True:
  if l not in p:
    print(l)
    exit()
  if r not in p:
    print(r)
    exit()
  l -= 1
  r += 1

Measured memory_bytes: 9188
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

vp q;
vector<queue<ll>> a;
  


void solve(){
  ll n;
 cin >> n;
 a.resize(n);
  
 rep(i,0,n){
  rep(j,0,n-1){
   ll x;
    cin >> x;
    --x;
    a[i].push(x);
  }
 }
  
auto check=[&](ll i){
 if(a[i].size()==0) return; 
 ll x=a[i].front(); 
 if(a[x].size()==0) return;  
  ll y=a[x].front(); 
  if(y==i) {
  if(x>y) swap(x,y);
  q.eb(P(x,y));
  }
};
  
 rep(i,0,n) check(i);
 
 ll ans=0;
  while(q.size()){
    ans++;
   sort(all(q));
   q.erase(unique(q.begin(), q.end()), q.end());
   vp prev=q; 
   q.clear(); 
   for(auto p: prev){
    ll x=p.first;
    ll y=p.second;
    a[x].pop();
    a[y].pop();
   }
    for(auto p: prev){
    ll x=p.first;
    ll y=p.second;
    check(x);
    check(y); 
   }
    
  }
  
  rep(i,0,n) if(a[i].size()) ans=-1;
  
  cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 100009;
int n, a, b, c;
string s[N];

void nope() {
    cout << "No\n";
    exit(0);
}

void add_to(int fi, int se, vector<int>& abc, vector<char>& ans) {
    char c = 'A' + fi;
    ans.push_back(c);
    abc[fi]++;
    abc[se]--;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> a >> b >> c;
    for(int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    vector<char> ans;

    int i = 0;
    if(a == 0 && b == 0 && c > 1) {
        if(s[0] == "AB") nope();
        else if(s[0] == "BC") {
            ans.push_back('B');
            c--; b++;
        }
        else {
            ans.push_back('A');
            c--; a++;
        }
        i++;
    }

    if(a == 0 && c == 0 && b > 1) {
        if(s[0] == "AB") {
            ans.push_back('A');
            b--; a++;
        } else if(s[0] == "BC") {
            ans.push_back('C');
            b--; c++;
        } else nope();
        i++;
    }

    if(b == 0 && c == 0 && a > 1) {
        if(s[0] == "AB") {
            ans.push_back('B');
            a--; b++;
        } else if(s[0] == "BC") {
            nope();
        } else {
            ans.push_back('C');
            a--; c++;
        }
        i++;
    }

    if(a) a = 1;
    if(b) b = 1;
    if(c) c = 1;

    vector<int> abc = {a, b, c};
    
    while(i < n) {
        int fi = s[i][0] - 'A', se = s[i][1] - 'A';

        if(abc[fi] == 0 && abc[se] == 0) nope();

        if(abc[fi] == 0) {
            add_to(fi, se, abc, ans);
        } else if(abc[se] == 0) {
            add_to(se, fi, abc, ans);
        } else if(i == n-1) {
            add_to(fi, se, abc, ans);
        } else {
            int nf = s[i+1][0] - 'A', ns = s[i+1][1] - 'A';
            if(fi == nf || fi == ns) {
                add_to(fi, se, abc, ans);
            } else {
                add_to(se, fi, abc, ans);
            }
        }
        i++;
    }

    cout << "Yes\n";
    for(char c : ans) {
        cout << c << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 6932
# -*- coding: utf-8 -*-
n=int(input())
x=[]
y=[]
total=[]
count=[]
for _ in range(n):
    x1,y1=map(int,input().split())
    x.append(x1)
    y.append(y1)
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            temporary=(x[i]-x[j],y[i]-y[j])
            if temporary in total:
                count[total.index(temporary)]=count[total.index(temporary)]+1
            else:
                total.append(temporary)
                count.append(0)
if n==1:
    print(1)
else:
    print(n-max(count)-1)

Measured memory_bytes: 3316