akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n, l;
    cin >> n >> l;

    int sum = n * l + n*(n+1)/2 - n;
    int ans = INF;
    int apple = 0;
    
    irep2(i, 1, n) {
        int eat = sum - (l + i - 1);
        if(ans > abs(eat-sum)) {
            apple = i;
            ans = abs(eat-sum);
        }
    }
    cout << sum - (l + apple -1) << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int K;
  string S;
  cin >> K >> S;
  if(SZ(S)<=K) cout << S << endl;
  else{
    rep(i,K) cout << S[i];
    cout << "...";
    cout << endl;
  }
  return 0;
}


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

int main(){
    int x,y;
    cin >> x >> y;
    int ans =0;
    int f=0;
    int s=0;
    int t=0;
    int w=0;

    if(x==1){
        f++;
    }
    if(x==2){
        s++;
    }
    if(x==3){
        t++;
    }
      if(y==1){
        f++;
    }
    if(y==2){
        s++;
    }
    if(y==3){
        t++;
    }
    if(x==1&&y==1){
        w++;
    }

    cout <<100000*t + 200000*s + 300000*f + 400000*w <<endl;


}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		long x = fs.nextLong();
		long a = x/500;
		x -= a*500;
		long b = x/5;
		long ans = a * 1000 + b * 5;
		System.out.println(ans);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d; 
  
  for(int i; ;i++){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      break;
    }
    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      break;
    }
  }
    
}


Measured memory_bytes: 3600
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL dp[20002][2002];
int N;
struct data{
	int w,s,v;
}a[1002];
bool cmp(data A,data B){
	return A.s+A.w<B.s+B.w;
}
int main(){
	fastio;
	cin>>N;
	rb(i,1,N)
		cin>>a[i].w>>a[i].s>>a[i].v;
	sort(a+1,a+1+N,cmp);
	LL res=0;
	rb(i,1,N){
		rb(W,0,20000){
			dp[W][i]=dp[W][i-1];
			if(a[i].w<=W&&a[i].s>=W-a[i].w){
				dp[W][i]=max(dp[W][i],dp[W-a[i].w][i-1]+a[i].v);
			}
			res=max(res,dp[W][i]);
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 253056
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	cin >> N >> M;
	vector<pair<int, int>>v(M);
	for (auto &i : v)cin >> i.first >> i.second;
	sort(v.begin(), v.end());
	vector<int>l(N + 1);
	vector<int>r(N + 1);
	for (int i = 1; i <= N; i++) {
		l[i] = r[i] = i;
	}
	for (auto i : v) {
		l[i.second] = l[i.second + 1] = min(l[i.second], l[i.second + 1]);
		r[i.second] = r[i.second + 1] = max(r[i.second], r[i.second + 1]);
	}
	for (int i = 1; i <= N; i++) {
		if (i > 1)cout << " ";
		cout << r[i] - l[i] + 1;
	}
	cout << endl;
}


Measured memory_bytes: 5112
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
char mat[10002];
ll ans[10002];
ll dfs(ll u)
{
	if (ans[u]!=-1)
	{
		return ans[u];
	}
	ll an=1e17;
	for(auto v:adj[u])
	{
		if (mat[v]=='.')
		{
			an=min(an, dfs(v));
		}else{
			if(mat[u]=='.')
			{
				an=min(an, 1+dfs(v));				
			}else{
				an=min(an, dfs(v));
			}
		}
	}
	if (an==1e17)
	{
		an=0;
	}
	ans[u]=an;
	return an;
}
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll h,w;
	cin>>h>>w;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin>>mat[i*w+j];
			if(i<h-1){
			adj[i*w+j].pb((i+1)*w+j);
			}
			if(j<w-1){
			adj[i*w+j].pb(i*w+j+1);
			}
			ans[i*w+j]=-1;
		}
	}
	cout<<dfs(0)+(mat[0]=='#')<<"\n";
	return 0;
}


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

int main() {
  char c;
  cin >> c;

  int num = c;
  num++;
  char ans = num;
  cout << ans << endl;
  return 0;
}

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

if N == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


fact_list = factorization(N)

res = 0
for k, v in fact_list:
    cnt = 1
    while True:
        v -= cnt

        if v == 0:
            res += 1
            break

        if v < 0:
            break

        cnt += 1
        res += 1

print(res)


Measured memory_bytes: 9492
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 998244353
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return sol;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int a[200005], b[200005];
void solve()
{
	int n;
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i] >> b[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	int ans = 0;
	if(n & 1)
	{
		int l = a[n / 2];
		int r = b[n / 2];
		ans = r - l + 1;
	}
	else
	{
		int l = a[n / 2] + a[n / 2 - 1];
		int r = b[n / 2] + b[n / 2 - 1];
		ans = r - l + 1;
	}
	cout << ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
}


