akhauriyash/Code-Regression huggingface dataset:
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let a = read![[i64]];

    // m = Πa - 1
    let x = (0..N).map(|i| a[i] - 1).sum::<i64>();

    println!("{}", x)
}


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

struct Kruskal {
  Kruskal() {}
  Kruskal(int n) {
    init(n);
  }

  struct UnionFind {
    vector<int> p, r;

    UnionFind() {}
    UnionFind(int size) {
      init(size);
    }

    void init(int size) {
      p.resize(size);
      r.resize(size);
      for (int i = 0; i < size; ++i) {
        p[i] = i;
        r[i] = 1;
      }
    }

    int root(int x) {
      if (p[x] == x)
        return x;
      else
        return p[x] = root(p[x]);
    }

    void unite(int x, int y) {
      x = root(x);
      y = root(y);

      if (x == y) return;

      if (r[x] > r[y]) swap(x, y);
      r[x] += r[y];
      p[y] = x;
    }

    bool same(int x, int y) {
      return root(x) == root(y);
    }
  };

  struct edges {
    edges() {}
    edges(int u, int v, long long cost) : u(u), v(v), cost(cost) {}
    bool operator<(const edges &e) const {
      return cost < e.cost;
    }

    int u, v;
    long long cost;
  };

  struct edge {
    edge() {}
    edge(int to, long long cost) : to(to), cost(cost) {}

    int to;
    long long cost;
  };

  vector<edges> E;
  vector<vector<edge>> G;

  void init(int n) {
    G.resize(n + 1);
  }

  void add_edge(int u, int v, long long cost) {
    E.push_back(edges(u, v, cost));
  }

  void make_graph(edges e) {
    G[e.u].push_back(edge(e.v, e.cost));
    G[e.v].push_back(edge(e.u, e.cost));
  }

  long long kruskal(int n) {
    long long res = 0;
    UnionFind uf(n + 1);

    sort(E.begin(), E.end());
    for (auto &e : E) {
      if (!uf.same(e.u, e.v)) {
        res += e.cost;
        uf.unite(e.u, e.v);
        make_graph(e);
      }
    }

    return res;
  }

  long long kruskal() {
    return kruskal(G.size());
  }
};

int main() {
  int n;

  while (cin >> n, n) {
    Kruskal G(n);

    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
      int a, b, c;
      scanf("%d,%d,%d", &a, &b, &c);

      G.add_edge(a, b, c / 100 - 1);
    }

    cout << G.kruskal() << endl;
  }
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


const int MAX_N = 710;
bool d[MAX_N][MAX_N];

