akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
using namespace std;


int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin>>s[i][j];
		}
	}
	bool flag = true;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i == 0&&j==0) {
				if (s[i][j] == '#' && s[i + 1][j] == '.' && s[i][j + 1] == '.') {
					flag = false;
					goto label;
				}
			}
			else if(i==h-1&&j==w-1){
				if (s[i][j] == '#' && s[i ][j-1] == '.' && s[i-1][j] == '.') {
					flag = false;
					goto label;
				}
			}
			else if (i == 0&&j==w-1) {
				if (s[i][j] == '#' && s[i + 1][j] == '.' && s[i][j - 1] == '.') {
					flag = false;
					goto label;
				}
			}
			else if (i == h - 1 && j == 0) {
				if (s[i][j] == '#' && s[i - 1][j] == '.' && s[i][j + 1] == '.') {
					flag = false;
					goto label;
				}
			}
			else if (i == 0) {
				if (s[i][j] == '#' && s[i + 1][j] == '.' && s[i][j + 1] == '.'&&s[i][j-1]=='.') {
					flag = false;
					goto label;
				}
			}
			else if (i == h-1) {
				if (s[i][j] == '#' && s[i - 1][j] == '.' && s[i][j + 1] == '.' && s[i][j - 1] == '.') {
					flag = false;
					goto label;
				}
			}
			else if (j == 0) {
				if (s[i][j] == '#' && s[i ][j+1] == '.' && s[i+1][j] == '.' && s[i-1][j] == '.') {
					flag = false;
					goto label;
				}
			}
			else if (j == w-1) {
				if (s[i][j] == '#' && s[i][j - 1] == '.' && s[i + 1][j] == '.' && s[i - 1][j] == '.') {
					flag = false;
					goto label;
				}
			}
			else {
				if (s[i][j] == '#' && s[i][j - 1] == '.' && s[i + 1][j] == '.' && s[i - 1][j] == '.'&&s[i][j+1]=='.') {
					flag = false;
					goto label;
				}
			}
		}
	}
label:
	if (flag) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

