akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {string: String};
    println!("{}", solve(string));
}

fn solve(mut string: String) -> String {
    while string.len() > 0 {
        let before_processing = string.len();

        string = string.replace(string.chars().next().unwrap(), "");
        let after_processing = string.len();

        if (before_processing - after_processing) % 2 != 0{
            return "No".to_string()
        }
    }

    "Yes".to_string()
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> used(n+1,0);
	vector<int> ans(m);
	
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		ans[i]=a;
		used[a]=1;
	}
	
	vector<int> syu(n+1,0);
	
	for(int i=0;i<m;i++){
		if(syu[ans[m-i-1]]!=1){
			cout<<ans[m-i-1]<<endl;
			syu[ans[m-i-1]]=1;
		}
	}
	
	for(int i=1;i<n+1;i++){
		if(used[i]==0)cout<<i<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int mod=1e9+7;
void add(int& x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
int main(){
	while(true){
		string a,b,c;
		cin>>a;
		if(a[0]=='0') break;
		cin>>b>>c;
		int N=a.size();
		int x=1,y=0;	//kuriagari 0, 1
		for(int i=N-1;i>=0;i--){
			int nx=0,ny=0;
			rep(j,10){
				if( (a[i]!='?'&&a[i]!='0'+j) || (i==0&&j==0) ) continue;
				rep(k,10){
					if( (b[i]!='?'&&b[i]!='0'+k) || (i==0&&k==0) ) continue;
					{
						int l=j+k;
						if(c[i]!='?'&&c[i]!='0'+(l%10)) ;
						else{
							if(l>=10) add(ny,x);
							else add(nx,x);
						}
					}
					{
						int l=j+k+1;
						if(c[i]!='?'&&c[i]!='0'+(l%10)) ;
						else{
							if(l>=10) add(ny,y);
							else add(nx,y);
						}
					}
				}
			}
			x=nx,y=ny;
		}
		cout<<x<<endl;
	}
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> a(N);
  for(int i=0; i<N; i++){
    a[i].first=1;  
  }
  a[0].second=1;
  for(int i=0; i<M; i++){
    int x, y;
    cin >> x >> y;
    a[x-1].first--; a[y-1].first++;
    if(a[x-1].second==1){
      if(a[x-1].first==0){
        a[x-1].second=0; a[y-1].second=1;
      }
      else if(a[x-1].second>0){
        a[y-1].second=1;
      }
    }
  }
  int ans=0;
  for(int i=0; i<N; i++){
    ans+=a[i].second;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#define ll long long
//#define INF LONG_MAX
using namespace std;

int main() {
  string S;
  cin >> S;
  string jug = "No";
  if (S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') {
    jug = "Yes";
  }
  cout << jug << endl;
  return 0;
}


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

s = 0
for i in range(n):
    s += l+(i+1)-1

cur = 10**18
temp = 0
for i in range(n):
    temp = s - (l+(i+1)-1)
    if abs(temp-s) <= cur:
        ans = temp
        cur = abs(temp-s)
#print(s)
print(ans)


Measured memory_bytes: 38384
n,k = map(int,input().split())
a=[0]*(n+1)
b=[0]*n

ans = 0

for i in range(k):
    d=int(input())
    b = list(map(int, input().split()))
    for h in range(d):
        a[b[h]]+=1

for i in range(1,n+1):
    if a[i] == 0:
        ans +=1

print(str(ans))

Measured memory_bytes: 67444
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}

#define P pair<int,int>
bool G[30000];
vector<pair<int,P> >ta;
int main(){
	int n,m;
while(true){
	cin>>n>>m;
	if(n==0&&m==0)break;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
ta.push_back(pair<int,P>(a,P(b,c)));
}
sort(ta.begin(),ta.end());
G[1]=1;
for(int i=0;i<m;i++){
	int a=ta[i].first,b=ta[i].second.first,c=ta[i].second.second;
	if(G[b]==1)G[c]=1;
}
int ans=0;
for(int i=0;i<=n;i++)if(G[i])ans++;
cout<<ans<<endl;
fill(G,G+30000,0);
ta.clear();
}
return 0;
}

Measured memory_bytes: 1712
/*
Author: Xjrjyy
LANG: C++
PROG: agc041_a.cpp
Mail: admin@xjrjyy.com
Blog: https://blog.xjrjyy.cn/
*/

#include <cstdio>
#include <cctype>
#include <vector>
#include <iostream>

#define MAXN ()

long long n, a, b;

long long abs(long long x) { return x >= 0 ? x : -x; }

int main()
{
    scanf("%lld%lld%lld", &n, &a, &b);
    if (abs(a - b) & 1)
    {
        long long ta = std::min(a - 1, n - a);
        long long tb = std::min(b - 1, n - b);
        printf("%lld\n", (abs(a - b) >> 1) + std::min(ta, tb) + 1);
    }
    else
    {
        printf("%lld\n", abs(a - b) >> 1);
    }
    return 0;
}


Measured memory_bytes: 3828
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])
T = sum(t)