Measured memory_bytes: 5164
import java.util.*;

public class Main {
    public static void main(String[] args) {
//        test();
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        System.out.println(calc(N));
    }
    
    private static long calc(int x) {
        int[] primes = new int[x+1];
        Arrays.fill(primes, 1);
        primes[0] = primes[1] = 0;
        for (int i = 3; i < primes.length; i++) {
            if (i % 2 == 0) primes[i] = 0;
        }

        int j = 3;
        while (j*j < primes.length) {
            for (int k = j+1; k < primes.length; k++) {
                if (k % j == 0) primes[k] = 0;
            }

            j += 2;
        }



        // Calc factorial
        int[] factors = new int[x + 1];

        while(x > 1) {
            int i = 3;
            int f = x;

            while (f % 2 == 0) {
                factors[2]++;
                f /= 2;
            }

            while (i <= f) {
                if (primes[i] == 1) {
                    while (f % i == 0) {
                        factors[i]++;
                        f /= i;
                    }
                }
                i += 2;
            }
            if (f != 1) factors[f]++;

            x--;
        }

//        System.out.println(Arrays.toString(factors));

        long d = (long)Math.pow(10, 9) + 7;
        long count = 1;
        for (int f: factors) {
            if (f != 0)
                count *= (f+1);
            while (count >= d) {
                count -= d;
            }
//            System.out.println(count);
        }

        return count;
    }
    
    private static void test() {
        assert calc(6) == 30;
        assert calc(1000) == 972926972;
    }
}


Measured memory_bytes: 9684
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.conv;

void main() {
	auto n = (readln.chomp.to!int % 500);
	auto A = readln.chomp.to!int;
	if(n > A) "No".writeln;
	else "Yes".writeln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    ll W,H;
    cin>>W>>H;
    ll x,y;
    cin>>x>>y;
    //ll ans;
    //ans=W*H*10000000/2;
   // cout<<ans/10000000<<"."<<ans%10000000/1000000<<ans%1000000/100000<<ans%10000/1000
    //<<ans%1000/100<<ans%100/10<<ans%10;
    cout<<double(W)*double(H)/2;
        if(x*2==W&&y*2==H)cout<<" "<<1;
        else cout<<" "<<0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();

		System.out.println(Math.PI * 2 * r);
	}

}


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

int a[]{ 1867,1911,1925,1988,7000 };
char dir[] = "MTSH";
int main() {
	int e, y; scanf("%d%d", &e, &y);
	if (e == 0) {
		int i; for (i = 0; a[i] < y; i++); i--;
		printf("%c%d\n", dir[i], y - a[i]);
	}
	else printf("%d\n", y + a[e - 1]);
}

Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
    cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np


N, C_num = map(int, input().split(" "))
S, T, C = [], [], []
for _ in range(N):
    s, t, c = map(int, input().split(" "))
    S.append(s * 2 - 1)
    T.append(t * 2)
    C.append(c - 1)

table = np.zeros((C_num, 10 ** 5 * 3), "int32")
for s, t, c in zip(S, T, C):
    table[c, s:t] = 1

print(table.sum(0).max())


Measured memory_bytes: 65956
#include <bits/stdc++.h>
using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

int main() {
	int A,B,C;
	string D, E, F;
	cin >> D;
	A = 0;
	for (size_t i = 0; i < 3; i++)
	{
		if (D.at(i) == 'R')A++;
	}
	if (A==2&&D.at(1) != 'R')A--;
	cout << A;
}