int N, dp[MAXN + 3][3], point[MAXN + 3][3];

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> point[i][0] >> point[i][1] >> point[i][2];

    dp[1][0] = point[1][0];
    dp[1][1] = point[1][1];
    dp[1][2] = point[1][2];
    for (int i = 2; i <= N; i++) {
        for (int current = 0; current < 3; current++) {
            dp[i][current] = 0;
            for (int last = 0; last < 3; last++) {
                if (last != current)
                    dp[i][current] = max(dp[i][current], dp[i - 1][last] + point[i][current]);
            }
        }
    }

    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(){
  int n,i,x[100000];
  long long int a,b,ans=0;
  scanf("%d%lld%lld",&n,&a,&b);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<n-1;i++){
    if((x[i+1]-x[i])*a>b)ans+=b;
    else ans+=(x[i+1]-x[i])*a;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,h,a=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>h;
    if(h>=k)
      a++;
  }
  cout<<a<<endl;
  return(0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int N; ll s[3002], dp[3002][3002];
int main(){
    scanf("%d", &N);
    for(int i=1; i<=N; i++){
        scanf("%lld", &s[i]); dp[i][i] = s[i]; s[i] += s[i-1]; 
    }
    for(int len=1; len < N; len++){
        for(int i=1; i+len<=N; i++){
            int j = i + len;
            dp[i][j] = s[j] - s[i-1] - min(dp[i+1][j], dp[i][j-1]);
        }
    }
    printf("%lld\n", 2*dp[1][N] - s[N]);
}

Measured memory_bytes: 70016
# https://twitter.com/tempura_cpp/status/1259483252919635969

n, k = gets.to_s.split.map{|e|e.to_i}
a = [0] + gets.to_s.split.map{|e|e.to_i}

c = 1

while k > 0
  
  c = a[c] if k & 1 > 0
  
  na = Array.new(n+1)
  
  (n+1).times{ |i| na[i] = a[a[i]] }
  
  a = na
  k >>= 1
end

puts c


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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

const LL LL_INF = 1e18;
mt19937 rng(static_cast<uint32_t>(chrono::steady_clock::now().time_since_epoch().count()));

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

  #ifdef EntityIT
  freopen("input.txt", "r", stdin);
  #endif // EntityIT

  int n, m; cin >> n >> m;

  LL ans = LL_INF;
  for (int i = 1; i < m; ++i) {
    LL a = static_cast<LL>(n >> 1) * (m - i),
       b = static_cast<LL>(n - (n >> 1)) * (m - i),
       c = static_cast<LL>(n) * i;
    asMn(ans, max({a, b, c}) - min({a, b, c}));

    if (m - i >= 2) {
      int rem = m - i;
      a = static_cast<LL>(rem >> 1) * n;
      b = static_cast<LL>(rem - (rem >> 1)) * n;
      asMn(ans, max({a, b, c}) - min({a, b, c}));
    }
  }
  swap(n, m);
  for (int i = 1; i < m; ++i) {
    LL a = static_cast<LL>(n >> 1) * (m - i),
       b = static_cast<LL>(n - (n >> 1)) * (m - i),
       c = static_cast<LL>(n) * i;
    asMn(ans, max({a, b, c}) - min({a, b, c}));

    if (m - i >= 2) {
      int rem = m - i;
      a = static_cast<LL>(rem >> 1) * n;
      b = static_cast<LL>(rem - (rem >> 1)) * n;
      asMn(ans, max({a, b, c}) - min({a, b, c}));
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3620
string = input()
n  = len(string)
a  = '10'*(n//2+1)
b  = '01'*(n//2+1)
a = a[:n]
b = b[:n]

x = int(a,2) ^ int(string,2)
y = int(b,2) ^ int(string,2)
l ="{0:b}".format(x)
k ="{0:b}".format(y)

print(min(l.count('1'),k.count('1')))

Measured memory_bytes: 3572
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 998244353

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def fact_all(n,M=mod):
    f = [1]*(n+1)
    ans = 1
    for i in range(1,n+1):
        ans = (ans*i)%M
        f[i] = ans
    return f

## inv(0!)~inv(n!)をmodしつつ求める
def fact_inv_all(fact_all,M=mod):
    N = len(fact_all)
    finv = [0]*N
    finv[-1] = pow(fact_all[-1],M-2,M)
    for i in range(N-1)[::-1]:
        finv[i] = finv[i+1]*(i+1)%M
    return finv

## nCkをmodしつつ返す
def nCk(n,k,fact_list,inv_list,M=mod):
    return (((fact_list[n]*inv_list[k])%M)*inv_list[n-k])%M

N,M,K = LI()

Ma = [0]*(N)
Ma[0] = 1
for i in range(1,len(Ma)):
    Ma[i] = Ma[i-1]*(M-1)
    Ma[i] %= mod

fl = fact_all(N)
il = fact_inv_all(fl)

ans = 0
for j in range(K+1):
    ans += nCk(N-1,j,fl,il)*Ma[N-1-j]*M
    ans %= mod

print(ans)

Measured memory_bytes: 76116
#include <stdio.h>
int H[500001],heap_size;

int parent(int n){
  return ((double)1/2)*n;
}

int left(int n){
  return 2*n;
}

int right(int n){
  return 2*n+1;
}

void maxHeapify(int n){
  int l = left(n),r = right(n),largest,temp;
  if (l <= heap_size && H[l] > H[n]){
    largest = l;
  } else {
    largest = n;
  }
  if (r <= heap_size && H[r] > H[largest]){
    largest = r;
  }
  if (largest != n){
    temp = H[n];
    H[n] = H[largest];
    H[largest] = temp;
    maxHeapify(largest);
  }
}

int main() {
  int i;

  scanf ("%d",&heap_size);
  for (i=1;i<=heap_size;i++){
    scanf ("%d",&H[i]);
  }
  /*
  for (i=1;i<=heap_size;i++){
    printf ("node %d: key = %d, ",i,H[i]);
    if (parent(i)>=1){
      printf ("parent key = %d, ",H[parent(i)]);
    }
    if (left(i)<=heap_size){
      printf ("left key = %d, ",H[left(i)]);
    }
    if (right(i)<=heap_size){
      printf ("right key = %d, ",H[right(i)]);
    }
    printf("\n");
    }
  */

  for (i=heap_size/2; i>=1;i--){
    maxHeapify(i);
  }

  for (i=1;i<=heap_size;i++){
    //if (i!=1){
      printf(" ");
    //}
    printf("%d", H[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2552
def solve():
  q,h,s,d= (int(i) for i in input().split())
  n = int(input())
  Ltanka = [4*q,2*h,s]
  L2tanka = [8*q,4*h,2*s,d]
  ans = 0
  while n != 0:
   if n == 1:
    ans += min(Ltanka)
    n-= 1
   else:
    times =  n//2
    ans += times*min(L2tanka)
    n -= times *2
  return ans
  
if __name__ == '__main__':
  print(solve())

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

int MAX=200000;

int main(void){
    int n,R[MAX];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>R[i];
    }
    int maxv=-2000000000;
    int minv=R[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout<<maxv<<"\n";
}


Measured memory_bytes: 3868
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int factorial(int a)            //20!までオーバーフローなし
{
    if (a == 1)
    {
        return 1;
    }else
    {
        return (a * factorial(a - 1));
    }
    
}

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    double inx, iny;
    vector<double> x, y;
    vector<int> city;
    for (int i = 0; i < N; i++)
    {
        cin >> inx >> iny;
        x.emplace_back(inx);
        y.emplace_back(iny);
        city.emplace_back(i + 1);
    }
    
    double sum = 0;
    do
    {
        for (int i = 1; i <= N - 1; i++)
        {
            sum += sqrt(pow((x[city[i] - 1] - x[city[i - 1] - 1]), 2.0) + pow((y[city[i] - 1] - y[city[i - 1] - 1]), 2.0));
        }
        
    } while (next_permutation(city.begin(), city.end()));
    
    cout << setprecision(10) << sum / factorial(N) << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <map>

using namespace std;

int main(){
  int H,W,N;
  cin >> H;
  cin >> W;
  cin >> N;

  map<pair<int,int>,int> m;

  for(int i = 0;i < N;i++){
    int _1,_2;
    cin >> _1;
    cin >> _2;
    _1--;
    _2--;

    for(int h = max(_1 - 2,0);h < min(_1 + 1,H - 2);h++){
      for(int w = max(_2 - 2,0);w < min(_2 + 1,W - 2);w++){
	pair<int,int> idx(h,w);
	if(m.find(idx) == m.end()){
	  m[idx] = 1;
	}else{
	  m[idx]++;
	}
      }
    }
  }

  map<int,int> c;
  int64_t total = 0;
  for(auto& mm : m){
    if(c.find(mm.second) == c.end()){
      c[mm.second] = 1;
    }else{
      c[mm.second]++;
    }
    total++;
  }

  std::cout << (((int64_t)(H - 2))*((int64_t)(W - 2)) - total) << std::endl;
  for(int i = 1;i < 10;i++){
    if(c.find(i) == c.end()){
      std::cout << 0 << std::endl;
    }else{
      std::cout << c[i] << std::endl;
    }
  }
  
}


Measured memory_bytes: 56448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCode
{
    class Class1
    {
        static void Main(string[] args)
        {
            string c = Console.ReadLine();
            string ans = null;
            if(c == "a" || c == "i" || c == "u"|| c == "e" || c == "o")
            {
                ans = "vowel";
            }
            else
            {
                ans = "consonant";
            }
            Console.WriteLine(ans);
        }
        

       
    }
    
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
const unsigned int M = 1000000007;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> d(n);
  rep(i,k){
     int m;
     cin >> m;
     rep(j,m){
        int a;
        cin >> a;
        d[a-1] = 1;
     }
  }
  int ans = 0;
  rep(i,n) if(d[i]==0) ++ans;
  cout << ans << endl;
 return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
    string s;
    int n;
    cin >> s >> n;
    int cnt = 0;
    rep(i, s.size()){
        if(s[i] != '1'){
            if(n > cnt)
                cout << s[i] << endl;
            else
                cout << 1 << endl;
            return 0;
        }
        cnt++;
    }
    cout << 1 << endl;
}


Measured memory_bytes: 256
/* Coached by rainboy */
#include <stdio.h>

#define N 200000

int oo[1 + (N - 1) * 2], oj[1 + (N - 1) * 2];

int link(int o, int j) {
	static int _ = 1;

	oo[_] = o, oj[_] = j;
	return _++;
}

int ae[N], aa[N];

void dfs(int p, int i, int a) {
	int o;

	aa[i] += a;
	a = aa[i];
	for (o = ae[i]; o; o = oo[o]) {
		int j;

		j = oj[o];
		if (j != p)
			dfs(i, j, a);
	}
}

int main() {
	int n, q, h, i, j;

	scanf("%d%d", &n, &q);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		ae[i] = link(ae[i], j);
		ae[j] = link(ae[j], i);
	}
	while (q--) {
		int p, x;

		scanf("%d%d", &p, &x), p--;
		aa[p] += x;
	}
	dfs(-1, 0, 0);
	for (i = 0; i < n; i++)
		printf("%d ", aa[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 16384
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
  let mut buf = String::new();
  stdin().read_line(&mut buf).ok();
  buf.trim().parse::<T>().ok().unwrap()
}

fn read_tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: FromStr, T2: FromStr>(n: u32) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

fn main() {
  let s: u32 = read();
  let lrs: Vec<(u32,u32)> = read_tuples(s);
  let ans: u32 = lrs.into_iter().map(|p| p.1 - p.0 + 1).sum();
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>

int main(){
	int num=0, i;
	int money = 100000;
	scanf("%d",&num);

	for (i = 0; i < num; i++){
		money += money/20;
		if (money % 1000){
			money = (int)(ceil((double)money / 1000)) * 1000;
		}
	}
	printf("%d\n", money);

	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    bool can=true;
    vin v(n);
    rep(i,n){
        cin>>v[i];
        if(can&&i){
            if(v[i]!=v[0])can=false;
        }
    }
    if(can){
        cout<<n/2<<endl;
        return 0;
    }
    vin even (100001);
    vin odd(100001);
    rep(i,n){
        if(i%2)odd[v[i]]++;
        else even[v[i]]++;
    }
    int maxeven=*max_element(all(even));
    int maxodd=*max_element(all(odd));
    int evenadd;
    int oddadd;
    rep(i,100001){
        if(even[i]==maxeven)evenadd=i;
        if(odd[i]==maxodd)oddadd=i;
    }
    if(evenadd!=oddadd){
        cout<<n-maxeven-maxodd<<endl;
        return 0;
    }
    else{
        even[evenadd]=0;
        odd[oddadd]=0;
        int seceven=*max_element(all(even));
        int secodd=*max_element(all(odd));
        if(seceven==0)cout<<n-maxeven-secodd<<endl;
        else if(secodd==0)cout<<n-maxodd-seceven<<endl;
        else cout<<n-max(maxodd+seceven,maxeven+secodd)<<endl;
    }
}

Measured memory_bytes: 1408
//C++11

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

const int LEN = 12;
bool mat[LEN][LEN];
int visit[LEN][LEN];

void search(int i,int j,int orig)
{
    if(i<0||j<0||LEN<=i||LEN<=j) return;
    if(!mat[i][j]) return;
    if(visit[i][j]>=0) return;
    visit[i][j] = orig;
    search(i+1,j,orig);
    search(i-1,j,orig);
    search(i,j+1,orig);
    search(i,j-1,orig);
}

int solve(void)
{
    //init
    REP(i,LEN) REP(j,LEN) visit[i][j] = -1;
    //search
    REP(i,LEN) REP(j,LEN) search(i,j,i+j*LEN);
    //count
    vector <int> cnt(LEN*LEN,0);
    REP(i,LEN) REP(j,LEN) cnt[i+j*LEN] = visit[i][j];
    sort(cnt.begin(), cnt.end());
    cnt.erase(unique(cnt.begin(), cnt.end()), cnt.end());
    cnt.erase(remove(cnt.begin(), cnt.end(), -1), cnt.end());
    return cnt.size();
}

int main(void)
{
    while(true){
        //read data
        string s;
        REP(i,LEN){
            getline(cin,s);
            REP(j,LEN){
                mat[i][j] = (s[j]=='0') ? false : true;
            }
        }
        //solve and print
        int res = solve();
        cout << res << endl;
        //end of input
        if(!getline(cin,s)) break;
    }
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int MaxN = 3000 + 5, MaxM = 3000 + 5;

int N, M;
char A[MaxN], B[MaxM];
int dp[MaxN][MaxM];
bool Out[MaxN][MaxM]; int pre[MaxN][MaxM][2];
char st[MaxN]; int tp;

void init() {
  scanf("%s %s", A + 1, B + 1);
  N = strlen(A + 1), M = strlen(B + 1);
}

void solve() {
  int ans = 0, ansx = 1, ansy = 1;

  for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j) {
    if (dp[i - 1][j - 1] > dp[i][j]) {
      dp[i][j] = dp[i - 1][j - 1];
      pre[i][j][0] = i - 1;
      pre[i][j][1] = j - 1;
    }
    if (dp[i - 1][j] > dp[i][j]) {
      dp[i][j] = dp[i - 1][j];
      pre[i][j][0] = i - 1;
      pre[i][j][1] = j;
    }
    if (dp[i][j - 1] > dp[i][j]) {
      dp[i][j] = dp[i][j - 1];
      pre[i][j][0] = i;
      pre[i][j][1] = j - 1;
    }
    if (A[i] == B[j]) {
      if (dp[i - 1][j - 1] + 1 > dp[i][j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        pre[i][j][0] = i - 1;
        pre[i][j][1] = j - 1;
        Out[i][j] = true;
      }
    }
    if (dp[i][j] > ans) {
      ans = dp[i][j];
      ansx = i, ansy = j;
    }
  }

  while (ansx != 0 && ansy != 0) {
    if (Out[ansx][ansy] == true) st[++tp] = A[ansx];
    int x = pre[ansx][ansy][0], y = pre[ansx][ansy][1];
    ansx = x, ansy = y;
  }
  while (tp > 0) {
    printf("%c", st[tp]);
    tp--;
  }
}

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

Measured memory_bytes: 114816
#include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<string.h>
#include<map>
#include<cmath>
#include<stack>
#include<algorithm>
#include<assert.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
inline ll floor(const ll&a,const ll&b){return a/b;};
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const ll INF=4223372036854775807,max_n=100005,mod=1e9+7;
inline ll ceil(const ll&a,const ll&b){if(a%b==0)return a/b;return a/b+1;};
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int a[10]={0,1,2,3,4,5,6,7,8};
struct Node
{
	double x,y;
};
Node data1[10];
double juli(int x,int y)
{
	return sqrt((data1[x].x-data1[y].x)*(data1[x].x-data1[y].x)+(data1[x].y-data1[y].y)*(data1[x].y-data1[y].y));
}
double ans;
ll jiecheng(int x)
{
	ll ans=1;
	for(int i=2;i<=x;i++)
	{
		ans*=i;
	}
	return ans;
}
int main()
{
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(0);
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>data1[i].x>>data1[i].y;
	}
	do
	{
		for(int i=2;i<=n;i++)
		{
			ans+=juli(a[i],a[i-1]);
		}
	}while(next_permutation(a+1,a+1+n));
	printf("%.10f",ans/jiecheng(n));
}

Measured memory_bytes: 3716
/**
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 2019-11-23 19:44:46
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

template <typename T>
class CumulativeSum2D {
 public:
  CumulativeSum2D(const std::vector<vector<T>>& vec)
      : vec_(vec), height_(vec.size()), width_(vec[0].size()) {
    Build();
  }
  T Get(int sx, int sy, int gx, int gy);

 private:
  size_t height_;
  size_t width_;
  std::vector<vector<T>> vec_;
  std::vector<vector<T>> sum_;
  void Build();
};

// return sum of [sx, gx] * [sy, gy]
template <typename T>
T CumulativeSum2D<T>::Get(int sx, int sy, int gx, int gy) {
  assert(sx <= gx && sy <= gy);
  assert(0 <= sx && sx < height_ && 0 <= gx && gx < height_ && 0 <= sy &&
         sy < width_ && 0 <= gy && gy < width_);
  return sum_[gx + 1][gy + 1] - sum_[gx + 1][sy] - sum_[sx][gy + 1] +
         sum_[sx][sy];
}

template <typename T>
void CumulativeSum2D<T>::Build() {
  sum_.assign(height_ + 1, vector<T>(width_ + 1, static_cast<T>(0)));
  for (size_t i = 0; i < height_; ++i) {
    for (size_t j = 0; j < width_; ++j) {
      sum_[i + 1][j + 1] = sum_[i + 1][j] + vec_[i][j];
    }
  }
  for (size_t i = 0; i < width_; ++i) {
    for (size_t j = 0; j < height_; ++j) {
      sum_[j + 1][i + 1] += sum_[j][i + 1];
    }
  }
}

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

  int n, m, query; cin >> n >> m >> query;
  vector<vector<int>> board(n, vector<int>(n));
  for (int i = 0; i < m; ++i) {
    int l, r; cin >> l >> r; --l; --r;
    ++board[l][r];
  }

  CumulativeSum2D<int> cs2(board);

  for (int i = 0; i < query; ++i) {
    int p, q; cin >> p >> q;
    --p; --q;
    cout << cs2.Get(p, p, q, q) << '\n';
  }

  return 0;
}

Measured memory_bytes: 3968
N,Y = map(int,input().split())
s=0
for x in range(2001):
  for y in range(2001):
    z = N - (x+y)
    if 1000*x + 5000*y + 10000*z == Y and z >=0:
      print(z,' ',y,' ',x)
      s = s+1
      break
  else:
    continue
  break
if s == 0:
  print(-1,' ',-1,' ',-1)

Measured memory_bytes: 3064
nn = int(input())
aa = list(map(int,input().split()))
#print(aa)
aa.sort()
#print(aa)

flag = 0

for i in range(nn-1):
    if (aa[i] == aa[i+1]) and (flag == 0):
        print('NO')
        flag = 1

if flag == 0:
    print('YES')

Measured memory_bytes: 103872
#include<stdio.h>
int main(void){
int n,q;
  scanf("%d%d",&n,&q);
  char s[n+1];
  scanf("%s",&s);
  int l[q],r[q];
  for(int i=0;i<q;i++){
	scanf("%d%d",&l[i],&r[i]);
  }
int c=0;
  int ll[n],rr[n];
  for(int i=0;i<n;i++){
	ll[i]=0;
    rr[i]=0;
  }
  int flag=0;
  int cl=0,cr=0;
	for(int i=0;i<n;i++){
      if(flag&&s[i]=='C'){
	flag=0;
        cl++;
        ll[i]=cl;
      }
      else {
        if(s[i]=='A')flag=1;
        else flag=0;
 		ll[i]=cl;
         }
    }
  
     /*else ll[i]=cl;
    if(s[n-1-i]=='C'&&s[n-2-i]=='A'){
      rr[n-1-i]=cr;
     cr++;
      rr[n-2-i]=cr;
    }
      else rr[n-1-i]=cr;
    }*/
 /* for(int i=0;i<n;i++){
	printf("%d ",ll[i]);
  }
  printf("\n");
   for(int i=0;i<n;i++){
	printf("%d ",rr[n-1-i]);
  }*/
  for(int i=0;i<q;i++){
	printf("%d\n",ll[r[i]-1]-ll[l[i]-1]);
  }
  return 0;
}

Measured memory_bytes: 2432
import heapq
from itertools import chain

R = lambda: map(int, input().split())
n, k = R()
v = list(R())
r = 0
for i in range(1, min(n, k) + 1):
    for j in range(i):
        s = 0
        h = []
        for m in chain(range(i - j), range(n - j, n)):
            x = v[m]
            s += x
            if x < 0:
                heapq.heappush(h, x)
        j = i
        while h and j < k:
            s -= heapq.heappop(h)
            j += 1
        r = max(r, s)
print(r)


Measured memory_bytes: 3064
Imports System
Imports System.Collections.Generic
class p
    shared sub main()
        dim s = Console.ReadLine().Split()
        dim N = Integer.Parse(s(0))
        dim M = Integer.Parse(s(1))
        dim X = Integer.Parse(s(2))
        s = Console.ReadLine().Split()
        dim a = 0
        dim b = 0
        for each i as string In s
            if Integer.Parse(i) >= X then
                a += 1
            end if
            if Integer.Parse(i) <= X then
                b += 1
            end if
        next
        Console.WriteLine(Math.Min(a, b))
    end sub
end class

Measured memory_bytes: 22352
import java.util.*;

public class Main {
    static int max = 1000000;
    static int[] queue = new int[max];
    static int tail = 0; static int head = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] s = new char[h][w];
        for (int i=0;i<h;i++){
            String ss = sc.next();
            for (int j=0;j<w;j++)s[i][j]=ss.charAt(j);
        }
        HashMap<Integer,HashSet<Integer>> graph = new HashMap<>();
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                HashSet<Integer> hash = new HashSet<>();
                if (s[i][j]=='.'){
                    if (i!=h-1){
                        if (s[i+1][j]=='.')hash.add((i+1)*100+j);
                    }
                    if (i!=0){
                        if (s[i-1][j]=='.')hash.add((i-1)*100+j);
                    }
                    if (j!=w-1){
                        if (s[i][j+1]=='.')hash.add(i*100+j+1);
                    }
                    if (j!=0){
                        if (s[i][j-1]=='.')hash.add(i*100+j-1);
                    }
                }
                graph.put(100*i+j,hash);
            }
        }
        int ans = 0;
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                boolean[][] seen = new boolean[h][w];
                for (int a=0;a<h;a++)for (int b=0;b<w;b++)seen[a][b]=false;
                enqueue(100*i+j);
                seen[i][j]=true;
                int[][] local = new int[h][w];
                while (!isEmpty()){
                    int v = dequeue();
                    for (int ins : graph.get(v)){
                        if (!seen[ins/100][ins%100]){
                            enqueue(ins);
                            seen[ins/100][ins%100]=true;
                            local[ins/100][ins%100]=local[v/100][v%100]+1;
                        }
                    }
                }
                int LOCAL = 0;
                for (int y=0;y<h;y++){
                    Arrays.sort(local[y]);
                    LOCAL=Math.max(local[y][w-1],LOCAL);
                }
                ans = Math.max(ans,LOCAL);
            }
        }
        System.out.println(ans);
    }


    static void init(){head = 0; tail = 0;}
    static boolean isEmpty(){return (head==tail);}
    static boolean isFull(){return (head == (tail+1)%max);}
    static public void enqueue(int v){
        if (isFull()){
            System.out.println("error: queue is full.");
            return;
        }
        queue[tail++] = v;
        if (tail == max) tail = 0;
    }
    static public int dequeue(){
        if (isEmpty()){
            System.out.println("error: queue is empty");
            return -1;
        }
        int res = queue[head];
        ++head;
        if (head == max) head = 0;
        return res;
    }

}


Measured memory_bytes: 55172
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	/*
	int rs[26];
	int rt[26];
	for(int i=0;i<26;i++) rs[i]=rt[i]=-1;
	*/
	vector<int> rs(26,-1);
	vector<int> rt(26,-1);
	for(int i=0;i<s.length();i++){
		int a=s[i]-'a';
		int b=t[i]-'a';
		if(rs[a]!=-1 || rt[b]!=-1){
			if(rs[a]!=b || rt[b]!=a){
				cout << "No" << endl;
				return 0;
			}
		}else{
			rs[a]=b;
			rt[b]=a;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

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

#define rep(i, a, N) for(int i = a; i < N; i++)

int main() {
    int c[3][3];

    rep(i, 0, 3)
        rep(j, 0, 3)
            cin >> c[i][j];
    
    int column[3] = {};
    int row[3] = {};
    rep(i, 0, 3) {
        rep(j, 0, 3) {
            column[j] += c[i][j] - c[0][j];
            row[i] += c[i][j] - c[i][0];
        }
    }

    if (column[0] == column[1] && column[1] == column[2] && row[0] == row[1] && row[1] == row[2])
        cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

vector<vector<int>> G;
vector<bool> used;
vector<P> es;

void dfs(int s, int cur) {
  used[s] = true;
  for (auto t : G[s]) {
    if (es[cur] == P{ s, t } || es[cur] == P{ t, s }) continue;
    if (!used[t]) dfs(t, cur);
  }
}

main() {
  int N, M; cin >> N >> M;
  G.resize(N);
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
    es.push_back({ a, b });
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    used.assign(N, false);
    dfs(0, i);
    for (int j = 0; j < N; j++) {
      if (!used[j]) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m;
	cin >> n >> m;
	vector<vector<int>> ta(n+2,vector<int>(m+2,1));
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<m;j++){
			if(str[j]=='.'){
				ta[i+1][j+1]=0;
			}else{
				ta[i+1][j+1]=1;
			}
		}
	}
	int res=0;
	vector<vector<int>> hou={{-1,0},{1,0},{0,-1},{0,1}};
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int x=i+1,y=j+1;
			if(ta[x][y]==1) continue;
			vector<vector<bool>> ju(n+2,vector<bool>(m+2));
			ju[x][y]=true;
			vector<vector<int>> dist(n+2,vector<int>(m+2,1<<29));
			dist[x][y]=0;
			stack<pair<int,int>> st;
			st.push(make_pair(x,y));
			while(st.size()){
				pair<int,int> p0=st.top();
				st.pop();
				int cx=p0.first,cy=p0.second;
				int d=dist[cx][cy];
				for(vector<int> &h:hou){
					int nx=cx+h[0],ny=cy+h[1];
					if(ta[nx][ny]==1) continue;
					if(ju[nx][ny]==1) continue;
					if(dist[nx][ny]<=(d+1)) continue;
					dist[nx][ny]=d+1;
					st.push(make_pair(nx,ny));
				}
			}
			for(int ii=0;ii<n;ii++){
				for(int jj=0;jj<m;jj++){
					if(dist[ii+1][jj+1]>(1<<20)) continue;
					res=max(res,dist[ii+1][jj+1]);
				}
			}
		}
	}
	cout << res << "\n";
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> Pll;

constexpr ll INF = 1e15;

int main() {
    int N; cin >> N;
    vector<vector<Pll>> graph(N+1);
    for (int i = 0; i < N-1; i++) {
        int a, b, c; cin >> a >> b >> c;
        graph[a].push_back(Pll(b, c));
        graph[b].push_back(Pll(a, c));
    }
    int Q, K; cin >> Q >> K;
    vector<ll> cost(N+1, INF);
    vector<bool> searched(N+1, false);
    cost[K] = 0;
    priority_queue<Pll> pq;
    pq.push(Pll(0, K));
    while (!pq.empty()) {
        Pll x = pq.top(); pq.pop();
        ll c = x.first, f = x.second;
        if (searched[f]) continue;
        searched[f] = true;
        for (auto y : graph[f]) {
            if (y.second + c < cost[y.first]) {
                pq.push(Pll(y.second + c, y.first));
                cost[y.first] = c + y.second;
            }
        }
    }
    while (Q--) {
        int x, y; cin >> x >> y;
        cout << cost[x] + cost[y] << endl;
    }
}


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll n,m;
    cin>>n>>m;
    ll ans= ((n*(n-1))/2) + ((m*(m-1))/2);
    cout<<ans<<"\n";
}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3548
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int[][] array = new int[w+1][h+1];
        
        int n = sc.nextInt();
        while (n-- > 0) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int type = sc.nextInt();
            
            if (type == 1) {
                for (int i = 1; i <= h; i++) {
                    for (int j = 1; j <= x; j++) {
                        array[j][i] = 1;
                    }
                }
            } else if (type == 2) {
                for (int i = 1; i <= h; i++) {
                    for (int j = x+1; j <= w; j++) {
                        array[j][i] = 1;
                    }
                }
            } else if (type == 3) {
                for (int i = 1; i <= w; i++) {
                    for (int j = 1; j <= y; j++) {
                        array[i][j] = 1;
                    }
                }
            } else {
                for (int i = 1; i <= w; i++) {
                    for (int j = y+1; j <= h; j++) {
                        array[i][j] = 1;
                    }
                }
            }
        }
        
        int count = 0;
        for (int i = 1; i <= w; i++) {
                // System.out.println(Arrays.toString(array[i]));
            for (int j = 1; j <= h; j++) {
                if (array[i][j] == 1) count++;
            }
        }
        
        System.out.println(h * w - count);
    }
}


Measured memory_bytes: 38592
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    
    cin >> n;
    
    for (int i = n; i <= 999; i++) {
        int tmp = i;
        int keta1 = tmp % 10;
        tmp /= 10;
        int keta2 = tmp % 10;
        tmp /= 10;
        int keta3 = tmp % 10;
        if (keta1 == keta2 && keta2 == keta3) {
            cout << i << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

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

    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> abs_A(N);
    ll cnt = 0;
    ll sum = 0;
    rep(i, N) {
        sum += abs(A[i]);
        abs_A[i] = abs(A[i]);
        if (A[i] < 0) cnt++;
    }

    if (cnt % 2 == 0) {
        cout << sum << endl;
        return 0;
    }

    sort(ALL(abs_A));
    cout << sum - 2 * abs_A[0] << endl;

    return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
//#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int INF = 1e10;
const long double PI = (acos(-1));

int dp[105][4][2];
// dp[i][num][sml] : i桁目まで 非ゼロがnum個 smlが0ならNと一致　smlが1ならN未満が確定

signed main() {
	string N;
	int K;
	cin >> N >> K;
	dp[0][0][0] = 1;
	int len = N.size();
	rep(i, len)rep(num, 10)rep(sml, 2) {
		int nd = N[i] - '0'; //Nのi桁目の数字
		rep(d, 10) {
			int ni = i + 1, nnum = num, nsml = sml;
			if (d != 0)nnum++; //非ゼロのとき、numは1増える
			if (nnum > K)continue; 
			if (sml == 0) { //Nと一致してるなら
				if (d > nd)continue; //ndは超えてはならない
				if (d < nd)nsml = 1; //nd未満なら、次はN未満が確定
			}
			dp[ni][nnum][nsml] += dp[i][num][sml];
		}
	}
	int ans = dp[len][K][0] + dp[len][K][1];
	cout << ans << endl;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll n;
    cin >> n;
    vs s(n);
    rep(i,n)cin >> s[i];

    ll m;
    cin >> m;
    vs t(m);
    rep(i,m)cin >> t[i];

    ll count=0,max=-1;
    rep(i,n){
        count=0;
        rep(j,n){
            if(s[i] == s[j])count++;
        }
        rep(j,m){
            if(s[i] == t[j])count--;
        }
        if(count >= max)max = count;
    }

    if(max < 0)max = 0;
    
    cout << max << endl;
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<char>c(n);
  
  for (int i = 0; i < n; i++)
  {
    cin >> c.at(i);
  }
  
  k -= 1;
  
  if (c.at(k) == 'A')
    c.at(k) = 'a';
  if (c.at(k) == 'B')
    c.at(k) = 'b';
  if (c.at(k) == 'C')
    c.at(k) = 'c';
  
  for (int i = 0; i < n; i++)
    cout << c.at(i);
  
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>

using namespace std;

const int MAXN = 100000;

map<pair<int, int>, int> edges;
queue<pair<int, int> > q;
int dad[1 + MAXN], components;
vector<int> g[1 + MAXN];

int findDad(int node) {
    if (dad[node] == node)
        return node;
    return dad[node] = findDad(dad[node]);
}

void addEdge(int a, int b) {
    a = findDad(a);
    b = findDad(b);
    g[a].emplace_back(b);
    g[b].emplace_back(a);
    if (a > b)
        swap(a, b);
    edges[make_pair(a, b)]++;
    if (edges[make_pair(a, b)] == 2)
        q.push(make_pair(a, b));
}

void join(int a, int b) {
    components--;
    if (g[a].size() > g[b].size())
        swap(a, b);
    dad[a] = b;
    for (auto it : g[a]) {
        int c = findDad(it);
        if (c != b)
            addEdge(b, c);
    }
}

int main(){
    //ifstream cin("input.in");
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        dad[i] = i;
    for (int i = 1; i <= 2 * (n - 1); i++) {
        int a, b;
        cin >> a >> b;
        addEdge(a, b);
    }
    components = n;
    while (!q.empty()) {
        int a = q.front().first, b = q.front().second;
        q.pop();
        a = findDad(a);
        b = findDad(b);
        if (a != b)
            join(a, b);
    }
    if (components == 1)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}





Measured memory_bytes: 30588
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String s = S.substring(0, S.length());
		String t = T.substring(0, S.length());
		if(s.equals(t))
		System.out.println("Yes");
		else
		System.out.println("No");
	}
}

Measured memory_bytes: 35868
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, l;
    cin >> n >> l;
    int sum = 0;
    int diff = 1000000;
    int ans = 0;
    REP(i, n)
    {
        sum += l + (i + 1) - 1;
    }

    REP(i, n)
    {
        int tmp = l + i + 1 - 1;
        if (diff > abs(tmp))
        {
            ans = sum - tmp;
            diff = abs(tmp);
        }
    }
    cout << ans << endl;
}

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

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

	string S;
	cin >> S;

	bool ans = false;

	if (N % 2 == 0) {
		string mae = S.substr(0, N/2);
		string ato = S.substr(N/2, N/2);
		if (mae == ato) {
			ans = true;
		}
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n,w,i,j;
    cin>>n>>w;
    ll a[n],b[n];
    ll ma=0;
    ifr(i,n)cin>>a[i]>>b[i],ma+=b[i];
    ll dp[n][ma+1];
    ifr(i,n)
    	ifr(j,ma+1)
    		dp[i][j]=INT_MAX;
    dp[0][b[0]]=a[0];
    fr(i,1,n,1){
    	ifr(j,ma+1){
    		if(j-b[i] >= 0){
    			if(dp[i-1][j-b[i]]!=INT_MAX)
	    			dp[i][j]=min(dp[i-1][j],dp[i-1][j-b[i]]+a[i]);
	    		else{
	    			if(j-b[i]==0)
		    			dp[i][j]=min(dp[i-1][j],a[i]);
		    		else
		    			dp[i][j]=dp[i-1][j];
	    		}
    		}
	    	else
	    		dp[i][j]=dp[i-1][j];
    	}
    }
    ll c=0;
    ifr(i,ma+1){
    	if(dp[n-1][i]<=w)
    		c=i;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,l,r;
    cin >> N >> l >> r;
    while(N != 0){
        vector<int> A(N+1);
        for(int i=1; i<=N; i++){
            cin >> A[i];
        }
        int cnt = 0;
        for(int x=l; x<=r; x++){
            bool did = false;
            for(int i=1; i<=N; i++){
                if(x%A[i] == 0){
                    did = true;
                    if(i%2){
                        cnt++;
                    }
                    break;
                }
            }
            if(!did and N%2==0) cnt++;
        }
        cout << cnt << enld;
        cin >> N >> l >> r;
    }
    return 0;
}


Measured memory_bytes: 3184