akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
using ll = long long;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[N-1-i];
    }

    int ans = 0;
    vector<int> dp(N, INF);

    for (int i = 0; i < N; i++)
    {
        int pos = upper_bound(dp.begin(), dp.end(), A[i]) - dp.begin();
        dp[pos] = A[i];
        ans = max(ans, pos+1);
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {

	int antena[5];
	int k;

	for (int i = 0; i < 5; i++) {
		cin >> antena[i];
	}

	cin >> k;

	int dist = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = i + 1; j < 5; j++)  {
			int d = abs(antena[i] - antena[j]);
			if (d > dist) {
				dist = d;
			}
		}

	}

	if (dist <= k) {
		cout << "Yay!";
	} else {
		cout << ":(";
	}
	

	return 0;
}



Measured memory_bytes: 256
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
maze = [list(input()) for _ in range(h)]
que = deque()
d = [[-1] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            d[i][j] = 0
            que.append((i, j))
l = 0

while que:
    x, y = que.popleft()
    l = d[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx = x + dx
        ny = y + dy
        if not 0 <= nx < h or not 0 <= ny < w or d[nx][ny] != -1:
            continue
        d[nx][ny] = l + 1
        que.append((nx, ny))
print(l)

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

#define LL long long
#define x first
#define y second

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n; cin >> n;
    vector<pair<int,int>> v(n), u(n);
    int ans = 0, i = 0, cur, mn;
    for(auto &x : v) cin >> x.first >> x.second;

     for (int p : {1, -1}) {
            for (int q : {1, -1}) {
                mn = p * v[0].x + q * v[0].y;
                for (int i = 1; i < n; i++) {
                    cur = p * v[i].x + q * v[i].y;
                    ans = max(ans, cur - mn);
                    mn = min(mn, cur);
                }
            }
        }
    cout << ans;
}

Measured memory_bytes: 6328
#include <iostream>
using namespace std;
int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  A *= 100;
  B *= 100;
  int water;
  int suger, max_suger{0};
  int all, max_all{0};
  double dens, max_dens{-1.0};
  double limit_dens{E / (100.0 + E)};
  for (int a{0}; a <= F; a += A) {
    for (int b{0}; a + b <= F; b += B) {
      water = a + b;
      for (int c{0}; water + c <= F; c += C) {
        for (int d{0}; water + c + d <= F; d += D) {
          suger = c + d;
          all = water + suger;
          dens = static_cast<double>(suger) / all;
          if (dens > limit_dens) break;
          if (max_dens < dens) {
            max_all = all;
            max_suger = suger;
            max_dens = dens;
          }
        }
      }
    }
  }

  cout << max_all << " " << max_suger << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	ll ans = a[0];
	for(int i = 1; i < n; i++) {
		ans ^= a[i];
	}
	if (ans == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
def oneIsland(lis):
    island=0
    newlis=lis
    newlis.append(False)
    for n,i in enumerate(newlis):
        if n==len(newlis)-1:break
        if i and (not newlis[n+1]):
            island+=1
    return(island)
N=int(input())
h=[int(i) for i in input().split()]
toGrowBoolean=[]
for i in range(max(h)):#長さi+1以上ならTrue
    toGrowBoolean.append([k>i for k in h])
print(sum([oneIsland(row) for row in toGrowBoolean]))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
inline ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int N, M;
vector<int> X, Y, Z;
vector<int> adj[100001];
bool visited[100001];

void dfs(int idx)
{
    visited[idx] = true;
    
    for(int i = 0; i < adj[idx].size(); i++)
    {
        auto next = adj[idx][i];
        if(visited[next]) continue;
        dfs(next);
    }
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N >> M;
    int ret = 0;
    for(int i = 0; i < M; i++)
    {
        int x, y, z; cin >> x >> y >> z;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    
    for(int i = 1; i <= N; i++)
    {
        if(visited[i]) continue;
        dfs(i);
        ret += 1;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define f first
#define s second
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sdl(x) scanf("%lld",&x)
#define sdl2(x,y) scanf("%lld%lld",&x,&y)
#define sdl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pb(x) push_back(x)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define Forp(i,s,e) for (ll i = s; i <= e; i++)
#define Forn(i,s,e) for (ll i = s; i >= e; i--)


#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<p.f<<" "<<p.s;return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}


int main(){_
	ll n;
	cin >> n;
	ll a[n];
	Forp(i,0,n-1)
	cin >> a[i];
	ll temp = a[0];
	ll c = 1;
	// vll t;
	ll ans = 0;
	for(ll i = 1 ; i < n ; i++){
		if(a[i] == temp){
			c++;
		}
		else{
			ans += (c/2);
			c = 1;
			temp = a[i];
		}
	}
	ans += (c/2);
	cout << ans << endl;
    return 0;

}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int X,K,Q;
int T[111111],A[111111];
vint idx[111111];
int ans[111111];

signed main(){
    cin>>X>>K;
    vint R={0};
    rep(i,K){
        int r;cin>>r;R.pb(r);
    }
    R.pb(INT_MAX);
    cin>>Q;
    rep(i,Q){
        cin>>T[i]>>A[i];
        int tmp=upper_bound(all(R),T[i])-R.begin();
        tmp--;
        idx[tmp].pb(i);
    }
    UnionFindTree uf(Q);
    set<pint>s;
    for(int i=0;i<Q;i++)s.insert({A[i],i});
    int acc=0;


    for(int i=0;i+1<R.size();i++){
        for(auto &w:idx[i]){
            int tmp=A[uf.find(w)]+acc;
            if(i&1)tmp+=T[w]-R[i];
            else tmp-=T[w]-R[i];
            chmin(tmp,X);
            chmax(tmp,0);
            ans[w]=tmp;
        }
        int d=R[i+1]-R[i];
        if(i&1){
            acc+=d;
            if(s.rbegin()->fi+acc<=X)continue;
            int k=s.rbegin()->se;
            while(s.size()&&s.rbegin()->fi+acc>X){
                uf.unite(k,s.rbegin()->se);
                s.erase(*s.rbegin());
            }
            k=uf.find(k);
            A[k]=X-acc;
            s.insert({X-acc,k});
        }
        else{
            acc-=d;
            if(s.begin()->fi+acc>=0)continue;
            int k=s.begin()->se;
            while(s.size()&&s.begin()->fi+acc<0){
                uf.unite(k,s.begin()->se);
                s.erase(s.begin());
            }
            k=uf.find(k);
            A[k]=-acc;
            s.insert({-acc,k});
        }
    }

    rep(i,Q)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 16628
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        System.out.println(a==b?c:(a==c?b:a));
    }
 
    
}

Measured memory_bytes: 21588
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
int main(){
//	ios::sync_with_stdio(false);
//	ifstream cin("data.txt");
//	freopen("data.txt", "r", stdin);
	int n;
	cin >> n;
	int ans = 0;
	if(n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000){
		cout << 10 << endl;
		return 0;
	}
	while(n){
		ans += n % 10;
		n /= 10;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define int long long
#define endl '\n'

const int N = 100005;
int n, b[N], a[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	int prv = 0;
	int sum = 0;
	b[0] = LONG_MAX;
	for(int i = 1 ; i < n ; i ++){
		cin >> b[i];
	}
	sum += b[1];
	sum += b[n - 1];
	for(int i = 2 ; i <= n - 1 ; i ++){
		sum += min(b[i], b[i - 1]);
	}
	cout << sum;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

cnt = 0
money = 1000
b = 0
for i in range(n-1):
    if cnt == 0 and A[i] < A[i+1]:
        cnt += money//A[i]
        money %= A[i]
        b = A[i]
    else:
        money += cnt * A[i]
        cnt = 0
        if A[i] < A[i+1]:
            cnt += money//A[i]
            money %= A[i]
if cnt > 0:
    money += cnt * max(A[-1], b)
print(money)

Measured memory_bytes: 9124
#include<stdio.h>


#define MAX_INPUT 100

void inputArray(int array[], int *arraySize);
int selectionSort(int array[], int arraySize);
void outputArray(int array[], int arraySize);

int main(void)
{
  int size;
  int selectionArray[MAX_INPUT];
  int sortNum = 0;
  
  //  printf("selection sort.\n");
  inputArray(selectionArray, &size);
  sortNum = selectionSort(selectionArray, size);

  outputArray(selectionArray, size);
  printf("%d\n", sortNum);
  
  return 0;
}

void inputArray(int array[], int *arraySize)
{
  //  printf("input array size =\n");
  scanf("%d", arraySize);

  //  printf("input array = \n");
  for ( int i = 0; i < *arraySize; i++ ) {
    scanf("%d", &array[i]);
  }
}

// return value is number of change.
int selectionSort(int array[], int arraySize)
{
  int sortNum = 0;
  int temp;
  int minj;

  for ( int i=0; i < arraySize; i++ ) {
    minj = i;
    for ( int j=i; j < arraySize; j++ ) {
      if ( array[j]  < array[minj] ) {
	minj = j;
      }
    }
    if ( minj != i ) {
      temp = array[minj];
      array[minj] = array[i];
      array[i] = temp;
      sortNum++;
    }
  }
  return sortNum;
}

void outputArray(int array[], int arraySize)
{
  for (int i=0; i < arraySize-1; i++) {
    printf("%d ", array[i]);
  }
  printf("%d\n", array[arraySize-1]);
}

Measured memory_bytes: 1028
#include<stdio.h>

int n, A[2000];

int exhaustiveSearch(int i, int j){
  int more;
  /*?????????*/
  if(j == 0){
    return 1;
  }
  /*????????????*/
  else if(i >= n){
    return 0;
  }
  /*???????????????*/
  else{
    more  = exhaustiveSearch(i + 1, j) || exhaustiveSearch(i + 1, j - A[i]);
  }
  return more;
}

int main(){
  int i, q, Mi;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &Mi);
    if(exhaustiveSearch(0, Mi)){
      printf("yes\n");
    }
    else printf("no\n");
  }
  
  return 0;
}

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

char s_number[26] = {}, t_number[26] = {};
int i, j, k, count_s = 0, count_t = 0;

int chenge_t(char c);
int chenge_s(char c);


int main() {
  string s, t;
  cin >> s >> t;
  int chenged_s, chenged_t;
  for (j = 0; j < s.length(); j++) {
    chenged_s = chenge_s(s.at(j));
    chenged_t = chenge_t(t.at(j));
    if (chenged_s != chenged_t) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


int chenge_s(char c) {
  for (i = 0; i < count_s; i++) {
    if (c == s_number[i]) {
      return i;
    }
  }
  s_number[count_s] = c;
  count_s++;
  return (count_s - 1);
}

int chenge_t(char c) {
  for (i = 0; i < count_t; i++) {
    if (c == t_number[i]) {
      return i;
    }
  }
  t_number[count_t] = c;
  count_t++;
  return (count_t - 1);
}


Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	ull x, y;
	cin >> x >> y;
	if (x < y) {
		ull tmp = x;
		x = y;
		y = tmp;
	}
	if ((x - y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;


	return 0;
}

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

ll N, M, S[200000];
vector<ll> E[200000];
bool used[200000][2][2], visited[200000][2][2];

bool dfs(ll v, ll p1, ll p2) {
  if (visited[v][p1][p2]) return true;
  used[v][p1][p2] = true;
  visited[v][p1][p2] = true;
  for (ll u : E[v]) {
    if ((p2 == p1 && p1 != S[v] && S[v] == S[u]) || (p2 != p1 && p1 == S[v] && S[v] != S[u])) {
      if (dfs(u, S[v], p1)) return true;
    }
  }
  visited[v][p1][p2] = false;
  return false;
}

int main(void) {
  string s;
  cin >> N >> M >> s;
  REP(i, 0, N) S[i] = (s[i] == 'A' ? 0 : 1);
  REP(i, 0, M) {
    ll A, B;
    cin >> A >> B, A--, B--;
    E[A].push_back(B);
    E[B].push_back(A);
  }

  REP(i, 0, N) REP(j, 0, 2) REP(k, 0, 2) {
    used[i][j][k] = false;
    visited[i][j][k] = false;
  }

  REP(p1, 0, 2) REP(p2, 0, 2) {
    REP(v, 0, N) if (!used[v][p1][p2]) {
      if ((p2 == p1 && p1 != S[v]) || (p2 != p1 && p1 == S[v])) {
        if (dfs(v, p1, p2)) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 23556
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fi first
#define se second
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m, T;

char s[100];

int main(){
	int i, j, k;
	string ans;
	scanf(" %s", s);
	if(s[0] == 'S') ans = "Cloudy";
	else if(s[0] == 'C') ans = "Rainy";
	else ans = "Sunny";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
        int a = scan.nextInt();		//辺a
        int b = scan.nextInt();		//辺b
	    int c = scan.nextInt();		//角度
	    double angle = c * Math.PI /180;//角度
	    
	    //面積
	    double menseki = a * b  * Math.sin(angle) / 2;
	    
	    //dは残りの辺。Lは周の長さ
	    double L = a + b + Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(c)));
	    
	    //高さ
	    double h = menseki * 2 / a;
	   
	    System.out.println(menseki);
	    System.out.println(L);
	    System.out.println(h);
	}
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(int i=1; i<s.size(); ++i) {
        if(s[i-1] != s[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
h = int(input())
t = input().split()
for i in range(h):
    ans = f"node {i+1}: key = {t[i]}, "
    p = (i+1)//2-1
    if p >= 0:
        ans += f"parent key = {t[min([p,h])]}, "
    l, r = (i+1)*2-1, (i+1)*2
    if l < h:
        ans += f"left key = {t[l]}, "
        if r < h:
            ans += f"right key = {t[r]}, "
    print(ans)



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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N;
int x, y;

int main() {
	cin >> N;
	int la = 0;
	bool ok = 1;
	rep(i, N) {
		int t, p, q;
		cin >> t >> p >> q;
		int ns = abs(p - x) + abs(q - y);
		int tt = t - la;
		if (ns <= tt && (tt - ns) % 2 == 0) {
			x = p;
			y = q;
			la = t;
		} else {
			ok = 0;
		}
	}
	puts(ok ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    int l,r,d;
    cin >> l >> r >> d;
    int cnt=0;
    for(int i=l; i<=r; ++i) {
        if (i%d==0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>

using namespace std;



int main() {
	queue<pair<int, int>> q;
	int n,row,size,tmp;
	pair<int, int> ptmp;
	cin >> n;
	int** mat = new int* [n];
	int *distance = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> row >> size;
		mat[row - 1] = new int[n];
		for (int j = 0;j < n;j++) {
			mat[row - 1][j] = 0;
		}
		for (int j = 0;j < size;j++) {
			cin >> tmp;
			mat[row - 1][tmp - 1] = 1;
		}
		distance[i] = -1;
	}
	distance[0] = 0;
	q.push(make_pair(0, 0));
	while (!q.empty()) {
		ptmp = q.front();
		q.pop();
		for (int i = 0;i < n;i++) {
			if (mat[ptmp.first][i] && distance[i] == -1) {
				distance[i] = ptmp.second + 1;
				q.push(make_pair(i, ptmp.second + 1));
			}
		}
	}
	for (int i = 0;i < n;i++) {
		cout << i + 1 << " " << distance[i] << endl;
	}


}



Measured memory_bytes: 3108
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n, A[50];
	scanf("%d", &n);
	int minus_ = 0, minus_index = 0, plus_ = 0, plus_index = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", A + i);
		if (plus_ < A[i]) {
			plus_ = A[i];
			plus_index = i;
		}
		if (minus_ < -A[i]) {
			minus_ = -A[i];
			minus_index = i;
		}
	}
	
	if (minus_ <= plus_) {
		printf("%d\n", n * 2 - 1);
		for (int i = 0; i < n; i++)
			printf("%d %d\n", plus_index + 1, i + 1);
		for (int i = 1; i < n; i++)
			printf("%d %d\n", i, i + 1);
	} else {
		printf("%d\n", n * 2 - 1);
		for (int i = 0; i < n; i++)
			printf("%d %d\n", minus_index + 1, i + 1);
		for (int i = n - 2; 0 <= i; i--)
			printf("%d %d\n", i + 2, i + 1);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void)
{
    int n, k, ans = 1;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        ans = min(ans + k, ans * 2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main(){
    
    int k;
    int x;
    cin >> k >> x;
    if(k==1) cout << x;
    else if(k==2) cout << x-1 << " " << x << " " << x+1 ;
    else{
    for(int i=0;i<2*k-1;i++){
        cout << x-(k-1)+i << " " ;
        
    }
    }
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
xyh=[list(map(int, input().split())) for _ in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)
# 中心座標を全探索（たかだか101*101*N通り）
for i in range(101):
    for j in range(101):
        # １つ目の要素を用いてHを設定
        H=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for x,y,h in xyh:
            if h==max(H-abs(x-i)-abs(y-j),0):
                continue
            else:
                break
        else:
            print(i,j,H)

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
int main()
{
	char a[11];
	char b[11];
	char c[11];
	
	scanf("%s %s %s", a, b, c);
	int lena = strlen(a);
	int lenb = strlen(b);
	int lenc = strlen(c);
	
	if(a[lena-1] == b[0] && b[lenb-1] == c[0])
	{
		printf("YES\n");
	} else
	{
		printf("NO\n");
	}
	
	
	
	
	return 0;
}

Measured memory_bytes: 1640
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF (1 << 30)
using namespace std;
using ll = long long;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    double N, K;
    cin >> N >> K;

    double countable = ceil(N / 2.0);

    if (countable >= K) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  ll n,m,k; cin >> n >> m >> k;
  vector<ll> a(n),b(m);
  REP(i,n) cin >> a[i];
  REP(i,m) cin >> b[i];

  // 累積和
  vector<ll> sa(n+1), sb(m+1);
  REP(i,n) sa[i+1] = sa[i] + a[i];
  REP(i,m) sb[i+1] = sb[i] + b[i];

  int ans=0;
  // bを固定して考える
  REP(i, m+1) {
    if (sb[i] > k) break;
    auto it = std::upper_bound(sa.begin(), sa.end(), k-sb[i]);
    int p = max(0, (int)(it-sa.begin()-1));
    ans = max(ans, p+i);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 9512
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 200050;
const long long MOD = 1000000007;

int N;
int C[MAX_N];
long long tmpc[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> C[i];
    }

    for (int i = 0; i < MAX_N; i++) {
        tmpc[i] = 0;
    }

    long long ret = 1;
    tmpc[C[1]] = 1;

    for (int i = 2; i <= N; i++) {
        if (tmpc[C[i]] == 0) {
            tmpc[C[i]] = ret;
        } else {
            if (C[i] != C[i-1]) {
                ret = (ret + tmpc[C[i]]) % MOD;
                tmpc[C[i]] = ret;
            }
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
ll solve(ll i,ll j, ll arr[], ll dp[3000][3000], ll n){

    if(i>j){
        return 0;
    }
    else if(i==j){
        dp[i][j]=arr[i];
        return arr[i];
    }
    else if(dp[i][j]!=0){
        return dp[i][j];
    }
    else{
        ll ret = arr[i] - solve(i + 1, j,arr,dp,n );
        ret = max(ret, arr[j] - solve(i, j-1,arr,dp,n));
        dp[i][j]=ret;
        return ret;
    }
    return 0;
}
int main(int argc, char const *argv[])
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) {
        ll n;
        cin>>n;
        ll arr[n],dp[3000][3000]={0};
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }

        cout<<solve(0,n-1,arr,dp,n)<<endl;
    }
    return 0;
}


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

// 入力
int H, W;
vector<vector<int> > field;

// 探索
void dfs(int h, int w) {
    field[h][w] = 0;

    // 八方向を探索
    for (int dh = -1; dh <= 1; ++dh) {
        for (int dw = -1; dw <= 1; ++dw) {
            int nh = h + dh, nw = w + dw;
            
            // 場外アウトしたり、0 だったりはスルー
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (field[nh][nw] == 0) continue;

            // 再帰的に探索
            dfs(nh, nw);
        }
    }
}

int main() {
    // 入力受け取り
    while (cin >> W >> H) {
        if (H == 0 || W == 0) break;
        field.assign(H, vector<int>(W, 0));
        for (int h = 0; h < H; ++h) for (int w = 0; w < W; ++w) cin >> field[h][w];

        // 探索開始
        int count = 0;
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                if (field[h][w] == 0) continue; // 残島じゃなかったらスルー
                dfs(h, w);
                ++count;
            }
        }
        cout << count << endl;
    }
}



Measured memory_bytes: 3244
use std::io;

fn main() {
    let st = parse_values::<String>(2);
    let ab = parse_values::<usize>(2);
    let mut a = ab[0];
    let mut b = ab[1];
    let u = parse_line::<String>();
    if u == st[0] {
        a -= 1;
    } else {
        b -= 1;
    }
    println!("{} {}", a, b);
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_values<T: std::str::FromStr>(n: usize) -> Vec<T> {
    let line = parse_line::<String>();
    let mut split = line.split_whitespace();
    let mut values = Vec::with_capacity(n);
    for _ in 0..n {
        let v = split.next().unwrap().parse::<T>().ok().unwrap();
        values.push(v);
    }
    values
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
    int a,b,d,r;
    double f;

    scanf("%d%d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/b;
    printf("%d %d %f\n",d,r,f);
    return 0;
    }


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 
const int N = 105;
bool z[N];
int main(){
  fio; cout<<fixed<<setprecision(25);	
  int n ; cin >> n;
  bool ok = 0;
  for(int i =1 ;i <= n; ++i){
    int x , y;cin >> x >> y;
    z[i] = (x == y);
    int cnt = 0;
    for(int j = i;j >= 1 && j >= i-2; --j){
      cnt += z[j];
    }
    if(cnt >= 3) ok = 1;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
   
}


Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (long long i = 0; i < (n); i++)
using namespace std;

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

    long long N;
    scanf("%lld",&N);

    long long L;
    scanf("%lld",&L);

    std::vector<std::string> S(N);
    REP(i, N)
        std::cin >> S[i];

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

    REP(i, N)
        cout << S[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
X = int(input())

import math
def using_sqrt(x):
    n = 0
    for k in range(x, 1000000):
        factor = 0

        # 2以外の偶数は素数ではないので無視する
        if k % 2 == 0 and k != 2:
            continue

        # 繰り返しの上限を対象の平方根にする
        for divisor in range(2, math.floor(math.sqrt(k)) + 1):
            if k % divisor == 0:
                factor += 1

        if factor == 0:
            #n += 1
            ans = k
            break

    return ans

ans = using_sqrt(X)
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y; cin >> x >> y;
  ll tmp = x;
  int ans = 0;
  while(tmp <= y) {
    ans++;
    tmp *= 2;
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10000)
n=int(input())
a=[]
b=[[]for _ in [0]*n]

def f(i,x):
    print('.'*x+a[i])
    for j in b[i]:
        f(j,x+1)

for i in range(n):
    c=int(input())
    a+=[input()]
    if c!=0:b[c-1]+=[i]
f(0,0)

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

int a[100000];
int N;
int h[100000];

int main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&h[i]);
  }

  a[0]=0;
  a[1]=abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    if(a[i-2]+abs(h[i]-h[i-2]) < a[i-1]+abs(h[i]-h[i-1])){
      a[i] = a[i-2]+abs(h[i]-h[i-2]);
    }else{
      a[i] = a[i-1]+abs(h[i]-h[i-1]);
    }
  }
  printf("%d\n",a[N-1]);
}


Measured memory_bytes: 896
# ABC122C - GeT AC
import sys
input = sys.stdin.readline


def main():
    n, q = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    arr = tuple(tuple(map(int, input().split())) for _ in range(q))
    cnt = [0] * (n + 1)
    for i in range(n):
        if s[i : i + 2] == "AC":
            cnt[i + 1] = cnt[i] + 1
        else:
            cnt[i + 1] = cnt[i]
    for i, j in arr:
        print(cnt[j - 1] - cnt[i - 1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 19816
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v = read_vec::<u64>();
    let (n, a, b) = (v[0], v[1], v[2]);
    let x = read_vec::<u64>();
    println!(
        "{}",
        (1..n as usize).fold(0, |sum, i| sum + std::cmp::min(b, a * (x[i] - x[i - 1])))
    );
}


Measured memory_bytes: 8444
#include <iostream>

using namespace std;

int main()
{
    char S[4], T[4];
    cin >> S;
    cin >> T;
    int count = 0;
    for(int i=0;i<3;i++){
        count += S[i] == T[i] ? 1 : 0; 
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding:utf-8 -*-

N,K = map(int,input().split(" "))
A = list(map(int, input().split(" ")))

F=0
for i in A:
    if i==1:
        X=F 
        Y=N-(F+1)
        break;
    F=F+1

P=(X+Y)//(K-1)
if (X+Y)%(K-1)>0:
    print(P+1)
else:
    print(P)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

unsigned long long modpow(unsigned long long n, unsigned long long k, unsigned long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

ld n;
int cnt1= 0;int cnt2 = 0;int cnt3 = 0;
vector<vector<vector<ld>>>dp(305,vector<vector<ld>>(305,vector<ld>(305,-1)));
vector<ld>a(305);

ld dfs(ld a,ld b,ld c){
     if(a==0&&b==0&&c==0) return 0;
     if(dp[a][b][c]>=0) return dp[a][b][c];
     ld d = a+b+c;
     ld ans = n/d;
     if(a) ans += dfs(a-1,b,c)*a/d;
     if(b) ans += dfs(a+1,b-1,c)*b/d;
     if(c) ans += dfs(a,b+1,c-1)*c/d;
     dp[a][b][c] = ans;
     return dp[a][b][c];
}
void solve(){
     cin >> n;
     for(int i = 0;i<n;i++) cin >> a[i];
     for(int i = 0;i<n;i++){
        if(a[i]==1) cnt1++;
        else if(a[i]==2) cnt2++;
        else cnt3++;
     }
     cout << fixed << setprecision(10)<<dfs(cnt1,cnt2,cnt3);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 451544
N = int(input())
lis = []
for i in range(N):
    lis.append(list(map(int,input().split())))
lis.sort(key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 53720
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }
    sort(a.begin(), a.end());

    long sum=0;
    for(i=0; i<n-1; i++) {
        sum += a[i];
    }
    if(sum > a[n-1]) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;


int main()
{
  int N, C;

  cin >> N >> C;
  vector< pair< int, int > > t[100001];

  for(int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --c;
    t[a].emplace_back(b, c);
  }

  int ret = 0, need = 0, lock[30] = {};

  for(int i = 1; i < 100001; i++) {
    for(auto &p : t[i]) {
      if(lock[p.second] == 0) ++need;
      lock[p.second] = max(lock[p.second], p.first);
    }
    ret = max(ret, need);
    for(int j = 0; j < C; j++) {
      if(lock[j] == i) lock[j] = 0, --need;
    }
  }

  cout << ret << endl;
}

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll N, M;
  cin >> N >> M;
  ll p[M];
  string S[M];
  for(int i=0;i<M;i++){
    cin >> p[i] >> S[i];
  }
  
  ll count[N];
  bool AC[N];
  for(int i=0;i<N;i++){
    count[i] = 0;
    AC[i] = false;
  }
  for(int i=0;i<M;i++){
    if(!AC[p[i]-1]){
      if(S[i] == "WA"){
        count[p[i]-1]++;
      }else{
        AC[p[i]-1] = true;
      }
    }
  }
  
  ll ans1 = 0;
  ll ans2 = 0;
  for(int i=0;i<N;i++){
    if(AC[i]){
      ans1++;
      ans2 += count[i];
    }
  }
  cout << ans1 << ' ' << ans2 << endl;
}

Measured memory_bytes: 7424
// Problem: H - Grid 1
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_h
// Parsed on: 2020-09-07 11:16:54
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define md ((int)1e9 + 7)
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> dp(h, vector<int>(w));
    vector<string> ar(h);
    for (auto &e : ar) cin >> e;

    dp[0][0] = 1;
    for (int a = 0; a < h; a++)
        for (int b = 0; b < w; b++) {
            if (a == b && a == 0) continue;
            if (ar[a][b] == '#')
                dp[a][b] = 0;
            else
                dp[a][b] = ((a ? dp[a - 1][b] : 0)%md + (b ? dp[a][b - 1] : 0)%md)%md;
        }

    cout << dp.back().back();

    return 0;
}


Measured memory_bytes: 8640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int main(int argc, const char * argv[]) {
  	double W,H,x,y;
  int multi;
  cin >> W >> H >> x >> y;
  if(x*2==W && y*2==H) multi = 1;
  else multi = 0;
  cout << W*H/2 << ' ' << multi;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
           
           Scanner reader = new Scanner(System.in);
           
           int a = reader.nextInt();
           int b = reader.nextInt();
           int c = reader.nextInt();
           reader.close();
           
           if(a<b&&b<c){
               System.out.println("Yes");
           }
           else{
               System.out.println("No");
           }
    }
}

Measured memory_bytes: 26316
// Making chalk mark on generator: $1
// Knowing where to make mark: $9,999
#include <bits/stdc++.h>
#define when(...) fprintf(stderr,__VA_ARGS__)
typedef long long ll;
ll read() {
	static char c;
	static ll x;
	int flag = 1;
	while (c = getchar(), !isdigit(c))
		if (c == '-') flag = 0;
	x = c - '0';
	while (c = getchar(), isdigit(c))
		x = x * 10 + c - '0';
	return flag ? x : -x;
}

struct node {
	int w, s, v;
	bool operator<(const node &rhs) const {return w + s < rhs.w + rhs.s;}
} ns[1111];
int n;
bool vis[1010][20010];
ll ans[1010][20010];
ll f(ll x, ll rem) {
	if (rem < 0) return -1e18;
	if (x == 0) return 0;
	ll &tmp = ans[x][rem];
	if (vis[x][rem]) return tmp;
	vis[x][rem] = 1;

	if (rem == 0) return tmp = 0;
	return tmp = std::max(f(x - 1, rem),
	                      f(x - 1, std::min(rem - ns[x].w, (ll)ns[x].s)) + ns[x].v);
}

signed main() {
	n = read();
	for (int i = 1; i <= n; ++i) {
		ns[i].w = read();
		ns[i].s = read();
		ns[i].v = read();
	}
	std::sort(ns + 1, ns + 1 + n);
	printf("%lld\n", f(n, 20000));
}


Measured memory_bytes: 176256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define INF 100000000
int main(){
    ll N,K;
    string S;
    cin>>N>>K>>S;
    
    if(S[K-1]=='A')S[K-1]='a';
    if(S[K-1]=='B')S[K-1]='b';
    if(S[K-1]=='C')S[K-1]='c';
    cout<<S;
    
}

Measured memory_bytes: 256
N,K=map(int,input().split())
h=[]
for i in range(N):
    h.append(int(input()))
    

h.sort()
QQ=1000000000
for i in range(N-K+1):
    QQ=min(QQ,abs(h[i]-h[i+K-1]))
print(QQ)

Measured memory_bytes: 7384
#include<iostream>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int N;
    cin >> N;

	int max_donut;
	max_donut = N / 7;

	int remain;
	int flag = 0;
	for (int i=0;i <= max_donut; i++){
		remain = N - i*7;
		if (remain % 4 == 0){
			flag = 1;
			break;
		}
	}

	if(flag == 0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	
	int d[7][7] = 
	{{ -1,300,500,600,700,1350,1650}
	,{  6, -1,350,450,600,1150,1500}
	,{ 13,  7,  0,250,400,1000,1350}
	,{ 18, 12,  5,  0,250, 850,1300}
	,{ 23, 17, 10,  5, -1, 600,1150}
	,{ 43, 37, 30, 25, 20,  -1, 500}
	,{ 58, 52, 45, 40, 35,  15,  -1}};
	
	

	int s,t,hs,ms,ht,mt;
	while(cin>>s,s){
		cin>>hs>>ms>>t>>ht>>mt;
		ms += hs*60;
		mt += ht*60;
		s--,t--;
		bool flg = false;
		if((17*60+30<=ms&&ms<=19*60+30)
		 ||(17*60+30<=mt&&mt<=19*60+30))flg = true;
		int price = d[s][t];
		if(d[t][s] <= 40 && flg){
			price/=2;
			if(price%50!=0){
				price += 50 - (price%50);
			}
		}
		cout<<price<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int a[5];
int n,s; 
int main(){
	cin>>n;
	while(n){
		a[++s]=n%10;
		n/=10;
	}
    if(a[2]==a[3]){
    	if(a[1]==a[2]||a[3]==a[4]){
		   printf("Yes");
		   return 0;
	    }
	}
	printf("No");
    return 0;
}


Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
 
int main(){
    string s,t;
    cin >> s >> t;
    bool flag = false;
    int st = -1;
    string ans(s.size(), 'x'),temp(s.size(), 'x');
    //tが含まれているか
    for(int i = 0; i < s.size() - t.size() + 1; i++){
        if(s[i] != t[0] and s[i] != '?') continue;        
        flag = true;
        for(int j = 0; j < t.size(); j++){
            if(s[i + j] != t[j] and s[i + j] != '?'){
                flag = false;
            }
        }
        if(flag){
            st = i;
            for(int k = 0; k < s.size(); k++){
                if(s[k] == '?') temp[k] = 'a';
                if(s[k] != '?') temp[k] = s[k];
            }
            for(int l = 0; l < t.size(); l++){
                temp[l + st] = t[l];
            }
            if(ans > temp) ans = temp;
        }
    }
 
    if(st == -1){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int main()
{
    int n;
    set<int> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        s.insert(d);
    }

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll u[N],m[N],b[N];
vector<vector<int> > adj;
bool visited[N][10]={};
int nodesNum;
int s,t;


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

int x1,y1,x2,y2,x3,y3,x4,y4;
cin>>x1>>y1>>x2>>y2;
int x=x2-x1;
int y=y2-y1;
x3=x2-y;
y3=y2+x;
x4=x1-y;
y4=y1+x;
cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4;

    return 0;
}


Measured memory_bytes: 3636
S = input()
T = input()
N = len(T)
y = 0
for i in range(0,len(S)-N+1):
  
  s = S[i:i+N]
  x = 0
  for k in range(0,N):
    if T[k] == s[k]:
      x = x + 1
  if x >= y:
    y = x
print(N-y)      

Measured memory_bytes: 9120
n = gets.to_i
s = gets.strip.split(' ').map(&:to_i)
r = 'Yes'
top = s[0]
(0..(n-2)).each do |i|
  top = s[i] if s[i] > top
  if s[i] - 1 > s[i+1] || top - 1 > s[i+1]
    r = 'No'
    break
  end
end
puts r

Measured memory_bytes: 9604