cnt = 0
l, r = 0, 0
while l < n:
    b = 0
    while r < n and b + 1 <= c and t[r] - t[l] <= k:
        b += 1
        r += 1
    l = r
    cnt += 1
print(cnt)

Measured memory_bytes: 8252
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

int r,s,p,n,k;

string x,ans;

int main()
{
    cin >> n >> k;
    cin >> r >> s >> p >> x;
    for (int i=0;i<n;i++)
    {
        if (x[i]=='r')ans+="p";
        if (x[i]=='s')ans+="r";
        if (x[i]=='p')ans+="s";
    }
    string alpha="rsp";
    for (int i=k;i<n;i++)
    {
        if (ans[i]==ans[i-k])
        {
            int ind=0;
            while(ind<alpha.length())
            {
                ans[i]=alpha[ind++];
                if (i+k<n&&ans[i]!=ans[i-k]&&ans[i]!=ans[i+k])break;
                if (ans[i-k]!=ans[i]&&i+k>=n)break;
            }
        }
    }
    int tot=0;
    for (int i=0;i<n;i++)
    {
        if (ans[i]=='r'&&x[i]=='s')tot+=r;
        if (ans[i]=='s'&&x[i]=='p')tot+=s;
        if (ans[i]=='p'&&x[i]=='r')tot+=p;
    }
    cout << tot << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node {
  int p;
  int l;
  int r;
};

struct Node T[MAX];
int n;

void pre(int u){
  if(u == NIL) return;
  printf(" %d", u);
  pre(T[u].l);
  pre(T[u].r);
}

void in(int u){
  if(u == NIL)return;
  in(T[u].l);
  printf(" %d", u);
  in(T[u].r);
}

void pos(int u){
  if(u == NIL) return;
  pos(T[u].l);
  pos(T[u].r);
  printf(" %d", u);
}
int main(){
  int i;
  int v,l,r, root;

  scanf("%d", &n);

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

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

  for(i=0; i<n; i++){
    if(T[i].p == NIL) root = i;
  }
  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  pos(root);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2056
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

bool cards[100000];

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (!(n || k)) return 0;
    fill(cards, cards+n, false);
    bool have_zero = false;
    for (int i = 0; i < k; i++) {
      int j;
      cin >> j;
      if (j)
        cards[j-1] = true;
      else
        have_zero = true;
    }
    int count = 0;
    vector<pair<int, int> > sequences;
    for (int i = 0; i < n; i++)
      if (cards[i])
        count++;
      else if (count) {
        sequences.push_back(make_pair(i-count, count));
        count = 0;
      }
    if (count)
      sequences.push_back(make_pair(n-count, count));
    int maxv = 0;
    if (have_zero) {
      maxv = min(sequences[0].second + 1, n);
      for (vector<pair<int, int> >::iterator a = sequences.begin(), b = a + 1;
           b != sequences.end() && maxv != n ; ++a, ++b)
        if (a->first + a->second + 1 == b->first)
          maxv = max(maxv, a->second + b->second + 1);
        else
          maxv = max(maxv, b->second + 1);
    } else
      for (int i = 0; i < sequences.size(); i++)
        maxv = max(maxv, sequences[i].second);
    cout << maxv << endl;
  }
}

Measured memory_bytes: 1004
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import Data.Char
import Data.List

a#b = abs$a-b

main = B.interact$B.pack.show.f.UV.unfoldr(B.readInt.B.dropWhile isSpace)
f :: UV.Vector Int -> Int
f v= q n hv
  where
    n = v UV.! 0
    hv = UV.slice 1 n v