Measured memory_bytes: 3620
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <math.h>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  long n,a[200000],cnt[100000];
  bool ans=true;
  std::cin >> n;
  for(long i=0; i<n; i++){
     std::cin >> a[i];
     cnt[i]=0;
   }

   for(int i=0; i<n; i++){
     cnt[a[i]]++;
   }

   if(n%2==1){
     if(cnt[0]!=1) ans=false;
   for(int i=2; i<=n-1; i+=2){
     if(cnt[i]!=2) ans=false;
   }
 }

 else if(n%2==0){
   if(cnt[0]!=0) ans=false;
 for(int i=1; i<=n-1; i+=2){
   if(cnt[i]!=2) ans=false;
 }
}
  ll b=1;

   if(ans){
     for(int i=1; i<=n/2; i++){
       b*=2;
       b=b%mod;
     }
     std::cout << b << '\n';
   }
   else std::cout << '0' << '\n';

  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
  int a,b,c,d=0;
  scanf("%d%d%d\n", &a, &b, &c);
  if(a==b && a!=c) d=1;
  if(a==c && a!=b) d=1;
  if(b==c && a!=c) d=1;
  
  if(d==1)puts("Yes");
  else  puts("No");
     return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        if (s.contains("A") && s.contains("B")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


Measured memory_bytes: 22868
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int D=1000010;
int n,dp[D],ans=INT_MAX;
vector<int> g[D];
void recalc(int x,int fa){
    int mx=0;
    for (auto i:g[x]){
	if (i==fa) continue;
	int t=(dp[i]>0?dp[i]:1);
	dp[x]+=t;
	mx=max(mx,(int)(dp[i]==0));
    }
    dp[x]-=mx;
}
void dark(int x,int fa){
    int tmp=dp[fa],tmp2=dp[x];
    if (fa){
	recalc(fa,x);
	recalc(x,0);
    }
    if (g[x].size()>=3) ans=min(ans,dp[x]);
    for (auto i:g[x]){
	if (i==fa) continue;
	dark(i,x);
    }
    dp[fa]=tmp;
    dp[x]=tmp2;
}
void calc(int x,int fa){
    int mx=0;
    for (auto i:g[x]){
	if (i==fa) continue;
	calc(i,x);
	int t=(dp[i]>0?dp[i]:1);
	dp[x]+=t;
	mx=max(mx,(int)(dp[i]==0));
    }
    dp[x]-=mx;
    //cerr<<"X"<<x<<" "<<fa<<" "<<dp[x]<<endl;
}
int main(){
    scanf("%d",&n);
    for (int i=1; i<n; ++i){
	int x,y; scanf("%d%d",&x,&y); ++x; ++y;
	g[x].push_back(y);
	g[y].push_back(x);
    }
    bool fl=1;
    for (int i=1; i<=n; ++i) if (g[i].size()>=3) fl=0;
    if (fl){
	cout<<1;
	return 0;
    }
    int r;
    for (int i=1; i<=n; ++i) if (g[i].size()>=3){
	    r=i;
	    break;
	}
    //cerr<<"RR"<<r<<endl;
    calc(r,0);
    //for (int i=1; i<=n; ++i) cout<<dp[i]<<" "; cout<<endl;
    //return 0;
    ans=dp[r];
    //dark(r,0);
    cout<<ans;
}


Measured memory_bytes: 29824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <tuple>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

int main(int argc, char **argv) {
    int n;
    cin >> n;
    std::vector<i64> vec(n);
    for (int i=0; i<n; ++i) {
        cin >> vec[i];
    }

    bool ok{true}, fl{false};
    i64 num{0};
    for (int i=1; i<n; ++i) {
        num = max(num, vec[i]);
        if (vec[i-1] > vec[i]) {
            if (fl) {
                ok = false;
                break;
            }
            if (num - vec[i] > 1) {
                ok = false;
                break;
            }
            if (vec[i-1] - vec[i] == 1) {
                fl = true;
                continue;
            } else {
                ok = false;
                break;
            }
        } else {
            fl = false;
        }
    }

    cout << (ok ? "Yes": "No") << endl;

    return 0;
}


Measured memory_bytes: 1024
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
bool arr[100000];
int main() {
	IOS
	cin>>n>>k;
	ans=n;
	for(int i=1;i<=k;i++){
		int t;
		cin>>t;
		while(t--){
			int w;
			cin>>w;
			arr[w]=1;
		}
	}
	for(int i=1;i<=n;i++)
		if(arr[i])
			ans--;
	cout<<ans<<endl;

}

Measured memory_bytes: 3668
//https://abc100.contest.atcoder.jp/tasks/abc100_d

#include <vector>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <iomanip>
#include <queue>
#include <string>
using namespace std;

#define left asdfghjkl
#define right sdfghjk
#define ll long long
#define db double

struct triple{
    ll a, b, c;
};

int n,m;
vector<triple> cake;

ll findCake(ll k){
    priority_queue<ll, vector<ll>, less<ll> > pq;
    ll c1, c2, c3;
    c3 = (ll) k % 2;
    k = (ll) k/2;
    c2 = (ll) k % 2;
    k = (ll) k/2;
    c1 = k;
    if(!c1){
        c1 = -1;
    }
    if(!c2){
        c2 = -1;
    }
    if(!c3){
        c3 = -1;
    }
    for(int i = 0; i < n; i++){
        ll a, b,c ;
        a = cake[i].a;
        b = cake[i].b;
        c = cake[i].c;
        pq.push(c1*a + c2*b + c3*c);
    }
    ll sum = 0;
    for(int i = 0; i < m; i++){
        sum += pq.top();
        pq.pop();
    }
    //cout << sum << endl;
    return sum;
}

int main(){
    //freopen("input.txt","r",stdin);
    cin >> n >> m;
    for(ll i = 0; i < n; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        triple temp;
        temp.a = a;
        temp.b = b;
        temp.c = c;
        cake.push_back(temp);
    }
    ll res = 0;
    for(ll i = 0; i < 8; i++){
        res = max(res,findCake(i));
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rt register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rt it = f; it <= e; ++it)
#define per(it, f, e) for (rt it = f; it >= e; --it)
const int MAXN = 2e5 + 10;
ll dp[MAXN];
int h[MAXN];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, k;
	cin >> n >> k;
	rep (i, 1, n) {
		cin >> h[i];
	}
	rep (i, 2, n) {
		dp[i] = 1e18;
		rep (j, 1, min(i - 1, k)) {
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << dp[n] << endl; 
	return 0;
}

Measured memory_bytes: 1408
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;


int main(int argc, char* argv[]) {

	string S;
	int cnt,ans = 1;

	cin >> S;

	if(S[0]!='A'){
		ans=0;
	}

	cnt=0;
	for (int i=2;i<S.length()-1;i++){
		if (S[i]=='C') {
			cnt++;
		}
	}

	if(cnt!=1){
		ans=0;
	}

	cnt=0;
	for (int i=1;i<S.length();i++){
		if(S[i]>='A' && S[i]<='Z'){
			cnt++;
		}
	}

	if(cnt!=1){
		ans=0;
	}

	if(ans){
		cout << "AC" << endl;
	}
	else{
		cout << "WA" << endl;
	}

	return 0;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import collections

def search_b(a_char, a_count, b_most_common, fixed_count):
  thres = fixed_count - a_count
  for (b_char, b_count) in [b for b in b_most_common if b[1] > thres]:
    if a_char != b_char:
      return a_count + b_count
  
  return fixed_count


def search(a_most_common, b_most_common):
  fixed_count = -1
  b_max = b_most_common[0][1]

  for (a_char, a_count) in a_most_common:
    if a_count <= fixed_count - b_max:
      break

    fixed_count = search_b(a_char, a_count, b_most_common, fixed_count)
  
  return fixed_count


def main():
  n = int(input())
  V = list(map(int, input().split()))

  a = V[::2]
  b = V[1::2]
  
  a_counter = collections.Counter(a)
  b_counter = collections.Counter(b)

  a_most_common = a_counter.most_common()
  b_most_common = b_counter.most_common()

  if len(a_most_common) == 1 and len(b_most_common) == 1 and a_most_common[0][0] == b_most_common[0][0]:
    print(n // 2)
    return

  print(n - search(a_most_common, b_most_common))


if __name__ == '__main__':
  main()


Measured memory_bytes: 21944
#include <stdio.h>

int main(void) {
    double i,max,min;
    scanf("%lf",&max);
    min=max;
    while(1) {
        if(scanf("%lf",&i) == -1){
            break;
        }
        if(i < min){
            min = i;
        }
        if(i > max){
            max = i;
        }
    }
    printf("%f\n",max-min);
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
using namespace std;
int main(void){
	int a,b,n,s;
	while(cin>>a>>b>>n){
		a%=b;
		s=0;
		for(int i=0;i<n;++i){
			a*=10;
			s+=a/b;
			a%=b;
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <stack>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int r,c,n;
  cin>>r>>c>>n;
  vector<pair<ll,int>> v;
  for(int i=0;i<n;i++){
    int x,y,a,b;
    cin>>x>>y>>a>>b;
    if(x==0||x==r||y==0||y==c){
      if(a==0||a==r||b==0||b==c){
        if(x==0) v.push_back(make_pair(y,i));
        else if(y==c) v.push_back(make_pair(c+x,i));
        else if(x==r) v.push_back(make_pair(c-y+c+r,i));
        else if(y==0) v.push_back(make_pair(r-x+c+r+c,i));

        if(a==0) v.push_back(make_pair(b,i));
        else if(b==c) v.push_back(make_pair(c+a,i));
        else if(a==r) v.push_back(make_pair(c-b+c+r,i));
        else if(b==0) v.push_back(make_pair(r-a+c+r+c,i));
      }
    }
  }
  sort(v.begin(),v.end());

  stack<int> st;
  bool used[n+1]={};
  for(int i=0;i<v.size();i++){
    int now=v[i].second;
    if(used[now]==false){
      used[now]=true;
      st.push(now);
    }else{
      if(now==st.top()){
        st.pop();
      }else{
        cout<<"NO"<<endl;
        return 0;
      }
    }
  }

  cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 6256
#include <iostream>
#include <algorithm>

#include <cmath>
#include <string>

using namespace std;

int main() {
  // int max = 100000;

  string s;

  cin >> s;

  for (unsigned int i = 0; i < s.length(); ++i) {
    if (i % 2 == 0) {
      cout << s[i];
    }
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<queue>
#define M 52
#include<cstring>
using namespace std;
typedef pair<int,int> P;
bool flag;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1},w,h;
char r[M][M],l[M][M];
bool dp[M][M][M][M];

void bfs(int a,int b,int c,int d){
	queue<P> rr,ll;
	ll.push(P(a,b));
	rr.push(P(c,d));
	while(!ll.empty()&&!flag){
		P p=ll.front(),q=rr.front();
		ll.pop();rr.pop();
		int ly=p.first,lx=p.second,ry=q.first,rx=q.second;
		if(dp[ly][lx][ry][rx]!=0)
			continue;
		dp[ly][lx][ry][rx]=1;
		if(l[ly][lx]=='%'&&r[ry][rx]=='%'){
			flag=true;
			break;
		}else if(l[ly][lx]=='%'||r[ry][rx]=='%')
			continue;
		int nrx,nry,nlx,nly;
		for(int i=0;i<4;i++){
			nrx=dx[i]+rx;
			nry=dy[i]+ry;
			nlx=-dx[i]+lx;
			nly=dy[i]+ly;
			if(!(nrx>=0&&nrx<w&&nry>=0&&nry<h)||r[nry][nrx]=='#'){
				nrx=rx;nry=ry;
			}
			if(!(nlx>=0&&nlx<w&&nly>=0&&nly<h)||l[nly][nlx]=='#'){
				nlx=lx;nly=ly;
			}
			if(dp[nly][nlx][nry][nrx]==0){
				ll.push(P(nly,nlx));
				rr.push(P(nry,nrx));
			}
		}
	}
}
int main(){
	int a,b,c,d;
	while(cin>>w>>h,h||w){
		for(int i=0;i<h;i++)
			cin>>l[i]>>r[i];
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++){
				if(l[i][j]=='L'){
					a=i;b=j;
				}
				if(r[i][j]=='R'){
					c=i;d=j;
				}
		}
		memset(dp,0,sizeof(dp));
		flag=false;
		bfs(a,b,c,d);
		puts(flag?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
//#define sz 2

using namespace std;

int ans[ 200010 ];
int res[ 200010 ];
int fa[ 200010 ];
vector< int > e[ 200010 ];

void dfs( int );
int main() {
	int n;
	int x, y, sum = 0;
	int t, tt, ttt;
	int a = 1, b = 2, c = 3;
	scanf( "%d", &n );
	for( int i = 1; i < n; ++i ) {
		scanf( "%d%d", &x, &y );
		e[ x ].push_back( y );
		e[ y ].push_back( x );
	}
	ans[ 1 ] = 1;
	dfs( 1 );
	for( int i = 1; i <= n; ++i )
		if( ans[ i ] == 1 )
			++sum;
	tt = ttt = t = n / 3;
	if( n % 3 >= 1 )
		++t;
	if( n % 3 >= 2 )
		++tt;
	if( sum > t + ttt ) {
		for( int i = 1; i <= n; ++i )
			if( ans[ i ] == 2 ) {
				res[ i ] = c;
				c += 3;
			}
		for( int i = 1; i <= n; ++i ) {
			if( ans[ i ] == 1 ) {
				if( a <= n ) {
					printf( "%d ", a );
					a += 3;
				} else if( b <= n ) {
					printf( "%d ", b );
					b += 3;
				} else {
					printf( "%d ", c );
					c += 3;
				}
			} else 
				printf( "%d ", res[ i ] );
		}
	} else if( n - sum > tt + ttt ) {
		for( int i = 1; i <= n; ++i )
			if( ans[ i ] == 1 ) {
				res[ i ] = c;
				c += 3;
			}
		for( int i = 1; i <= n; ++i ) {
			if( ans[ i ] == 2 ) {
				if( a <= n ) {
					printf( "%d ", a );
					a += 3;
				} else if( b <= n ) {
					printf( "%d ", b );
					b += 3;
				} else {
					printf( "%d ", c );
					c += 3;
				}
			} else 
				printf( "%d ", res[ i ] );
		}
	} else {
		for( int i = 1; i <= n; ++i ) {
			if( ans[ i ] == 1 ) {
				if( a <= n ) {
					printf( "%d ", a );
					a += 3;
				} else {
					printf( "%d ", c );
					c += 3;
				}
			} else {
				if( b <= n ) {
					printf( "%d ", b );
					b += 3;
				} else {
					printf( "%d ", c );
					c += 3;
				}
			}
		}
	}
	return 0;
}

void dfs( int x ) {
	for( int i = 0; i < e[ x ].size(); ++i ) {
		if( fa[ x ] == e[ x ][ i ] )
			continue;
		fa[ e[ x ][ i ] ] = x;
		if( ans[ x ] == 1 )
			ans[ e[ x ][ i ] ] = 2;
		else
			ans[ e[ x ][ i ] ] = 1;
		dfs( e[ x ][ i ] );
	}
}

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

vector<int> X, Y, Xsum, Ysum;
int dpx[4000][17000], dpy[4000][17000];
int main() {
	string s;
	int x, y;
	cin >> s >> x >> y;
	int which=1, cnt=0;
	bool head=true;
	for(int i=0; i<s.size(); ++i){
	    if(s[i]=='T'){
	        if(head){
	            x -= cnt;
	            head=false;
	        }
	        else if(cnt>0){
	            if(which>0){
	                x += cnt;
	                X.push_back(cnt);
	                if(Xsum.size()>0) Xsum.push_back(Xsum.back()+cnt);
	                else Xsum.push_back(cnt);
	            }else{
	                y += cnt;
	                Y.push_back(cnt);
	                if(Ysum.size()>0) Ysum.push_back(Ysum.back()+cnt);
	                else Ysum.push_back(cnt);
	            }
	        }
	        which=1-which;
	        cnt=0;
	    }
	    else ++cnt;
	}
	if(cnt>0){
	    if(head) x -= cnt;
	    else if(which>0){
	        x += cnt;
	        X.push_back(cnt);
	        if(Xsum.size()>0) Xsum.push_back(Xsum.back()+cnt);
	        else Xsum.push_back(cnt);
	        
	    }else{
	        y += cnt;
	        Y.push_back(cnt);
	        if(Ysum.size()>0) Ysum.push_back(Ysum.back()+cnt);
	        else Ysum.push_back(cnt);
	    }
	}
	bool flag;
	if(x<0 || x%2>0 || y<0 || y%2>0) flag=false;
	else{
	    dpx[0][0]=1, dpy[0][0]=1;
	    for(int i=0; i<X.size(); ++i){
	        for(int j=0; j<=Xsum[i]; ++j){
	            dpx[i+1][j]=dpx[i][j];
	            if(X[i]<=j){
	                if(dpx[i][j-X[i]]==1) dpx[i+1][j]=1;
	            }
	        }
	    }
	    for(int i=0; i<Y.size(); ++i){
	        for(int j=0; j<=Ysum[i]; ++j){
	            dpy[i+1][j]=dpy[i][j];
	            if(Y[i]<=j){
	                if(dpy[i][j-Y[i]]==1) dpy[i+1][j]=1;
	            }
	        }
	    }
	    flag=(dpx[X.size()][x/2]==1) && (dpy[Y.size()][y/2]==1);
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 266624
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
using namespace std;
vector<ll> v[100001];
ll dp[100001], b[100001];
ll calc(ll x)
{
	b[x] = 1;
	if(v[x].empty())
		return dp[x] = 0;
	if(dp[x] >=0)
		return dp[x];
	for(auto u: v[x])
		dp[x] = max(dp[x], 1 + calc(u));
	return dp[x];
}
int main(void)
{
	ll n, m, t1, t2, i, m1;
	for(i=0; i<100001; i++)
		dp[i] = -1;
	cin>>n>>m;
	while(m--)
	{
		cin>>t1>>t2;
		v[t1].pb(t2);
	}
	for(i=1; i<=n; i++)
		if(!b[i])
			calc(i);
	m1 = dp[1];
	for(i=1; i<=n; i++)
		m1 = max(m1, dp[i]);
	cout<<m1<<"\n";
}	

Measured memory_bytes: 8576
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> A = new ArrayList<Integer>();
        int N = sc.nextInt();
        int D = sc.nextInt();
        long ans = 1;
        for (int i = D; i < N; i += D * 2 + 1) {
            if (i + D + 1 < N)
                ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
w,h,n = map(int,input().split())
paint = [list(map(int,input().split())) for _ in range(n)]
x1,x2,y1,y2 = 0,w,0,h
for p in paint:
    if p[2] == 1:
        x1 = max(x1,p[0])
    elif p[2] == 2:
        x2 = min(x2,p[0])
    elif p[2] == 3:
        y1 = max(y1,p[1])
    else:
        y2 = min(y2,p[1])
print(0 if x1>x2 or y1>y2 else (x2-x1)*(y2-y1))

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N, K;
int H[MAX_N];

signed main()
{
  cin >> N >> K;
  REP(n,N) {
    cin >> H[n];
  }

  sort(H, H+N, greater<int>());

  int ans = 0;
  FOR(n,K,N){
    ans += H[n];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;

int main() {
	int h, n;
	cin >> h >> n;
	vector<int>a(n);
	vector<int>b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	vector<vector<int>>dp(n + 1, vector<int>(h));
	for (int i = 0; i < n + 1; i++) {
		for (int j = 0; j < h; j++) {
			dp[i][j] = INF;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < h; j++) {
			if(j < a[i]) {
				dp[i + 1][j] = min(dp[i][j], b[i]);
			}
			else {
				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - a[i]] + b[i]);
			}
		}
	}
	//auto p = max(a.begin(), a.end());
	/*vector<int>dp(h + 1, INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < h; j++) {
			int nj = min(h, j + a[i]);
			dp[nj] = min(dp[nj], dp[j] + b[i]);	
		}
	}*/
	cout << dp[n][h-1] << endl;
	return 0;
}

Measured memory_bytes: 39424
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<String> Ans = new ArrayList<String>();
		String line = in.readLine();
		int size = Integer.parseInt(line);
		
		for(int n=0; n<size; n++){
			Ans.add("Case " + Integer.toString(n+1) + ":");
			
			line = in.readLine();
			int s = Integer.parseInt(line);
			
			for(int m=0; m<10; m++){
				s = nextNum(s);
				Ans.add(Integer.toString(s));
			}
		}
		
		for(int n=0; n<Ans.size(); n++){
			System.out.println(Ans.get(n));
		}
	}
	
	public int nextNum(int s){
		s = s * s;
		String dst = Integer.toString(s);
		int a = 8 - dst.length();
		for(int n=0; n<a; n++){
			dst = "0" + dst;
		}
		
		dst = dst.substring(2, 6);
		return Integer.parseInt(dst);
	}
}

Measured memory_bytes: 9368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll h, n;
    cin >> h >> n;

    ll a[n], b[n];
    rep(i, 0, n){
        cin >> a[i] >> b[i];
    }

    ll dp[10001];
    rep(i, 1, 10001){
        dp[i] = 1000000000;
    }
    dp[0] = 0;

    ll mi = 1000000000;
    rep(i, 0, h + 1){
        rep(j, 0, n){
            if(i + a[j] >= h){
                mi = min(mi, dp[i] + b[j]);
            }else{
                dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
            }
        }
    }

    cout << mi << endl;
    return 0;
}


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

int main(){
	int cards[4][13] = {};

	char suit;
	int num;
	int n;

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> suit >> num;
		if (suit == 'S') cards[0][num-1] = 1;
		else if (suit == 'H') cards[1][num-1] = 1;
		else if (suit == 'C') cards[2][num-1] = 1;
		else if (suit == 'D') cards[3][num-1] = 1;
	}

	for (int j = 0; j < 4; j++){
		for (int h = 0; h < 13; h++){
			if (cards[j][h] == 0){
				if (j == 0) cout << "S";
				if (j == 1) cout << "H";
				if (j == 2) cout << "C";
				if (j == 3) cout << "D";
				cout << " " << h + 1 << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3028
#include	<bits/stdc++.h>
using	namespace	std;
typedef	long long ll;

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N;
	string A, B, C;
	cin >>N >>A >>B >>C;
	int S=0;
	Rep0(i, N) {
		char a=A.at(i);
		char b=B.at(i);
		char c=C.at(i);
		if (a==b) {
			if (b==c)
				continue;
			S++;
		} else {
			S++;
			if (a==c)
				continue;
			if (b==c)
				continue;
			S++;
		}
	}
	cout <<S <<endl;
	return 0;
}



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

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

    long long n, k;
    cin >> n >> k;
    long long x[n];
    long long sum[n+1] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
        sum[i+1] = sum[i] + x[i];
    }
    long long ans=9e18;
    for(int i=1;i<=n;i++){
        long long ret = i * k;
        long long cnt=3;
        
        //cerr << ret << endl;
        for(int j = n; j >= 0; j-=i){
            ret += (sum[j] - sum[max(0, j - i)]) * max(5LL, cnt);
            if(ret >= ans) break;
            //cerr << (sum[j] - sum[j - 2 * i]) << endl;
            cnt+=2;;
        }
        
        ans = min(ans, ret);
        //cerr << i << " " << ans << " " << ret << endl;
    }
    ans += n * k;
    cout << ans << endl;
    
    
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 1000000000000
#define MAX 1000000000000000000
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

    vector<int> V[110000];


ll bfs(int s,ll d[]){
    queue<int> q;
    d[s]=0;
    q.push(s);
    while(!q.empty()){
        int x=q.front(); q.pop();
        for(int i=0;i<(int)V[x].size();i++){
            int nx=V[x][i];
            if(d[nx]!=-1) continue;
            d[nx]=d[x]+1;
            q.push(nx);
        }
    }
}

int main(){
    int N;
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    ll ds[110000],df[110000];
    for(int i=0;i<110000;i++){
        ds[i]=-1;
        df[i]=-1;
    }
    bfs(1,df);
    bfs(N,ds);
    int countf=0,counts=0;
    for(int i=1;i<=N;i++){
        if(df[i]<=ds[i]) countf++;
        else counts++;
    }
    if(countf>counts){
        cout<<"Fennec"<<endl;
    }else cout<<"Snuke"<<endl;
}

Measured memory_bytes: 7808
import java.util.*

fun main(args: Array<String>) {
    abc088d()
}

private data class Coordinate(val y: Int, val x: Int, val beforeCost: Int)

private const val INF = Int.MAX_VALUE / 3

fun abc088d() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val sList = (1..h).map { readLine()!!.map { it == '.' }.toBooleanArray() }.toTypedArray()

    val visited = Array(h) { BooleanArray(w) { false } }
    val minCosts = Array(h) { IntArray(w) { INF } }

    val queue = ArrayDeque(listOf(listOf(Coordinate(0, 0, 0))))
    while (queue.isNotEmpty()) {
        val coordinates = queue.poll()
        for (c in coordinates) {
            val currCost = c.beforeCost + 1
            if (c.y in 0 until h && c.x in 0 until w && sList[c.y][c.x] && !visited[c.y][c.x]) {
                visited[c.y][c.x] = true
                minCosts[c.y][c.x] = Math.min(minCosts[c.y][c.x], currCost)
                queue.add(
                    listOf(
                        Coordinate(c.y + 1, c.x, currCost),
                        Coordinate(c.y - 1, c.x, currCost),
                        Coordinate(c.y, c.x + 1, currCost),
                        Coordinate(c.y, c.x - 1, currCost)
                    )
                )
            }
        }
    }

    val goalCost = minCosts.last().last()
    if (goalCost == INF) return println(-1)

    val roadCount = sList.sumBy { booleans -> booleans.count { it } }
    val answer = roadCount - goalCost

    println(answer)
}


Measured memory_bytes: 38516
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> >g(n + 3);
    vector<int>vis(n + 3, 0);
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = 0;
    queue<int>q;
    for(int i = 1; i <= n; i++){
        if(vis[i] == 0){
            int cnt = 1;
            vis[i] = 1;
            q.push(i);
            while(!q.empty()){
                int u = q.front();
                q.pop();
                for(int j = 0; j < g[u].size(); j++){
                    int v = g[u][j];
                    if(vis[v] == 0){
                        vis[v] = 1;
                        q.push(v);
                        cnt++;
                    }
                }
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 15424
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  string s;
  cin >> s;
 
  if(s == "AAA" || s== "BBB") cout<<"No"<<endl;
  
  else cout<<"Yes"<<endl;
 
  //cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,j,k,l,m,n;
  cin>>n;
  if(n%9==0)
  {
    if(n/9<=9)
    {
      cout<<"Yes";
      return 0;
    }
  }
    else if(n%8==0)
      {
        if(n/8<=9)
        {
           cout<<"Yes";
          return 0;
        }
    }
        else if(n%7==0)
      {
        if(n/7<=9)
        {
cout<<"Yes";
          return 0;
        }
        }
        else if(n%6==0)
      {
        if(n/6<=9)
        {
          cout<<"Yes";
          return 0;
        }
        }
        else if(n%5==0)
      {
        if(n/5<=9)
        {
          cout<<"Yes";
          return 0;
        }
        }
        else if(n%4==0)
      {
        if(n/4<=9)
        {
          cout<<"Yes";
     return 0;
        }
        }
        else if(n%3==0)
      {
        if(n/3<=9)
        {
          cout<<"Yes";
          return 0;
        }
        }
        else if(n%2==0)
      {
        if(n/2<=9)
        {
          cout<<"Yes";
          return 0;
        }
        }
  else if(n==1)
  {
    cout<<"Yes";
    return 0;
  }
  cout<<"No";
}


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

namespace ConsoleApplication1
{
    class Program
    {
        struct ItemInfo
        {
            internal int value, weight;
        }

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int weightLimit = int.Parse(input[1]);

            ItemInfo[] itemList = new ItemInfo[n];

            for (int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ');
                itemList[i].value = int.Parse(input[0]);
                itemList[i].weight = int.Parse(input[1]);
            }

            Nullable<int>[] dp = new Nullable<int>[weightLimit + 1];
            dp[0] = 0;

            foreach (var item in itemList)
            {
                for (int i = weightLimit; i >= 0; i--)
                {
                    int sumWeight = i + item.weight;

                    if (sumWeight > weightLimit) continue;

                    if (dp[i] == null) continue;
                    int sumValue = dp[i].Value + item.value;

                    if (dp[sumWeight] == null || dp[sumWeight] < sumValue)
                    {
                        dp[sumWeight] = sumValue;
                    }
                }
            }

            Console.WriteLine(dp.Max());
        }
    }
}

Measured memory_bytes: 9624