ll calc(int n) {
    vector<vector<int>> es(n);
    vector<int> color(n, -1);
    rep(i, n) rep(j, n) if(!d[i][j]) es[i].pb(j);
    using P = pair<int, int>;
    vector<P> v;
    rep(i, n) {
        if(color[i] != -1) continue;
        vector<int> cnt(2);
        color[i] = 0;
        cnt[0]++;
        queue<int> q;
        q.push(i);
        while(!q.empty()) {
            int p = q.front();
            q.pop();
            for(auto& to : es[p]) {
                if(color[to] == -1) {
                    color[to] = !color[p];
                    q.push(to);
                    cnt[color[to]]++;
                }
                else if(color[p] == color[to]) {
                    return -1;
                }
            }
        }
        v.push_back(make_pair(cnt[0], cnt[1]));
    }
    vector<int> cur(n+10, INF);
    cur[0] = 0;
    rep(i, v.size()) {
        vector<int> nxt(n+10, INF);
        for(int j = 0; j + v[i].fi < nxt.size(); ++j) {
            nxt[j + v[i].fi] = min(nxt[j+v[i].fi], cur[j] + v[i].se);
        }
        for(int j = 0; j + v[i].se < nxt.size(); ++j) {
            nxt[j + v[i].se] = min(nxt[j+v[i].se], cur[j] + v[i].fi);
        }
        swap(cur, nxt);
    }
    ll ret = 4e18;
    rep(i, cur.size()) {
        ret = min(ret, i*(i-1LL)/2LL+(cur[i] * (cur[i]-1LL))/2LL);
    }
    return ret;
}

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        d[a][b] = d[b][a] = true;
    }
    rep(i, n) d[i][i] = true;
    int ans = calc(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int H, W, N;
vector<pii> v;
ll factorial[2 * MN], dp[3005];

ll fpow(ll x, ll y, ll m) {
    ll ret = 1;
    for (x %= m; y > 0; y >>= 1, x = (x * x) % m)
        if (y & 1) ret = (ret * x) % m;
    return ret;
}

ll inv(int x) {
    return fpow(x, MOD - 2, MOD);
}

ll choose(ll n, ll k) {
    return ((factorial[n] * inv(factorial[k])) % MOD * inv(factorial[n - k])) % MOD;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> H >> W >> N;
    for (int i = 0, r, c; i < N; i++) {
        cin >> r >> c;
        v.emplace_back(r, c);
    }
    v.emplace_back(1, 1);
    v.emplace_back(H, W);
    sort(v.begin(), v.end());
    factorial[0] = factorial[1] = 1;
    for (int i = 2; i <= 2e5; i++) factorial[i] = (factorial[i - 1] * i) % MOD;
    dp[0] = 1;
    for (int i = 1; i < v.size(); i++) {
        int cx = v[i].first, cy = v[i].second;
        dp[i] = choose(cx - 1 + cy - 1, cx - 1);
        for (int j = 1; j < i; j++) {
            int px = v[j].first, py = v[j].second;
            if (py > cy) continue;
            dp[i] = (dp[i] + MOD - (dp[j] * choose(cx - px + cy - py, cx - px)) % MOD) % MOD;
        }
    }
    cout << (dp[v.size() - 1]) % MOD << '\n';
    return 0;
}


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

using ll = long long;
using pi = pair<int, int>;

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

    ll d, t, s;
    cin >> d >> t >> s;
    if(s * t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

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

int main(){
  int n;
  while(~scanf("%d",&n)){
    printf("%d\n",n*(n+1)/2 + 1);
  }
  return 0;
}

Measured memory_bytes: 0
from itertools import permutations

n,m=map(int,input().split())
tree=[[] for i in range(m+1)]
for i in range(m):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

cnt=0
for i in permutations(range(1,n)):
    if i[0] in tree[0]:
        t_cnt=1
        for j in range(1,len(i)):
            if i[j] in tree[i[j-1]]:
                t_cnt+=1
            else:
                break
        if t_cnt==n-1:
            cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

int main() {
  char s[10];
  scanf("%s", s);
  printf("%c\n", 'A' <= s[0] && s[0] <= 'Z' ? 'A' : 'a');
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    string S;
    cin >> S;

    ll N = SZ(S), cnt = 0;
    REP(i,0,N/2) {
        if(S[i] != S[N-1-i]) ++cnt;
    }
    _PR(cnt);


    return 0;
}

/*



*/

Measured memory_bytes: 256
#K = input()
#X = list(map(int, input().split()))
#s = input().split()
S = input()

flag = True
count = 0
if (S[0] == "R"):
    count += 1
else:
    flag = False

if (S[1] == "R"):
    count += 1
    flag = True
else:
    flag = False

if (S[2] == "R"):
    if (flag):
        count += 1
    else:
        count = 1

print(count)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int A, B, C, D, L, R;
      cin >> A >> B >> C >> D;
      L = A + B;
      R = C + D;
      if (L < R){
        cout << "Right" << endl;
      }
      else if (L == R){
        cout << "Balanced" << endl;
      }
      else {
        cout << "Left" << endl;
      }
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    int ans = 1;
    for(long i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            if(ans<i) ans =i;
        }
    }
    if(ans == 1)
    {
        cout<<n-1<<endl;
    }
    else
    {
        long long tmp = n/ans;
        cout<<tmp + ans-2<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool valid(vector<int>& a,int len,int k,int n){
    int count=0;
   for(int i=0;i<n;i++){
       count+=(a[i]+len-1)/len-1;
       if(count>k)
       return false;
   }
    return count<=k;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> a(n,0);
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a.begin(),a.end(),greater<int>());
    int l=1,r=a[0],ans=a[0];
    if(k==0)
    cout<<ans;
    else{
        while(l<=r){
        int mid=l+(r-l)/2;
        if(valid(a,mid,k,n))
        ans=mid,r=mid-1;
        else
        l=mid+1;
        }
        cout<<ans;
    }
    return 0;
}


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

int main(void){
	ll A,B,N,res=LLONG_MAX;
	cin>>A>>B>>N;
	rep1(i,N)rep1(j,N){
		if(B*j%i==0){
			ll x=abs(B*j/i - A);
			res = min(res,x);
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3112
import java.util.*;   
import java.lang.*;   
import java.math.*;   
import java.io.*; 

public class Main {
	Scanner sc;
	
	void run() {
		sc = new Scanner(System.in);
		
		while (sc.hasNext()) {
			int d = sc.nextInt();
			int sum = 0;
			for (int i=0;i<600/d;i++) {
				sum += d * ( y_x2(i*d) );
			}
			System.out.println(sum);
		}
		
		
	}
	
	public int y_x2(int x) {
		return x*x;
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
}

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

using namespace std;

using pii = pair<int, int>;
using Edge = tuple<int, int, int>;
constexpr int MAX = 252521;
constexpr int INF = INT_MAX;

struct State {
    int v, cost, trans, en;
    
    State () {}
    State (int v, int cost, int trans, int en) :
        v{v}, cost{cost}, trans{trans}, en{en} {}

    bool operator < (const State& s) const {
        if (cost != s.cost) {
            return cost > s.cost;
        }
        return trans > s.trans;
    }
};

int N, T;
vector<Edge> G[MAX];

pii dijkstra()
{
    vector<pii> d(MAX, pii(INF, INF));
    
    priority_queue<State> pq;
    pq.push(State(0, 0, 0, -1));
    while (!pq.empty()) {
        auto st = pq.top(); pq.pop();
        int v = st.v, cost = st.cost, trans = st.trans, en = st.en;

        if (pii(cost, trans) > d[en]) continue;
        
        if (v == 1) {
            return d[en];
        }
        
        for (const auto& g : G[v]) {
            int to, ncost, nen;
            int ntrans = trans;
            
            tie(to, ncost, nen) = g;
            ncost += cost;
            
            if (en != -1 && abs(en - nen) > 1) {
                ncost += T;
                ntrans++;
            }
            
            if (pii(ncost, ntrans) < d[nen]) {
                d[nen] = pii(ncost, ntrans);
                pq.push(State(to, ncost, ntrans, nen));
            }
        }        
    }
    return pii(-1, -1);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string A, B;
    map<string, int> s2i;
    int n = 0;
    
    cin >> N >> T >> A >> B;
    
    s2i[A] = 0;
    s2i[B] = 1;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        vector<int> v;
        for (int j = 0; j < a; j++) {
            string s;
            cin >> s;
            if (s2i.count(s) == 0) {
                s2i[s] = s2i.size();
            }
            v.emplace_back(s2i[s]);
        }
        for (int j = 0; j < a - 1; j++) {
            int cost;
            cin >> cost;
            G[v[j]].emplace_back(v[j + 1], cost, n + j);
            G[v[j + 1]].emplace_back(v[j], cost, n + j);           
        }
        n += a;
    }
    pii res = dijkstra();
    if (res.first == -1) {
        cout << -1 << endl;
    } else {
        cout << res.first << " " << res.second << endl;
    }
    return 0;
}

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


int main() {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    int count = 0;
    
    string str1, str2;
    
    cin >> str1 >> str2;
    
    for (int i = 0; i < 3; i++) {
        if (str1.at(i) == str2.at(i)) {
            count += 1;
        }
    }
    
    cout << count;
}


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

int main() {
  int N;
  cin>>N;
  int sum=0;
  vector<int> A(N),B(N),C(N-1);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
  }
  for(int i=0; i<N; i++){
    cin>>B.at(i);
    sum+=B.at(i);
  }
  for(int i=0; i<(N-1); i++){
    cin>>C.at(i);
  }
  int a;
  
  for(int i=0; i<(N-1); i++){
    if((A.at(i)+1)==A.at(i+1)){
      if(A.at(i)!=N){
        sum+=C.at(A.at(i)-1);
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3620
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    H, W = map(int, rl().split())
    
    ans = 10 ** 10
    for y1 in range(1, H):
        s1 = y1 * W
        y2 = (H - y1) // 2
        y3 = H - y1 - y2
        s2 = y2 * W
        s3 = y3 * W
        ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
        x2 = W // 2
        x3 = W - x2
        s2 = (H - y1) * x2
        s3 = (H - y1) * x3
        ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    
    for x1 in range(1, W):
        s1 = x1 * H
        x2 = (W - x1) // 2
        x3 = W - x1 - x2
        s2 = x2 * H
        s3 = x3 * H
        ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
        y2 = H // 2
        y3 = H - y2
        s2 = (W - x1) * y2
        s3 = (W - x1) * y3
        ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 68040
arr = gets.chomp.split(" ").map(&:to_i)
n = arr[0]
k = arr[1]
r = k+1
    1 if r == 0 or r == n
  
    # store C(n,r) in a matrix
    c = Array.new(n+1).map{Array.new(r+1,0)}
    i,j = 0
  
    for i in 0..n
      # C(i,0) = 1 for i = 0...n
      c[i][0] = 1
    end
    for j in 0..r
      # if n = 0, C(n,r) = 0 for all 'r'
      c[0][j] = 0
    end
  
    for i in 1..n
      for j in 1..r
        if i == j
          # C(n,n) = 1
          c[i][j] = 1
        elsif j > i
          # case when r > n in C(n,r)
          c[i][j] = 0
        else
          # apply the standard recursive formula
          c[i][j] = c[i-1][j-1] + c[i-1][j]
        end
      end
    end

k.times{|t|
if t == 0 then
    puts n-k+1
elsif t > n - k then 
    puts 0
else
puts c[k-1][t]*c[n-k+1][t+1]%1000000007
end
}

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

//create arrays outside of main()
int N = 10;
char steps[100] = {};

stack<char> s;


int main() {

    int matched = 1;

    string str;
    cin >> str;

    for(int i=0; i<str.length(); i++){
        if(i%2==0){
            if(str[i]=='L'){
                matched = 0;
            }
        }
        if(i%2==1){
            if (str[i]=='R'){
                matched = 0;
            } 
        }
    }

    if(matched ==1 ){
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <ios>
#include <iomanip>

using namespace std;

//=================================================================
//Grand Contest 029 A
int main(){
    string S;
    cin >> S;
    ll b=0;
    ll w=0;
    ll ans=0;
    ll ans2=0;

    for(ll i=0; i< S.length(); i++){
        if(S[i]=='B'){
            b++;
        }else{
            ans += b;
            ans2 += i-w;
            w++;
        }
        //cout << ans << " " << ans2 << endl;
    }
    cout << ans2 << endl;
}

Measured memory_bytes: 832
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]


n,x = map(int, input().split())
l = list(map(int, input().split()))

temp = []

temp.append(0)
last = 0
for i in range(n):
    temp.append(last+l[i])
    last += l[i]
ans = 0
for i in range(n+1):
    if temp[i] <= x:
        ans += 1
print(ans)




Measured memory_bytes: 9072
#include <iostream>
#include <vector>

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;
    std::vector<std::vector<int>> M(2, std::vector<int>(N));
    
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < N; j++){
            std::cin >> M.at(i).at(j);
        }
    }

    int max = 0;
    for(int i = 0; i < N; i++){
        int cnt = 0;
        int line = 0;
        for(int j = 0; j < N; j++){
            cnt += M.at(line).at(j);
            if(j == i){
                line = 1;
                cnt += M.at(line).at(j);
            }
        }
        max = std::max(max, cnt);
    }
    
    std::cout << max << std::endl;
}


Measured memory_bytes: 384
/**
 * code generated by Junayed Kader
 * Student of Computer Science
 * @author
 */

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

ll gcd ( ll a, ll b )
{
    return __gcd ( a, b );
}
ll lcm ( ll a, ll b )
{
    return a * ( b / gcd ( a, b ) );
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}
ll min(ll a,ll b)
{
    return a<b?a:b;
}
const int mx = 1e5+123;
ll dp[123][mx], W, n, w[mx], v[mx];
ll solve(int i , int j)
{
    if(i>n) return 0;
    if(dp[i][j]!=-1) return dp[i][j];

    ll ret1 =0 ,ret2 = 0;
    if(w[i]+j<=W) ret1 = max(ret1, v[i]+solve (i+1, w[i]+j));
        ret2 = solve(i+1, j);

        return dp[i][j] = max(ret1, ret2);


}
void _case()
{

  cin >> n >> W;
  for ( int i = 1; i <= n; i++ ) {
    cin >> w[i] >> v[i];
  }

  memset ( dp, -1, sizeof(dp) );
  cout << solve ( 1, 0 ) << endl;

}
int main()
{
    optimize();
     _case();

    return 0;
}



Measured memory_bytes: 99888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		char[] line=sc.nextLine().toCharArray();
		for(int i=line.length-1;0<=i;i--){
			System.out.print(line[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 17272
# -*- coding: utf-8 -*-

def main():
    str=input()
    a,b=0,0
    l=len(str)
    
    for i in range(l):
        if(str[i]=='A'):
            a=i
            break
    for i in reversed(range(l)):
        if(str[i]=='Z'):
            b=i
            break
    print(b-a+1)
        


if __name__=="__main__":
    main()
    

Measured memory_bytes: 3516
s=input()
t=input()
sl=len(s)
tl=len(t)

cnt=0
ans=0

for i in range(sl-tl+1):
    for j in range(tl):
        if t[j] == s[i+j]:
            cnt+=1
    
    ans=max(cnt, ans)
    cnt=0

print(tl-ans)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair <int,int> pii;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef long long int lli;
typedef vector <lli> vlli;
typedef vector <vlli> vvlli;
typedef vector <string> vs;
typedef vector <bool> vb;

#define rep(i, n) for( i = 0; i < (n); ++i)
#define repA(i, a, n) for( i = a; i <= (n); ++i)
#define repD(i, a, n) for( i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sortr(x) sort(x.begin(),x.end(),greater <int> ())
#define mod 1000000007
#define ff first
#define ss second
#define fill(a,c)  memset(a, c, sizeof (a))
#define formap(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.first<<" , "<<it.second<<endl;} cerr<<endl
#define PI  3.14159265358979323846
#define pb push_back




int main() {
	cin.sync_with_stdio(0);cin.tie(0);
    cin.exceptions(cin.failbit);
    
    int i,j,x,y;
    cin>>x;
    y=x+x*x+x*x*x;
    cout<<y;
    
    
   
   
   
   
   
   
	return 0;
}


Measured memory_bytes: 3648
k = gets.to_i

def nextr(s)
  (s.size - 1).downto(1) do |i|
    if s[i].ord < s[i - 1].ord + 1 && s[i].ord < '9'.ord
      s[i] = (s[i].ord + 1).chr
      (i + 1).upto(s.size - 1) do |j|
        s[j] = [(s[j - 1].ord - 1), '0'.ord].max.chr
      end
      return s
    end
  end
  if s[0].ord < '9'.ord
    s[0] = (s[0].ord + 1).chr
  else
    s = '1' + s
  end
  1.upto(s.size - 1) do |j|
    s[j] = [(s[j - 1].ord - 1), '0'.ord].max.chr
  end
  s
end

s = '0'
count = 0
loop do
  if count == k
    puts s.to_i
    exit
  end
  s = nextr(s)
  count += 1
end


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

int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;

    if (s[0] != '1')
    {
        cout << s[0] << endl;
    }
    else
    {
        int p = 0;
        int onenum = 0;
        while (s[p] == '1')
        {
            p += 1;
            onenum += 1;
        }
        if(k <= onenum){
            cout << 1 << endl;
        }else{
            cout << s[p] << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val scanner = new Scanner(System.in)
  val h = scanner.nextInt
  val w = scanner.nextInt
  for(i <- 0 until h; j <- 0 until w) {
    if(scanner.next.equals("snuke")) {
      println("" + ('A' + j).toChar + (i + 1))
    }
  }
}

Measured memory_bytes: 22440
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	p = readline() |> split |> parseMap
	k = 0
	for i in 2:n-1
		if p[i-1]<p[i]<p[i+1] || p[i+1]<p[i]<p[i-1]
			k += 1
		end
	end
	println(k)
end

main()

Measured memory_bytes: 110588
import sys

input = sys.stdin.readline

mod = 998244353

n, k = map(int, input().split())

lr = [list(map(int, input().split())) for _ in range(k)]
lr.sort()

if lr[0][0] == 1:
    f = [1, 1]
else:
    f = [1, 0]

for i in range(2, n):
    next_f = f[i - 1]
    for l, r in lr:
        if i - l >= 0:
            next_f += f[i - l]
        else:
            break
        if i - r - 1 >= 0:
            next_f -= f[i - r - 1]
        else:
            break
    f.append(next_f % mod)


print(f[n - 1])


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

int main() {
   int a,b,c,t;
   cin>>a>>b>>c;
   
 // 1 a, b を比べて　もしaの方が大きければ交換
 if(a > b){
    t=a;
    a=b;
    b=t;
 }
    
 // 2  a,cを比べて　もしaの方が大きければ交換 
    if(a > c){
    t=a;
    a=c;
    c=t;   
    } 
 // 3 b,c を比べて　、もしbの方が大きければ交換
    if(b>c){
    t=b; 
    b=c;
    c=t;    
    }      
    cout << a<<" "<<b<<" " <<c<<endl;
  
        
return 0;    
}

Measured memory_bytes: 1164
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(int argc,char** argv){
  int n;
  cin >> n;
  int h[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  int cost[n];
  for(int i = 0; i < n; i++){
    cost[i] = 0;
  }
  cost[1] = abs(h[1]-h[0]);
  for(int i = 2; i < n; i++){
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]),cost[i-2] + abs(h[i]-h[i-2]));
  }
  cout << cost[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
int T,D,L;
cin>>T>>D>>L;
if(T==0)return 0;
V<int> dat(T);
for(int i=0;i<T;i++)cin>>dat[i];
int ans=0;
int place=0;
for(int i=0;i<T;i++){
  if(place){
    ans++;
    place--;
  }
  if(dat[i]>=L)place=D;
}
cout<<ans<<"\n";
}
}


Measured memory_bytes: 3512
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
string keys[10] = {
  "",
  ".,!? ",
  "abc",
  "def",
  "ghi",
  "jkl",
  "mno",
  "pqrs",
  "tuv",
  "wxyz"
};
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    string key_string;
    cin >> key_string;
    string ans;
    bool in_loop = false;
    int loop_ind = 0;
    int cur_key;
    for(int j = 0; j < key_string.size(); j++){
      if(key_string[j] == '0'){
        if(in_loop){
          ans += keys[cur_key][loop_ind];
          in_loop = false;
        }
      } else {
        if(in_loop){
          loop_ind = (loop_ind + 1) % keys[cur_key].size();
        } else {
          in_loop = true;
          loop_ind = 0;
          cur_key = key_string[j] - '0';
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
i_plus_A = Counter([i + A[i] for i in range(N)])
i_minus_A = [i - A[i] for i in range(N)]
ans = 0
for x in i_minus_A:
    ans += i_plus_A[x]
print(ans)

Measured memory_bytes: 140812
//In the name of Allah 
#include <bits/stdc++.h>

using namespace std; 

#define F first
#define S second
#define MP make_pair
#define PB push_back
#define int long long

const int N=5e6+200;
const int NN=2e3+100;
const int mod=1e9+7;

int f[N],rev[N],dp[NN][NN];

int tav(int n,int k){
	n%=mod; 
	if(k==0)return 1; 
	int ans=tav(n,k/2);
	ans*=ans; 
	ans%=mod;
	if(k%2==1)ans*=n; 
	ans%=mod; 
	return ans;
}
int choose(int n,int k){
	int ans=(f[n]*rev[k])%mod; 
	ans*=rev[n-k];
	ans%=mod; 
	return ans; 
}

int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);	
	int n,k;
	cin>>n>>k;
	k--;
	if(k==0)return cout<<"1\n",0;
	f[0]=1;
	for(int i=1;i<N;i++)
		f[i]=(f[i-1]*i)%mod; 
	
	rev[N-1]=tav(f[N-1],mod-2);
	for(int i=N-2;i>=0;i--)
		rev[i]=(rev[i+1]*(i+1))%mod;
	
	dp[0][0]=1;
	for(int i=1,sum;i<n;i++){
		sum=dp[i-1][i-1];
		dp[i][i]=(sum*choose(i*k+k-1,k-1))%mod;
		for(int j=i-1;j>=0;j--){
			if(j!=0)sum+=dp[i-1][j-1];
			sum%=mod; 
			dp[i][j]=(sum*choose(i*k+i-j+k-1,k-1))%mod;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=dp[n-1][i];
		ans%=mod;
	}
	cout<<(ans*f[n])%mod<<"\n";
	return 0;
}

Measured memory_bytes: 101504
import copy

H, W = map(int, input().split())
grid = [[1 if c == "." else 0 for c in input()] for _ in range(H)]

L = copy.deepcopy(grid)
R = copy.deepcopy(grid)
U = copy.deepcopy(grid)
D = copy.deepcopy(grid)

for i in range(H):
  for j in range(1, W):
    L[i][j] = (L[i][j-1] + 1) * L[i][j]
    R[i][-1-j] = (R[i][-j] + 1) * R[i][-1-j]

for j in range(W):
  for i in range(1, H):
    U[i][j] = (U[i-1][j] + 1) * U[i][j]
    D[-1-i][j] = (D[-i][j] + 1) * D[-1-i][j]

ans = 0

for i in range(H):
  for j in range(W):
    ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3, 0)

print(ans)


Measured memory_bytes: 240972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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;
}

int main()
{
  rep(i, 5)
  {
    int x;
    cin >> x;
    if (x == 0)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3520
import numpy as np
N,M = map(int,input().split())
pena = np.zeros(N)
clear = np.zeros(N)
for i in range(M):
    p,S = input().split()
    p = int(p)-1
    if S == "WA" and clear[p] == 0:
        pena[p] += 1
    else:
        clear[p] = 1
clear_num = np.where(clear == 1)[0]
new_pena = pena[clear_num]
print(int(np.sum(clear)),int(np.sum(new_pena)))

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h,w,n;
  cin >> h >> w >> n;
  map<pii,int32> v;
  REP(i,n){
    int32 r,c;
    cin >> r >> c;
    --r;--c;
    cin >> v[pii(r,c)];
  }
  vector<vector<vector<int32>>> dp(h,vector<vector<int32>>(w,vector<int32>(4,0)));
  REP(i,h)REP(j,w){
    if(i != 0){
      REP(k,4)
        chmax(dp[i][j][0], dp[i-1][j][k]);
    }
    if(j != 0){
      REP(k,4)
        chmax(dp[i][j][k],dp[i][j-1][k]);
    }
    if(v.count(pii(i,j))){
      FORR(k,3,1)
        chmax(dp[i][j][k],dp[i][j][k-1] + v[pii(i,j)]);
    }
  }
  int32 ans = 0;
  REP(k,4)chmax(ans,dp[h-1][w-1][k]);
  ANS(ans);
  return 0;
}

Measured memory_bytes: 648148
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc)
}

func resolve(n int) string {
	l := n % 10
	switch l {
	case 2, 4, 5, 7, 9:
		return "hon"
	case 0, 1, 6, 8:
		return "pon"
	}
	return "bon"
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1768
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register long long i = (a);i <= (b);++i)
#define per(i,a,b) for(register long long i = (a);i >= (b);--i)
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;

ll x,y,z;

int main(){
    //std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> x >> y >> z;
    std::swap(x,y);
    std::swap(x,z);
    cout << x << " " << y << " " << z << "\n";

    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = int((1 + (8 * N + 1) ** 0.5) / 2)
    if not N == K * (K - 1) // 2:
        print('No')
        return

    num = 1
    ans = [[0] * (K - 1) for _ in range(K - 1)]
    for i in range(K - 1):
        for j in range(i + 1):
            ans[i][j] = ans[j][i] = num
            num += 1
    
    print('Yes')
    print(K)
    for row in ans:
        print(K - 1, *row)
    tmp = [ans[i][i] for i in range(K - 1)]
    print(K - 1, *tmp)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9224
n, m = map(int,input().split())

colist=[]
checks=[0]*n
kyori=[0]*n
mae=[0]*n

for i in range(n):
    colist.append([])

for i in range(m):
    a, b = map(int,input().split())
    colist[a-1].append(b-1)
    colist[b-1].append(a-1)

#print(colist)

#now=[0]
#tugi=colist[0]
tugi=[0]
checks[0]=1
point=1
turn=1

while point<n and len(tugi)!=0:
    koho=[]
    for t in tugi:
        koho2=colist[t]
        for k2 in koho2:
            if checks[k2]==0:
                checks[k2]=1
                kyori[k2]=turn
                mae[k2]=t
                point+=1
                koho.append(k2)
    tugi=koho
    turn+=1

if point==n:
    print("Yes")
    for i in range(n-1):
        print(mae[1+i]+1)
else:
    print("No")

Measured memory_bytes: 102084
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int n;
int a[MAXN];
map<char, char> F, G;

int main()
{
	
	string s, t;
	cin >> s >> t;
	n = s.size();
	for (int i = 0; i < n; ++ i)
	{
		if (F.count(s[i]) == 0 && G.count(t[i]) == 0)
		{
			F[s[i]] = t[i];
			G[t[i]] = s[i];
		}
		else
		{
			if (F[s[i]] != t[i] || G[t[i]] != s[i])
			{
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	
	return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string s;
    cin >> s;
    if(s == string(s.rbegin(),s.rend())) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


int main()
{
	int h, w;

	cin >> h >> w;

	vector<vector<char>> a(h + 2, vector<char>(w + 2));

	int bc = 0;
	for (size_t i = 1; i < h + 1; i++)
	{
		cin >> (a[i].data() + 1);
		for (size_t j = 1; j < w + 1; j++)
		{
			bc += (a[i][j] == '#') ? 1 : 0;
		}
	}

	if (bc < h * w / 10)
	{
		vector<vector<INT>> d(h, vector<INT>(w, 10000));

		for (INT x = 0; x < w; x++)
		{
			for (INT y = 0; y < h; y++)
			{
				if (a[y + 1][x + 1] == '#')
				{
					for (INT x2 = 0; x2 < w; x2++)
					{
						for (INT y2 = 0; y2 < h; y2++)
						{
							d[y2][x2] = min(d[y2][x2], abs(x - x2) + abs(y - y2));
						}
					}
				}
			}
		}

		INT ans = 0;
		for (size_t x = 0; x < w; x++)
		{
			for (size_t y = 0; y < h; y++)
			{
				ans = max(d[y][x], ans);
			}
		}

		cout << ans << endl;
	}
	else
	{
		bool con;
		int ans = 0;

		while (true)
		{
			con = false;
			for (size_t x = 1; x < w + 1; x++)
			{
				for (size_t y = 1; y < h + 1; y++)
				{
					if (a[y][x] == '.')
					{
						con = true;
					}
					if (a[y][x] == '+')
					{
						a[y][x] = '#';
					}
				}
			}
			if (!con)
			{
				break;
			}
			for (size_t x = 1; x < w + 1; x++)
			{
				for (size_t y = 1; y < h + 1; y++)
				{
					if (a[y][x] == '#')
					{
						a[y - 1][x] = a[y - 1][x] == '.' ? '+' : a[y - 1][x];
						a[y + 1][x] = a[y + 1][x] == '.' ? '+' : a[y + 1][x];
						a[y][x - 1] = a[y][x - 1] == '.' ? '+' : a[y][x - 1];
						a[y][x + 1] = a[y][x + 1] == '.' ? '+' : a[y][x + 1];
					}
				}
			}
			ans++;
		}

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


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> isClear(N+1);
  vector<int> pen(N+1);
  int a;
  string b;
  for(int i = 0; i < M; i++){
    cin >> a >> b;
    
    if(b == "AC") {
      isClear.at(a) = true;
    }
    else if(!isClear.at(a)){
      pen.at(a)++;
    }
  }
  
  int AC = 0;
  int WA = 0;
  for(int i = 1; i < N+1; i++) {
    
    if(isClear.at(i)){
      AC++;
      WA += pen.at(i);
    }
  }
  
  cout << AC << " " << WA << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    vector<int> count(n-1, 0);
    string ans = "";
    for (int i = 0; i < s[0].size(); ++i) {
        int tmp = 0;
        for (int j = 1; j < n; ++j) {
            if (count[j] >= s[j].size()) {
                cout << ans << endl;
                return 0;
            }
            while (s[j][count[j]] < s[0][i]) {
                ++count[j];
                if (count[j] >= s[j].size()) {
                    cout << ans << endl;
                    return 0;
                }
            }
            if (s[j][count[j]] == s[0][i]) {
                ++count[j];
                ++tmp;
            }
        }
        if (tmp == n - 1) ans += s[0][i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll s=0, a[100005], n;

int main(){
	ll i, j;
	cin >> n;
	map<ll, int> m;
	for(i=0;i<n;i++){
		cin >> a[i];
		m[a[i]]++;
		s += a[i];
	}
	ll q;
	cin >> q;
	while(q--){
		ll b, num, c;
		cin >> b >> c;
		if(b == c){
			cout << s << '\n';
			continue;
		}
		num = m[b];
		s -= num*b;
		s += num*c;
		m[b] = 0;
		m[c] = num+m[c];
		cout << s << '\n';
	}
}


Measured memory_bytes: 10164
from bisect import bisect_right
n = int(input())
ans = 1
data = [-int(input())]
for i in range(n-1):
    x = -int(input())
    j = bisect_right(data,x)
    if j == ans:
        data.append(x)
        ans += 1
    else:
        data[j] = x
print(ans)

Measured memory_bytes: 51032
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  if(k == 0){
    cout << (ll)n*n << endl;
    return 0;
  }
  ll ans = 0;
  rep2(b, k+1, n+1){
    ans += (ll)(n+1)/b*(b-k);
    int m = (n+1)%b;
    if(m-k > 0) ans += m-k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	as <- map pred <$> readInts
	print $ solve as

solve as' = runST $ do
	let
		n = length as'
	as <- newListArray ( 0, n - 1 ) as' :: ST s ( STUArray s Int Int )
	res <- newSTRef 0
	forM_ [ 0 .. n - 1 ] $ \i -> do
		j <- readArray as i
		r <- readArray as j
		when ( r == i ) $
			modifySTRef res succ
	modifySTRef res ( `div` 2 ) 
	readSTRef res

Measured memory_bytes: 16764