q n hv = av V.! (n - 1)
  where
    av = V.generate n m
    m 0 = 0
    m 1 = (hv UV.! 0) # (hv UV.! 1)
    m i = min ((av V.! (i-2)) + ((hv UV.! (i-2)) # (hv UV.! i))) ((av V.! (i-1)) + ((hv UV.! (i-1)) # (hv UV.! i)))


Measured memory_bytes: 17788
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int64_t S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 200000;
int ai[N], bi[N], as[N], bs[N];
int vis[N], cc[N];
vector <int> bb[N];
int ans;
void dfs(int t)
{
    vis[t] = 1;
    for (int i = 0; i < bb[t].size(); ++ i)
        if (!vis[bb[t][i]]) dfs(bb[t][i]);
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i)
    {
        scanf("%d", &ai[i]);
        ai[0] ^= ai[i];
    }
    for (int i = 1; i <= n; ++ i)
    {
        scanf("%d", &bi[i]);
        bi[0] ^= bi[i];
    }
    for (int i = 0; i <= n; ++ i)
        as[i] = ai[i], bs[i] = bi[i];
    sort(as, as + n + 1);
    sort(bs, bs + n + 1);
    for (int i = 0; i <= n; ++ i)
        if (as[i] != bs[i]) {puts("-1"); return 0;}
    for (int i = 0; i <= n; ++ i)
        ai[i] = lower_bound(as, as + n + 1, ai[i]) - as,
        bi[i] = lower_bound(bs, bs + n + 1, bi[i]) - bs;
    for (int i = 0; i <= n; ++ i)
        if (ai[i] != bi[i] || i == 0)
        {
            if (i) ans ++;
            cc[ai[i]] ++; cc[bi[i]] ++;
            bb[ai[i]].push_back(bi[i]);
            bb[bi[i]].push_back(ai[i]);
        }
    for (int i = 0; i <= n; ++ i)
        if (!vis[i] && cc[i])
            dfs(i), ans ++;
    ans --;
    ans = max(ans, 0);
    printf("%d\n", ans);
}


Measured memory_bytes: 15104
def permu(n,r,p):
    result = 1
    for i in range(n,n-r,-1):
        result *= i
        result %= p
    return result

from collections import deque

n,k = map(int,input().split())
mod = 10**9 + 7
G = [[] for i in range(n)]
for i in range(n-1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

ans = k
s = True
que = deque([[-1,0]])
while que:
    pre,now = que.pop()

    if s:
        s = False
        ans *= permu(k-1,len(G[0]),mod)
        for nex in G[0]:
            que.append([0,nex])

    else:
        ans *= permu(k-2,len(G[now])-1,mod)
        for nex in G[now]:
            if nex == pre:continue
            que.append([now,nex])
    ans %= mod

print(ans)

Measured memory_bytes: 32536
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N;
int A[18], B[18];
unsigned char dp[36][1 << 18];
int keisan(int b, bool n, int k) {
	if (dp[k][b] != 255) return dp[k][b];
	if (b == (1 << N) - 1) return 0;

	int saishou = 254;
	int num2 = 0;
	rep(i, N) {
		if (!(b >> i & 1)) {
			if (A[i] < k && B[i] < k) return dp[k][b] = 254;
			if ((n + i) & 1) {
				if (B[i] >= k) {
					chmin(saishou, keisan(b + (1 << i), !n, B[i]) + num2);
				}
			}
			else {
				if (A[i] >= k) {
					chmin(saishou, keisan(b + (1 << i), !n, A[i]) + num2);
				}
			}
			num2++;
		}
	}
	return dp[k][b] = saishou;
}

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


	scanf("%d", &N);
	rep(i, N) scanf("%d", A + i);
	rep(i, N) scanf("%d", B + i);

	pair<int, int> kari[36];
	rep(i, N) kari[i] = mp(A[i], i);
	rep(i, N) kari[i + N] = mp(B[i], i + N);
	sort(kari, kari + N * 2);
	int k = 0;
	int mae = kari[0].first;
	rep(i, N * 2) {
		if (mae != kari[i].first) k++;
		mae = kari[i].first;
		if (kari[i].second < N) A[kari[i].second] = k;
		else B[kari[i].second - N] = k;
	}

	if (k == 0) {
		printf("0\n");
		return 0;
	}

	rep(i, k + 1) rep(j, 1 << N) dp[i][j] = 255;

	int kotae = keisan(0, 0, 0);
	if (kotae == 254) printf("-1\n");
	else printf("%d\n", kotae);

	Would you please return 0;
}

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

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);
    
    string s,t ;
    cin >> s >> t;
    int res = 0;
    for (int i = 0; i < 3; i++){
        if (s[i] == t[i]) res++;
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//�]���؂�グ�� =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
  b*=2;
  if(a<b){
    cout<<0;
  }
  else cout<<a-b;
	
	return 0;
}

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(int)n;i++)

int tr_2d[5002][5002];

map<int,int> zip_x,zip_y;
int unzip_x[5000],unzip_y[5000];



pair<int,int> compress(vector<int> &x, vector<int> &y){
// zipで座標->index
// unzipでindex->座標
// x,yは書き換えられるので注意
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(),x.end()),x.end());
  y.erase(unique(y.begin(),y.end()),y.end());
  rep(i,x.size()){
    zip_x[x[i]] = i;
    unzip_x[i] = x[i];
  }
  rep(i,y.size()){
    zip_y[y[i]] = i;
    unzip_y[i] = y[i];
  }
  return make_pair(x.size(),y.size());
}

void Imos2D(int n){
  rep(i,n+1)rep(j,n)tr_2d[i][j+1]+=tr_2d[i][j];
  rep(i,n)rep(j,n+1)tr_2d[i+1][j]+=tr_2d[i][j];
}

int sum(int xl,int xr,int yd,int yu){
  return tr_2d[xr][yu]-tr_2d[xl][yu]+tr_2d[xl][yd]-tr_2d[xr][yd];
}

signed main(){

  int n,m;
  cin>>n>>m;
  vector<int> tr_x(n),tr_x2(n),tr_y(n),tr_y2(n);
  rep(i,n+2){
    rep(j,n+2){
      tr_2d[i][j]=0;
    }
  }

  rep(i,n){
    int x,y;
    cin>>x>>y;
    tr_x[i] = x;
    tr_x2[i] = x;
    tr_y[i] = y;
    tr_y2[i] = y;
  }
  //座圧
  pair<int,int> size=compress(tr_x2,tr_y2);
  // cout<<size.first<<size.second<<endl;
  rep(i,n){
    int id_x = zip_x[tr_x[i]];
    int id_y = zip_y[tr_y[i]];
    tr_2d[id_x+1][id_y+1]++;
  }
  // rep(i,n){
  //   rep(j,n-1){
  //     cout<<tr_2d[i][j]<<" ";
  //   }
  //   cout<<tr_2d[i][n-1]<<endl;
  // }

  //2次元累積和
  Imos2D(n);
  // rep(i,n+1){
  //   rep(j,n){
  //     cout<<s[i][j]<<" ";
  //   }
  //   cout<<s[i][n]<<endl;
  // }

  rep(i,m){
    int xl,xr,yd,yu;
    cin>>xl>>yd>>xr>>yu;
    auto ixl = lower_bound(unzip_x,unzip_x+size.first,xl)-unzip_x;
    auto ixr = upper_bound(unzip_x,unzip_x+size.first,xr)-unzip_x-1;
    auto iyd = lower_bound(unzip_y,unzip_y+size.second,yd)-unzip_y;
    auto iyu = upper_bound(unzip_y,unzip_y+size.second,yu)-unzip_y-1;
    // cout << xl<<" "<<xr<<" : "<<ixl<< " " <<ixr<<endl;
    // cout << yd<<" "<<yu<<" : "<<iyd<< " " <<iyu<<endl;
    cout << sum(ixl,ixr+1,iyd,iyu+1)<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 199444
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;

ll gcd(ll a,ll b) { 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
bool isPrime(ll n){ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

ll c[1000000],idx;
int main(){
	ll a,b;
	cin >> a>>b;
	ll n=gcd(a,b);
	for(ll i=1; i*i<=n; i++){
		if(n%i==0){
			c[idx++]=i;
			if(n/i!=i) c[idx++]=n/i;
		}
	}
	sort(c,c+idx);
	for(ll i=0; i<idx; i++){
		if(isPrime(c[i])==true) ans++;	
	}
	cout<<ans+1<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.next());
        int k = Integer.parseInt(s.next());

        int count = 1;


        for(int i=1;i<n;){
            i = i * k;

            if(n/i >= 1){
            count++;

            }
        }

        System.out.println(count);

        
        }

}


Measured memory_bytes: 23764
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vector<P> v(n);
    rep(i, n) {
        int a,b;cin >> a >> b;
        v[i].second=a-b,v[i].first=a+b;
    }
    sort(all(v));
    int count = 0;
    // for(auto p:v) cout << p.first << ' ' << p.second << endl;
    int k=v[0].first;
    rep1(i, n-1) {
        if(k>v[i].second) count++;
        else k=v[i].first;
    }
    cout << n-count << endl;
    return 0;
}

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

const int MAX_V=101010;
int V,E;

int par[MAX_V]; //　親
int rnk[MAX_V]; // rank, 木の深さ

// V要素で初期化
void init(){
  for(int i=0;i<V;i++){
    par[i]=i;
    rnk[i]=0;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

// ｘとｙの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

// ｘとｙが同じ集合に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

int P[101010];

int main(){
  cin>>V>>E;
  init();
  rep(i,V){
    cin>>P[i]; P[i]--;
  }
  rep(i,E){
    int x,y; cin>>x>>y; x--,y--;
    unite(x,y);
  }
  int ans=0;
  rep(i,V){
    if(P[i]==i) ans++;
    else{
      if(same(P[i],i)) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define scale 1000000007

int main(){
    long long n,k,ans;
    long long temp;
  ans = 0;
    cin >> n >> k;
    for(long long i = k; i < n+2; i++){
        temp = (i * n + i - i * i +1 ) % scale;
        ans += temp;
      ans = ans % scale;
    }
  //ans = ans % scale;
    cout << ans << endl;
}

Measured memory_bytes: 3620
s = input()
c0 = 0
c1 = 0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] != '0':
      c0 += 1
    if s[i] != '1':
      c1 += 1
  else:
    if s[i] != '1':
      c0 += 1
    if s[i] != '0':
      c1 += 1
print(min(c0, c1))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sorted(a) sort(a.begin(),a.end())
#define rsorted(a) sort(a.rbegin(),a.rend())
#define test(val) cout<<val<<endl;
#define test1(val) cout<<val<<" ";

struct node{
    ll cost;
    ll arr[20];
};

ll required_level;
ll min_cost = INT_MAX;
void backtrack(node books[], int start, vector<ll>level,int n, int m, ll current_cost){
    if(start>=n)
    return;

    for(int i=start;i<n;i++){

        current_cost+=books[i].cost;
        for(int j=0;j<m;j++)
         level[j]+=books[i].arr[j];

        int f=0;
        for(int k=0;k<m;k++){
            if(level[k]<required_level){
                f=1;
                break;
            }
        }
        if(f==0)
        min_cost = min(min_cost,current_cost);
        backtrack(books,i+1,level,n,m,current_cost);
        for(int j=0;j<m;j++) 
        level[j]-=books[i].arr[j];
        current_cost-=books[i].cost;
    }
    return;
}

void solve(){
    int n,m,x;
    cin>>n>>m>>x;
    required_level=x;
    node books[n+1];
    vector<ll>level(m+1,0);
    for(int i=0;i<n;i++){
        cin>>books[i].cost;
        for(int j=0;j<m;j++)
            cin>>books[i].arr[j];
    }
    backtrack(books,0,level,n,m,0ll);
    if(min_cost==INT_MAX)
        cout<<-1<<endl;
    else
    cout<<min_cost<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }

return 0;
}

Measured memory_bytes: 3664
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>

#pragma GCC optimize("O3")

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

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i <= ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i >= ll(b); --i)
#define loop while(true)
#define asort(array, size) std::sort(array, array + size)
#define cauto const auto&
#define bit(n) (1LL << (n))

int main()
{
    int N, D;
    int count = 0;
    cin >> N >> D;
    rep(i, N) {
        ull X, Y;
        cin >> X >> Y;
        if (abs(sqrt((X * X) + (Y * Y))) <= D) ++count;
    }
    cout << count << endl;
    return 0;
}


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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        int[][] num = new int[10][10];
        for (int i = 1; i <= n; i++) {
            String str = String.valueOf(i);
            int largest = Integer.parseInt(String.valueOf(str.charAt(str.length() - 1)));
            int lowest = Integer.parseInt(String.valueOf(str.charAt(0)));
            num[largest][lowest]++;
        }

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            String str = String.valueOf(i);
            int largest = Integer.parseInt(String.valueOf(str.charAt(str.length() - 1)));
            int lowest = Integer.parseInt(String.valueOf(str.charAt(0)));
            ans += num[lowest][largest];
        }

        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        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: 56304
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

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

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

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

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

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

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


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string s;
	LL n;
	cin >> n >> s;
	LL len = s.size();

	vll dp1(n + 2), dp2(n + 2);
	dp1[0] = 1;
	for(int i = 1; i <= n; ++i){
		fill(ALL(dp2), 0LL);
		for(int j = 0; j <= n; ++j){
			LL &r = dp2[j];
			r += dp1[max(j - 1, 0)];
			r += dp1[j + 1] * 2;
			r %= MOD;
		}
		dp1.swap(dp2);
	}

	cout << dp1[len] << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int dp[21][50001];
int m, n;
int c[21];

void solve(){
    for(int i=1; i<=n; i++){
        dp[0][i]=i;
    }
    for(int i=1; i<m; i++){
        dp[i][0]=0;
    }
    for(int i=1; i<m;i++){
        for(int j=1; j<=n; j++){
            if(c[i]<=j){
                dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[m-1][n] << endl;
}

int main(){
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> c[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 5252
def cycle_getter(N, start):
    """
    :param N: 移動回数
    :param start:　初期条件
    :return front: cycleまでの要素のリスト
            cycle: cycle内の要素のリスト
            end: cycle後の余った部分の要素のリスト
            cnt: cycle回数
    """
    p = start
    front, cycle, end = [], [], []
    cnt = 0
    visit = {p:0}
    L, R = N, -1
    P = [p]
    for i in range(1,N):
        p = lift(p)
        if p in visit:
            """
            (L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
            [6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
            """
            L, R = visit[p], i
            period = R-L
            break
        visit[p] = i
        P.append(p)
    front = P[:L]
    if L != N:
        cycle, end = P[L:R], P[L:L+(N-L)%period]
        cnt = (N-L)//period
    return front, cycle, end, cnt

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


import sys
input = sys.stdin.readline
from itertools import accumulate

def lift(x): return P[x-1]

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
res = -float("inf")
for i in range(1,N+1):
    front, cycle, end, cnt = cycle_getter(K,i)
    S = sum(C[j-1] for j in front)
    T = sum(C[j-1] for j in cycle)
    if cycle+end:
        U = max(0, max(accumulate(C[j-1] for j in cycle+end)))
    else: U=0
    if front:
        R = max(accumulate(C[j-1] for j in front))
    else: R=0
    res = max(res, S+T*(cnt-1)+U, S+U, R)
print(res)

Measured memory_bytes: 220028
while True:
  try:
    data = raw_input()
  except EOFError:
    break

  a,b,c,d,e,f = map(float, data.split())

  x = ( b*f - e*c ) / ( b*d - a*e )

  y = ( c*d - a*f ) / ( b*d - a*e )

  if x == -0.0:
    x = 0

  if y == -0.0:
    y = 0

  print "%.3f %.3f" % ( round(x,3), round(y,3) )

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n,p; cin>>n>>p;
  vector<ll> a(n);
  rep(i, n) cin>>a[i];

  ll e = 0;
  ll o = 0;
  rep(i, n) {
    if (a[i]&1) o++;
    else e++;
  }

  if (o == 0) {
    if (p == 0) cout << (ll)pow(2, n) << endl;
    else cout << 0 << endl;
  } else {
    cout << (ll)pow(2, n-1) << endl;
  }

  return 0;
}


Measured memory_bytes: 4052
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


#include <set>
void solve() {
  int n, m, x, a;
  cin >> n >> m >> x;
  set<int> A;
  loop(i,0,m) { cin >> a; A.insert(a); }
  int cost1 = 0;
  loop(i,0,x+1) cost1 += A.count(i);
  int cost2 = 0;
  loop(i,x, n+1) cost2 += A.count(i);
  cout << min(cost1, cost2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,D;
  cin >> N >> D;
  vector<ll> X(N),Y(N);
  rep(i,N)  cin >> X.at(i) >> Y.at(i);

  two_sat ts(2*N);
  rep(i,N){
    ts.add_clause(i, true, i+N, true);
    ts.add_clause(i, false, i+N, false);
  }
  rep(i,N){
    REP(j,i+1,N){
      if(abs(X.at(i)-X.at(j)) < D)  ts.add_clause(i, false, j, false);
      if(abs(X.at(i)-Y.at(j)) < D)  ts.add_clause(i, false, j+N, false);
      if(abs(Y.at(i)-X.at(j)) < D)  ts.add_clause(i+N, false, j, false);
      if(abs(Y.at(i)-Y.at(j)) < D)  ts.add_clause(i+N, false, j+N, false);
    }
  }

  if(!ts.satisfiable()){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;

  vector<bool> ans = ts.answer();
  rep(i,N){
    if(ans.at(i)) cout << X.at(i) << endl;
    else  cout << Y.at(i) << endl;
  }

  return 0;
}

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

int main ()
{
	string s;
	for (int i = 1;i <= 6;i++)
	{
		cin >> s[i];
	}
	if (s[3] == s[4] && s[5] == s[6])
	{
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

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

int main(){
    int a,b,n,lower,upper,ans=0;
    cin >> n;
    vector<int> l(n);
    rep(i,0,n-1)cin >> l[i];

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

    rep(i,0,n-1){
        rep(j,i,n-1){
            a = l[i];
            b = l[j];
            if(i<j){
                lower = b-a;
                upper = a+b;
              //  auto li = upper_bound(l.begin(),l.end(),lower);
                auto ui = lower_bound(l.begin(),l.end(),upper);
               // if(a+b==)
               
                if((ui-l.begin()-1)<=j)continue;
               // cout << i <<" "<<j<<" "<<ui-l.begin() << " " <<ui-l.begin()-j<<endl;
                ans += ui - l.begin() -j-1;
                //if(ui==l.end())--ans;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  ll D;
  cin >> N >> D;
  int ans = 0;
  rep(i,N) {
    ll x,y;
    cin >> x >> y;
    if ( x*x + y*y <= D*D ) {
      ans++; 
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3556
import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())

def main():
    N, K = geta(int)
    h = geta(int)

    INF = 1 << 60
    dp = [INF]*N
    dp[0], dp[1] = 0, abs(h[0] - h[1])

    for i in range(2, N):
        lb = i - K if i > K else 0
        for j in range(lb, i):
            tmp = dp[j] + abs(h[j] - h[i])
            if tmp < dp[i]:
                dp[i] = tmp

    print(dp[N - 1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 52464
#include"bits/stdc++.h"
using namespace std;

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    long long tartget = a.back();

    long long ans = -1;

    for (int i = 0; i < n - 1; i++) {
        auto tmp = (a[i] > tartget / 2 ? tartget - a[i] : a[i]);

        if (tmp > ans) {
            ans = a[i];
        }
    }


    cout << tartget << " " << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    if(n>=2&&m>=2)
        cout<<((n*(n-1))/2)+((m*(m-1))/2);
    else if(n>=2&&m<2)
        cout<<((n*(n-1))/2);
    else if(n<2&&m>=2)
        cout<<((m*(m-1))/2);
    else
        cout<<0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<vector<int>>A(10,vector<int>(10));
  for(int i=1;i<=N;i++){
    string S=to_string(i);
    A[S.at(0)-48][S.at(S.size()-1)-48]++;
  }
  long long ans=0;
  for(int i=1;i<10;i++)for(int j=1;j<10;j++)ans+=A[i][j]*A[j][i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3696
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<ll> A;
#define ivt(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
    //    //freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    cin>>testcase;
    ll a=0,b=0,c=0,d=0;
    while(testcase--)
    {
        string s;
        cin>>s;
        
        if(s=="AC")
        {
            a++;
        }
        if(s=="WA")
        {
            b++;
        }
        if(s=="TLE")
        {
            c++;
        }
        if(s=="RE")
        {
            d++;
        }
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
    return 0;
}

Measured memory_bytes: 3660
import queue

def step(q, dist, i, j, ni, nj):
    if ni < 0 or ni >= h or nj < 0 or nj >= w: return q
    if dist[ni][nj] == -1:
        q.put((ni, nj))
        dist[ni][nj] = dist[i][j] + 1
    return q


def bfs():
    q = queue.Queue()
    q.put((0, 0))
    dist = [[-1] * w for _ in range(h)]
    dist[0][0] = 1
    while True:
        i, j = q.get()

        if left[i][j] == 0:
            ni, nj = i, j-1
            q = step(q, dist, i, j, ni, nj)
        
        if right[i][j] == 0:
            ni, nj = i, j+1
            q = step(q, dist, i, j, ni, nj)
        
        if up[i][j] == 0:
            ni, nj = i-1, j
            q = step(q, dist, i, j, ni, nj)

        if down[i][j] == 0:
            ni, nj = i+1, j
            q = step(q, dist, i, j, ni, nj)
    
        if q.empty(): break

    return dist[-1][-1]


while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0: break

    # 四方の壁を保持
    left = [[1] * w for _ in range(h)]
    right = [[1] * w for _ in range(h)]
    up = [[1] * w for _ in range(h)]
    down = [[1] * w for _ in range(h)]

    up[0][0] = 0
    down[-1][-1] = 0

    for i in range(2 * h - 1):
        line = list(map(int, input().split()))
        if i % 2 == 0:
            i2 = i // 2
            for j in range(0, w-1):
                right[i2][j] = line[j]
                left[i2][j+1] = line[j]
        else:
            i2 = i // 2
            for j in range(w):
                down[i2][j] = line[j]
                up[i2+1][j] = line[j]
    
    ans = bfs()
    print(ans if ans != -1 else 0)



Measured memory_bytes: 6848
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

int dp[105][105][305];

signed main() {
	int n, mw, W;
	cin >> n >> mw;
	int w[105], v[105];
	rep(i, n) cin >> w[i] >> v[i];
	W = w[0];
	rep(i, n) w[i] -= W;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			rep(k, 3 * n + 1) {
				if (k < w[j - 1]) {
					dp[i][j][k] = dp[i][j - 1][k];
				}
				else {
					dp[i][j][k] = max(dp[i][j - 1][k], dp[i - 1][j - 1][k - w[j - 1]] + v[j - 1]);
				}
			}
		}
	}
	int ans = 0;
	rep(i, n + 1) {
		if (mw - W * i >= 0) {
			ans = max(ans, dp[i][n][min(3 * n, mw - W * i)]);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 25216
#include<iostream>
#include<vector>
#include<string>
#include<map>

template<typename T>
struct CSR{
    std::map<std::pair<int,int>,T> List;
    std::vector<T> A,IA,JA,nIA;
    int H,W;
    CSR(int H,int W):H(H),W(W){}
    CSR(const CSR &X){*this=X;}
    void add_val(int row,int col,T val){
        List[std::make_pair(row,col)] += val;
    }
    CSR Unit()const{
        CSR res(H,W);
        for(int i=0;i<H;++i){
            res.add_val(i,i,1);
        }
        res.compress();
        return res;
    }
    void compress(){
        int N=List.size();
        A.resize(N);
        IA.resize(N);
        JA.resize(N);
        int ind=0;
        for(auto L:List){
            std::pair<int,int> pos=L.first;
            A[ind]=L.second;
            IA[ind]=pos.first;
            JA[ind]=pos.second;
            ind++;
        }
        nIA.resize(H+1,List.size());
        for(int i=0,r=0;i<IA.size();++i){
            while(r<=IA[i]){
                nIA[r]=i;
                r++;
            }
        }
    }
    CSR operator*(const CSR &X)const{
        if(W!=X.H){
            std::cerr << "err Matrix::operator*" <<std::endl;
            std::cerr << "  not equal matrix size" <<std::endl;
            exit(0);
        }
        CSR res(H,X.W);
        for(int i=0;i<H;++i){
            for(int j=nIA[i];j<nIA[i+1];++j){
                int k=JA[j];
                for(int t=X.nIA[k];t<X.nIA[k+1];++t){
                    res.add_val(i,X.JA[t],A[j]*X.A[t]);
                }
            }
        }
        res.compress();
        return res;
    }
    friend std::ostream& operator<<(std::ostream &os,CSR &X){
        for(int i=0;i<X.H;++i) for(int j=0;j<X.W;++j){
            std::pair<int,int> p=std::make_pair(i,j);
            if(X.List.count(p)) os<<X.List[p];
            else os<<0;
            os<<" \n"[j+1==X.W&&i+1<X.H];
        }
        return os;
    }
};
template<typename T>
CSR<T> cpow(CSR<T> x,long long n){
    CSR<T> res(x.H,x.W);
    res=res.Unit();
    while(n){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

int main(){
    using namespace std;
    string s;cin>>s;
    CSR<long long> v(s.size(),s.size()),ans(s.size(),1);
    for(int i=0;i<s.size();++i){
        if(s[i]=='R') v.add_val(i+1,i,1);
        else v.add_val(i-1,i,1);
        ans.add_val(i,0,1);
    }
    v.compress();
    ans.compress();
    v=cpow(v,1e10);
    v=cpow(v,10);
    ans = v*ans;
    std::cout<<ans<<"\n";
}

Measured memory_bytes: 47328
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B;
    cin >> A >> B;
    
    int ans = 0;
    
    for (int i = 0; i < 2; i++){
        if (A > B){
            ans += A;
            A -= 1;
        }
        else {
            ans += B;
            B -= 1;
        }
    }
    
    cout << ans << endl;
}

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

using namespace std;
int main(){
	int x=0,n,ans=0;
	cin>>n;
	char s[n];
	cin>>s;
	for(int i=0; i<n; i++){
		if(s[i]=='I'){
			x++;
			ans = max(x,ans);
		}
		else{
			x--;
		}
		
	}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256