akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>

using namespace std;

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

const int H_MAX = 300;
const int W_MAX = 300;
const int Q_MAX = 100000;
const int N_MAX = H_MAX * W_MAX;

int H, W, D;
int Q;
int L[Q_MAX];
int R[Q_MAX];

int h[N_MAX];
int w[N_MAX];
int m[N_MAX];

void solve() {
  FOR(i, D, H * W - 1) {
    m[i] = m[i - D] + abs(h[i] - h[i - D]) + abs(w[i] - w[i - D]);
  }

  REP(i, Q) {
    int f = L[i] - 1, t = R[i] - 1;
    printf("%d\n", m[t] - m[f]);
  }
}

void input() {
  scanf("%d%d%d", &H, &W, &D);
  REP(i, H) REP(j, W) {
    int A;
    scanf("%d", &A);
    h[A - 1] = i;
    w[A - 1] = j;
  }
  scanf("%d", &Q);
  REP(i, Q) scanf("%d%d", L + i, R + i);
}

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


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ull N{}, K{}; cin >> N >> K;
  vector<ull> A(N);
  using Pair = pair<ull, ull>;
  vector<Pair> res(N);
  boost::for_each(A, [](auto& a){ cin >> a; });

  for(ull i = 0; i < N; ++i)
  {
    Pair p{};
    for(ull j = 0; j < N; ++j)
    {
      if(i == j) continue;
      if(i < j)
      {
        if(A[i] > A[j]) ++p.first;
      }
      else
      {
        if(A[i] > A[j]) ++p.second;
      }
    }
    res[i] = std::move(p);
  }

  ull ans{};
  ull sup0 = K % 2 
    ? (((K + 1) / 2) % INF * K) % INF 
    : ((K / 2) % INF * (K + 1) % INF) ;
  ull sup1 = (K - 1) % 2 
    ? (((K) / 2) % INF * (K - 1)) % INF 
    : (((K - 1) / 2) % INF * (K) % INF) ;
  ans = boost::accumulate(res, (ull)0, [&sup0, &sup1](auto r, auto p){
    return ((r + (p.first * sup0) % INF) % INF + (p.second * sup1) % INF) % INF;
  });

  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

bool dp[1<<10];

bool solve(){
  int n;
  char s[SIZE];
  vector<int> vec[10];
  
  scanf("%d", &n);

  if(n == 0) return false;

  scanf("%s", s);

  int p = 0;
  
  for(int i=0;i<n;i++){
    int b = s[i] - '0';
    if(p != 0 && s[i] != 'u') vec[b].push_back(p);

    if(s[i] == 'u'){
      p = 0; continue;
    }

    if(p & (1 << b)){
      puts("UNSAFE");
      return true;
    }

    p |= 1 << b;
  }

  for(int i=0;i<10;i++){
    for(int j=0;j<(1<<10);j++) dp[j] = false;

    
    for(int j=0;j<vec[i].size();j++){
      dp[vec[i][j]] = true;
    }

    for(int j=0;j<(1<<10);j++){
      if(dp[j] && (j & (1 << i))){
        puts("UNSAFE");
        return true;
      }
      for(int k=0;k<10;k++){
        if(dp[j] && (j & (1 << k))){
          for(int l=0;l<vec[k].size();l++){
            if((j & vec[k][l]) == 0) dp[j|vec[k][l]] = true;
          }
        }
      }
    }
  }

  puts("SAFE");
  return true;
}


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



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

int main(void){
    int n,m;
    cin >> n >> m;
    
    vector<int> count(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        count[a-1]++;
        count[b-1]++;
    }

    for(int i=0;i<n;i++){
        cout << count[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;

    ll a[n];
    ll x = 0;
    rep(i, n){
        cin >> a[i];
        x += a[i];
        if(i & 1)x -= 2*a[i];
    }

    ll ans[n];
    ans[0] = x;
    ans[n-1] = 2*a[n-1] - ans[0];
    for(ll i = 1; i < n; ++i){
        ans[i] = 2*a[i-1] - ans[i-1];
    }

    rep(i, n)cout << ans[i] << " ";
}

Measured memory_bytes: 5204
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type smaller []byte

func (s smaller) Len() int {
	return len(s)
}
func (s smaller) Less(i, j int) bool {
	return s[i] < s[j]
}
func (s smaller) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type larger []byte

func (l larger) Len() int {
	return len(l)
}
func (l larger) Less(i, j int) bool {
	return l[i] > l[j]
}
func (l larger) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func main() {
	sc.Split(bufio.ScanWords)

	s, t := next(), next()

	sRunes, tRunes := []byte(s), []byte(t)
	sort.Sort(smaller(sRunes))
	sort.Sort(larger(tRunes))

	if string(sRunes) < string(tRunes) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K;
  if(N<10)K=K+100*(10-N);
  Out(K);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007;
#define NIL -1

int main(){
  ll a,b,x;
  cin>>a>>b>>x;
  ll ans=0;
  ll i;
  bool check=false;
  for(i=0;b>=x*i;i++){
    if(x*i>=a&&x*i<=b){
      ans=1;
      check=true;
      break;
    }
  }
  if(check) ans+=(b-x*i)/x;
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int l[50] = {};
int x[50] = {};

int main()
{
	int n, k;
	int num;
	int ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> l[i];
	}
	//
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (x[i] < l[j])
			{
				x[i] = l[j];
				num = j;
			}
		}
		l[num] = 0;
	}
	//
	for (int i = 0; i < k; i++)
	{
		ans = ans + x[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int q(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int h[2],k[2];
  FOR(2)scanf("%d %d",&h[i],&k[i]);
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  int x[2];
  FOR(2)x[i]=h[i]*a+h[i]/10*c+k[i]*b+k[i]/20*d;
  if(x[0]>x[1]){
    PRS("hiroshi");
  }else if(x[0]<x[1]){
    PRS("kenjiro");
  }else{
    PRS("even");
  }
  return 0;
}


Measured memory_bytes: 2140
#include <iostream>
using namespace std;
int main(){
        int h,w;
        int c[10][10];
        cin >> h >> w;
        for(int i=0; i<10; i++) {
                for(int j=0; j<10; j++) {
                        cin >> c[i][j];
                }
        }
        for(int k=0; k<10; k++) {
                for(int i=0; i<10; i++) {
                        for(int j=0; j<10; j++) {
                                if(c[i][j]>c[i][k]+c[k][j]) {
                                        c[i][j]=c[i][k]+c[k][j];
                                }
                        }
                }
        }
        int a;
        int res=0;
        for(int i=0; i<h; i++) {
                for(int j=0; j<w; j++) {
                        cin >> a;
                        if(a>=0) {
                                res+=c[a][1];
                        }
                }
        }
        cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
 
bool judge(ll cut, vector<ll> logs, ll n, ll k){
  ll ans=0;
  if(cut==0) return false;
  // for(int i=0; i<(int)logs.size(); i++){
  ll cc=0;
  for(ll i=0; i<n; i++){
  
    if(logs[i]%cut!=0) ans+=(logs[i]/cut);
    else ans+=(logs[i]/cut-1);
    // cout<<"ans["<<i<<"] = "<<ans<<endl;

    //ans = (logs[i] + cut - 1) / cut - 1;
    //if(ans > 0) cc += ans;

    if(ans>k) return false;
    // else cout<<"ans["<<i<<"] = "<<ans<<endl;
  }
  if(ans>k) return false;
  else return true;
  //if(cc>k) return false;
  //else return true;
}
 
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n,k; cin>>n>>k;
  vector<ll> a(n,0);
  rep(i,n) cin>>a[i];

  ll ok=1000000100;
  ll ng=0;

  ll t=0;
  //int k=0;
  //while(abs(ok-ng)>1){
  while(abs(ok-ng)>1){
  
    ll mid=(ok+ng)/2;

    if(judge(mid,a,n,k)){
      ok=mid;
      //cout<<"ok["<<k<<"] = "<<ok<<endl;
    }else{
      ng=mid;
      // cout<<"ng["<<k<<"] = "<<ng<<endl;
    }
    //cout<<"t = "<<t<<"/mid = "<<mid<<endl;
    //t++;
  }
  cout<<ok<<endl;
  return 0;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
  fastIO;
  ll x = 100;
  ll n;
  cin >> n;
  ll cnt = 0;
  while(x < n){
    x += x/100;
    cnt ++ ;
  }
  cout << cnt;
  return 0;
}

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

int main() {
  ll Ans = 1e9;  // 回答：
  
  int N; cin >> N; // 足場数
  vector<int> H(N); // 足場の高さ
  rep(i,N){cin>>H.at(i);}

  vector<int> DP(N,1e9);  // 各足場迄の最小コスト

  // 足場２つ目までは、固定
  DP.at(0) = 0;
  DP.at(1) = abs(H.at(1) - H.at(0));
  // ３つ目以降の処理
  for(int i=2;i<N;i++){
    DP.at(i) = min( abs(H.at(i)-H.at(i-1))+DP.at(i-1) , abs(H.at(i)-H.at(i-2))+DP.at(i-2) );
  }
    cout << DP.at(N-1) << endl;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size(), ans = 0;
    s.insert(s.begin(), 'A');
    for(int i = 0; i < n; i++) ans += s[i] >= s[i + 1];
    cout << ans << endl;
}



Measured memory_bytes: 3180
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int h,w;
int m;
int cnty[303030],cntx[302000];
vi adj[303020];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> h >> w >> m;
  for(int i=1;i<=m;i++){
    int x1,y1;
    cin >> x1 >> y1;
    adj[x1].pb(y1);
    cntx[x1]++;
    cnty[y1]++;
  }
  set<pi> s;
  for(int i=1;i<=w;i++){
    s.insert({cnty[i],i});
  }
  int ans = 0;
  
  for(int i=1;i<=h;i++){
    int cur = cntx[i];
    for(auto t:adj[i]){
      s.erase(s.find({cnty[t],t}));
      cnty[t]--;
      s.insert({cnty[t],t});
    }
    auto it = s.end();
    it--;
    ans = max(ans,(*it).fs+cur);
    for(auto t:adj[i]){
      s.erase(s.find({cnty[t],t}));
      cnty[t]++;
      s.insert({cnty[t],t});
    }
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 43520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int dp[n + 1];
    rep(i, 0, n + 1) dp[i] = INF;
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j *= 6) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
        for (int j = 1; j <= i; j *= 9) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


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

int main()
{
	string s;
	while(cin>>s){
		for(int i=0;i<s.size();i++){
			if(s[i]!='@')
				cout<<s[i];
			else{
				i++;
				int num=s[i]-'0';
				i++;
				for(int j=0;j<num;j++)
					cout<<s[i];
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<vector<pii> > vvpi;

const int maxn = 2e5;
const ll mod = 998244353LL;
const ll inf = 1e9;

vi adj[maxn + 1];
int x[maxn + 1];
int ans[maxn + 1];

void dfs(int s, int p, int cnt) {
	cnt += x[s];
	ans[s] = cnt;
	for(auto v : adj[s]) {
		if(v == p)	continue;
		dfs(v, s, cnt);
	}
}

int main() {
	int i, j, n, q;
	scanf("%d %d", &n, &q);
	for(i = 1; i < n; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	while(q--) {
		int a, b;
		scanf("%d %d", &a, &b);
		x[a] += b;
	}
	dfs(1, 0, 0);
	for(i = 1; i <= n; ++i) {
		printf("%d ", ans[i]);
	}
	printf("\n");
	return 0;
}

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    int a, b; cin >> a >> b;
    if(a > 9 || b > 9){
        return cout << -1 << '\n', 0;
    }
    cout << a*b << '\n';
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int a[1000]={};
    
    for(int i=0; i<s.length(); i++){
        for(char ch='a'; ch<='z'; ch++){
            if(ch==s[i]){
                a[ch]++;
            }
        }
    }
    bool flag=true;
    for(char ch='a'; ch<='z'; ch++){
        if(a[ch]>=2) flag = false;
    }
    
    cout << ((flag)?"yes":"no") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
const ll mod=1e9+7;


void solve(){

    ll a,b;
    cin>>a>>b;

    ll ans = a*(a-1) /2 + b*(b-1)/2;
    cout<<ans;

    
    return;
}
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
 
    return 0;
}       

Measured memory_bytes: 256
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
N, A, B, C = [int(x) for x in input().split()]
s = [input() for _ in range(N)]
abc = {'A': A, 'B': B, 'C': C}
can = True
moves = []
for i in range(N):
    moves.append(next(j for j in (0, 1) if abc[s[i][j]] < abc[s[i][j ^ 1]] or abc[s[i][j]] == abc[s[i][j ^ 1]] and (i + 1 == N or s[i + 1] == s[i] or s[i][j ^ 1] not in s[i + 1])))
    abc[s[i][moves[-1]]] += 1
    abc[s[i][moves[-1] ^ 1]] -= 1
    can &= all(x >= 0 for x in abc.values())
if can:
    print('Yes')
    print(*(s[i][moves[i]] for i in range(N)), sep='\n')
else:
    print('No')


Measured memory_bytes: 95940
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

N = int(input())

def cnt_power(ans, n, cnt):
    if cnt>n:
        return ans
    elif (ans*cnt) >= (10**9+7) :
        ans = ans*cnt % (10**9+7)
        cnt += 1
        return cnt_power(ans, n, cnt)
    else:
        ans = ans*cnt
        cnt += 1
        return cnt_power(ans, n, cnt)

print(cnt_power(1, N, 1))

Measured memory_bytes: 92644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Problem solver = new Problem();
        solver.solve(0, in, out);
        out.close();
    }

    static class Problem {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next(), t = in.next();
            int min = t.length();
            for(int i = 0; i <= s.length() - t.length(); i++) {
                int count = getCount(s, t, i);
                min = Math.min(min, count);
            }
            out.println(min);
        }

        private int getCount(String s, String t, int idx) {
            int count = 0;
            for(int i = idx, j = 0; j < t.length(); i++, j++) {
                if(s.charAt(i) != t.charAt(j))
                    count++;
            }
            return count;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 33128
#include <stdio.h>
#include <string.h>
#define N 500002

int max(int a, int b){
  if (a>b) return a;
  else return b;
}

int main(void){
  char s[N];
  long long ans=0;
  int a[N];
  scanf("%s", &s);
  int n = strlen(s);

  for(int i=0; i<n; i++){
    if (s[i] == '<')
      a[i+1] = a[i]+1;
  }

  for(int i=n-1; i>=0; i--){
    if (s[i] == '>')
      a[i] = max(a[i], a[i+1]+1);    
  }

  for(int i=0; i<=n; i++)
    ans += a[i];
  
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

typedef long long int lli;

const lli maxn = lli(1e5)+5, inf = lli(1e9)+5;

lli A[maxn], vis[maxn];
pair<lli, lli> val[maxn];
vector<lli> graph[maxn];

void dfs(lli node, lli comp)
{
	vis[node] = 1;
	val[comp] = min(val[comp], {A[node], node});
	for(auto it: graph[node])
	{
		if(!vis[it]) dfs(it, comp);
	}
}

int main(void)
{
	lli n, m, x, y;
	scanf("%lld%lld", &n, &m);
	for(lli i = 0;i < n;i++) scanf("%lld", &A[i]);
	for(lli i = 0;i <= n;i++) val[i] = {inf, inf};

	while(m--)
	{
		scanf("%lld%lld", &x, &y);
		graph[x].push_back(y), graph[y].push_back(x);
	}

	lli cnt = 0, res = 0;
	for(lli i = 0;i < n;i++)
	{
		if(!vis[i]) dfs(i, cnt++);
	}

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

	set<pair<lli, lli>> S;
	for(lli i = 0;i < n;i++) S.insert({A[i], i});

	for(lli i = 0;i < cnt;i++) res += val[i].first, S.erase(val[i]);

	cnt -= 2;
	while(cnt--)
	{
		if(S.empty())
		{
			printf("Impossible\n");
			exit(0);
		}
		res += S.begin()->first;
		S.erase(S.begin());
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 15616
#include <stdio.h>
#include <string.h>


int main()
{
	unsigned long long r,x,y,a,b,c;
	while(scanf("%ld %ld",&x,&y) != EOF){
	a = x;
	b = y;
	while((r = x % y) != 0) 
    {
        x = y;
        y = r;
    }
    
    c = a * b / y;
    
    printf("%ld %ld\n",y,c);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int a = 0;
string st;
long long int getnum() {
	long long int num = 0;
	while (isdigit(st[a])) {
		num = num * 10 + st[a] - '0';
		a++;
	}
	return num;
}

long long int getexpr0() {
	long long int num(getnum());
	while (a != st.size()) {
		if (st[a] == '+') {
			a++;
			long long int bnum = getnum();
			num += bnum;
		}
		else {
			a++;
			long long int bnum = getnum();
			num *= bnum;
		}
	}
	return num;

}
long long int getkake() {
	long long int num(getnum());
	while (a != st.size()) {
		if (st[a] == '*') {
			a++;
			long long int bnum = getnum();
			num *= bnum;
		}
		else {
			return num;
		}
	}
	return num;

}
long long int getplus() {
	long long int num(getkake());
	while (a != st.size()) {
		if (st[a] == '+') {
			a++;
			long long int bnum = getkake();
			num += bnum;
		}
		else {
			assert(false);
		}
	}
	return num;

}
int main() {cin >> st;
a = 0;
int n; cin >> n;
   long long  int aa=getexpr0();
   a = 0;
	long long int bb = getplus();
	if (aa == n&&bb == n) {
		cout << "U" << endl;
	}
	else if (aa == n) {
		cout << "L" << endl;
	}
	else if (bb == n) {
		cout << "M" << endl;
	}
	else {
		cout << 'I' << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef pair<int, int> P;
int ans[200005];
int par[400005];    // Union-Find(2倍用意しておく)

void init(int n){
    for(int i = 0; i < 2 * n; ++i){
        par[i] = i;
    }
}

int find(int n){
    if(par[n] == n){
        return n;
    }
    else{
        return par[n] = find(par[n]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    
    if(x == y)      return;
    
    par[y] = x;
    return;
}

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

int main(){
    int n, k, l;
    cin >> n >> k >> l;
    map<P, int> m;
    init(n);
    for(int i = 0; i < k; ++i){     // road
        int p, q;
        cin >> p >> q;
        --p;
        --q;
        unite(p, q);
    }
    for(int i = 0; i < l; ++i){     // rail
        int r, s;
        cin >> r >> s;
        --r;
        --s;
        unite(r + n, s + n);
    }
    
    for(int i = 0; i < n; ++i){
        ++m[P(find(i), find(i + n))];
    }
    
    for(int i = 0; i < n; ++i){
        ans[i] = m[P(find(i), find(i + n))];
    }
    
    for(int i = 0; i < n; ++i){
        cout << ans[i] << ((i == n - 1) ? "\n" : " ");
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    ll c[n-1];
    for(ll i=0; i<n; i++) {
        cin>>a[i];
    }
    for(ll i=0; i<n; i++) {
        cin>>b[i];
    }
    for(ll i=0; i<n-1; i++) {
        cin>>c[i];
    }

    ll ans=0;
    ll cuisine=0;
    for(ll i=0; i<n; i++) {
        // cuisine=a[i];
        // dbg(cuisine);
        // dbg(b[cuisine-1]);
        // ans = ans + b[cuisine-1];
        // dbg(ans);
        ans = ans + b[i];
    }
    for(ll i=0; i<n-1; i++){
        if(a[i]+1 == a[i+1]) {
            ans = ans + c[(a[i])-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n;
std::cin >> n;
std::vector<int> a1;
std::vector<int> a2;

rep(i,n){
    int temp;
    std::cin >> temp;
    a1.pb(temp);
}
rep(i,n){
    int temp;
    std::cin >> temp;
    a2.pb(temp);
}
std::vector<int> dp1;
std::vector<int> dp2;

if(n == 1){
    std::cout << a1[0] + a2[0] << std::endl;
} else {
    dp1.pb(a1[0]);
    dp2.pb(a1[0] + a2[0]);
    for(int i = 1; i < n; i++){
        dp1.pb(dp1[i - 1] + a1[i]);
        dp2.pb(std::max(dp1[i],dp2[i - 1]) + a2[i]);
    }
    std::cout << dp2[n - 1] << std::endl;
}


return 0;
}

Measured memory_bytes: 256
lr = []
l = []
r = []
n = int(input())
c = 0
for i in range(0,n):
    lr = input().split()
    l.append(int(lr[0]))
    r.append(int(lr[1]))

for i in range(0,n):
    if l[i] == r[i]:
        c += 1
    else:
        c += (1 + r[i] - l[i])

print(c)


Measured memory_bytes: 9148
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int nagasa = scan.nextInt();
		int n = scan.nextInt();
		int i = 0;
		String a = "";

		String[] ary = new String[nagasa];

		for (i = 0; i < nagasa; i++) {
			ary[i] = scan.next();
			//System.out.print(ary[i]);

		}

		Arrays.sort(ary);

		i = 0;

		for (i = 0; i < nagasa; i++) {
			a = a + ary[i];

			//System.out.println(a);

		}

		System.out.println(a);

	}

}

Measured memory_bytes: 24404
#include <stdio.h>

int main (void)
{
    int N;
    int X;
    int T;
    int mod;
    int ans;

    scanf("%d %d %d",&N,&X,&T);

    mod = N % X;
    ans = (N / X) * T;
    if(mod == 0)
    {
        printf("%d", ans);
    }
    else
    {
        ans = ans + T;
        printf("%d", ans);
    }

    return 0;
    
}

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

using namespace std;

typedef long long ll;

long long test_cases;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    /* cin >> test_cases; */
    test_cases = 1;

    ll n, k;
    ll p[1003];
    while (test_cases > 0)
    {

        cin >> n >> k;
        for (int i = 0; i < n; i++)
            cin >> p[i];

        sort(p, p + n);
        ll ans = 0;
        for (int i = 0; i < k; i++)
        {
            ans += p[i];
        }

        cout << ans << endl;
        test_cases--;
    }

    
    return 0;
}

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

#define rep(i,n) for(long long i=0;i<n;++i)

long long extend_gcd(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    } else {
        long long d = extend_gcd(b, a % b, y, x);
        y -= a / b * x;
        return d;
    }
}

int main(){
  long long n;
  scanf("%lld",&n);
  if(n==1<<0 or n==1<<1 or n==1<<2 or n==1<<3
     or n==1<<4 or n==1<<5 or n==1<<6 or n==1<<7
     or n==1<<8 or n==1<<9 or n==1<<10 or n==1<<11
     or n==1<<12 or n==1<<13 or n==1<<14 or n==1<<15
     or n==1<<16 or n==1<<17 or n==1<<18 or n==1<<19
     or n==1<<20 or n==1<<21 or n==1<<22){
    cout << n*2-1 << endl;
    return 0;
  }
  
  vector<long long> primes;
  for(long long i=2;i*i<=n;++i){
    if(n%i==0){
      long long tmp=1;
      while(n%i==0){
        tmp*=i;
        n/=i;
      }
      primes.push_back(tmp);
    }
  }
  if(n!=1){
    primes.push_back(n);
  }
  
  if(primes[0]%2==0){
    primes[0]*=2;
  }
  else{
    primes.push_back(2);
  }
  
  long long ans=1e16;
  for(long long i=0;i<(1<<primes.size());++i){
    long long a=1;
    long long b=1;
    for(int j=0;j<primes.size();++j){
      if(i&(1<<j)){
        a*=primes[j];
      }
      else{
        b*=primes[j];
      }
    }
    if(a==1 or b==1){
      continue;
    }
    long long x=1;
    long long y=1;
    extend_gcd(a,b,x,y);
    long long k=min(a*abs(x),b*abs(y));
    if(k==0){
      continue;
    }
    ans=min(ans,k);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3696
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
void dif(int x,int y,int n,int m,char s[100][100],char a){
  s[x][y]='\0';
  loop(i,-1,2){
    loop(j,-1,2){
      if(!(i&&j)&&x+i>=0&&x+i<n&&y+j>=0&&y+j<m&&s[x+i][y+j]==a)dif(x+i,y+j,n,m,s,a);
       }
    }
    //    cout<<s[0][0]<<endl;
}

int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    int co=0;
    char s[100][100];
    rep(i,n)cin>>s[i];
    rep(i,n)
      rep(j,m)
      if(s[i][j]){co++;dif(i,j,n,m,s,s[i][j]);}
    
    cout<<co<<endl;
  }


}

Measured memory_bytes: 2264
s=input()
t=input()
ans = 0
c = 0
m = 1001

for i in range(len(s)-len(t)+1):
    tmp = s[i:i+len(t)]
    #print(tmp)
    for j in range(len(t)):
        #print(tmp[j],t[j])
        if tmp[j] != t[j]:
            c+=1
        #print(c)
    if m > c:
        m = c
        ans = c
    c=0

print(ans)

Measured memory_bytes: 9132
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  string a[50];
  string b[50];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  bool ok = false;

  for (int sy = 0; sy < n; sy++) {
    if (sy + m > n) {
      break;
    }
    for (int sx = 0; sx < n; sx++) {
      if (sx + m > n) {
        break;
      }

      bool match = true;
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if (a[sy + y][sx + x] != b[y][x]) {
            match = false;
          }
        }
      }
      if (match) {
        ok = true;
      }
    }
  }

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


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  int n;
  cin >> n;
  
  vector<int> ps(n);
  vector<vector<Edge>> graph(n);
  vector<int> out_ds(n);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    p--;
    ps[i] = p;
    graph[p].push_back(Edge(p, i));
    out_ds[p]++;
  }

  auto grundy_fn = [](const vector<vector<Edge>>& graph, const vector<int>& gs, int v) -> int {
    set<int> s;
    for (const auto& e : graph[v]) {
      s.insert(gs[e.to]);
    }
    int c = 0;
    while (true) {
      if (s.find(c) == s.end()) return c;
      c++;
    }
  };

  vector<int> gs(n, -1);
  deque<int> q;
  for (int v = 0; v < n; v++) {
    if (out_ds[v] == 0) {
      q.push_back(v);
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop_front();
    gs[v] = grundy_fn(graph, gs, v);
    out_ds[ps[v]]--;
    if (out_ds[ps[v]] == 0) {
      q.push_back(ps[v]);
    }
  }

  vector<int> cycle;
  for (int v = 0; v < n; v++) {
    if (out_ds[v] > 0) {
      cycle.push_back(v);
      int u = ps[v];
      while (true) {
        cycle.push_back(u);
        u = ps[u];
        if (u == v) break;
      }
      break;
    }
  }
  reverse(cycle.begin(), cycle.end());

  if (cycle.empty()) {
    cerr << "Unexpected: No cycle!" << endl;
    exit(1);
  }

  if (DEBUG) cout << "cycle: " << cycle << endl;

  int v1 = cycle[cycle.size() - 1];
  vector<int> g1s;
  {
    set<int> s;
    for (const auto& e : graph[v1]) {
      s.insert(gs[e.to]);
    }
    int c = 0;
    while (true) {
      if (s.find(c) == s.end()) {
        g1s.push_back(c);
        if (g1s.size() == 2) break;
      }
      c++;
    }
  }

  bool ans = false;
  for (int g1 : g1s) {
    vector<int> hs(gs.begin(), gs.end());
    hs[v1] = g1;
    for (int i = cycle.size() - 2; i >= 0; i--) {
      hs[cycle[i]] = grundy_fn(graph, hs, cycle[i]);
    }
    if (grundy_fn(graph, hs, v1) == hs[v1]) {
      if (DEBUG) {
        cout << "v1: " << v1 << " hs[v1]: " << hs[v1] << " grundy: " << grundy_fn(graph, hs, v1) << endl;
      }
      ans = true;
    }
  }

  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 14068
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 2 * 1000 + 2;
int ix, iy, rects[N+1][N+1], vis[N+1][N+1];
void increment(int x1, int y1, int x2, int y2) {
    rects[x1][y1]++;
    rects[x1][y2]--;
    rects[x2][y1]--;
    rects[x2][y2]++;
}
void psum(int w, int h) {
    for(int x = 0; x < w; x++) {
        for(int y = 0; y < h; y++) {
            rects[x][y] += x ? rects[x-1][y] : 0;
            rects[x][y] += y ? rects[x][y-1] : 0;
            rects[x][y] -= x and y ? rects[x-1][y-1] : 0;
        }
    }
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void dfs(int w, int h, int x, int y) {
    vis[x][y] = true;
    for(int d = 0; d < 4; d++) {
        int nx = x + dx[d], ny = y + dy[d];
        if(0 <= nx and nx < w and 0 <= ny and ny < h and not vis[nx][ny] and not rects[nx][ny]) {
            dfs(w, h, nx, ny);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int w, h;
    while(cin >> w >> h and w and h) {
        int n;
        cin >> n;
        vector<int> x1(n), y1(n), x2(n), y2(n);
        set<int> xs = {0, w}, ys = {0, h};
        for(int i = 0; i < n; i++) {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            xs.insert({x1[i], x2[i]});
            ys.insert({y1[i], y2[i]});
        }
        map<int, int> idx, idy;
        ix = 0, iy = 0;
        for(int x : xs) {
            idx[x] = ix++;
        }
        for(int y : ys) {
            idy[y] = iy++;
        }
        for(int x = 0; x < idx[w]; x++) {
            for(int y = 0; y < idy[h]; y++) {
                rects[x][y] = vis[x][y] = 0;
            }
        }
        for(int i = 0; i < n; i++) {
            increment(idx[x1[i]], idy[y1[i]], idx[x2[i]], idy[y2[i]]);
        }
        psum(idx[w], idy[h]);
        int ans = 0;
        for(int x = 0; x < idx[w]; x++) {
            for(int y = 0; y < idy[h]; y++) {
                if(not vis[x][y] and not rects[x][y]) {
                    dfs(idx[w], idy[h], x, y);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  int N, a=0;
  cin >> N;
  vector<string> S(N);
  rep(i, N){
    cin >> S.at(i);
    if(i==0) continue;
    if(S.at(i).at(0)!=S.at(i-1).at(S.at(i-1).size()-1)){
      a=1;
      break;
    }
    rep(j,i){
      if(S.at(i)==S.at(j)){
        a=1;
        break;
      }
    }
    if(a==1) break;
  }
  if(a==1) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(input())
    x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(x[K - 1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
import java.util.Scanner;

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

    int L = scanner.nextInt();
    int[] a = new int[L + 1];
    for (int i = 1; i <= L; i++) a[i] = scanner.nextInt();

    long[][] dp = new long[L + 1][5];
    for (int i = 1; i <= L; i++) {
      int f = a[i] % 2 == 0 ? 0 : 1;
      if (a[i] == 0) f = 2;
      int g = a[i] % 2 == 1 ? 0 : 1;

      dp[i][0] = dp[i - 1][0] + a[i];
      dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + f;
      dp[i][2] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + g;
      dp[i][3] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2], dp[i - 1][3]) + f;
      dp[i][4] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2], dp[i - 1][3], dp[i - 1][4]) + a[i];
    }

    long min = dp[L][0];
    for (int i = 1; i < 5; i++) min = Math.min(min, dp[L][i]);
    System.out.println(min);
  }

  private static long min(long... args) {
    long m = Long.MAX_VALUE;
    for (long a : args) m = Math.min(m, a);
    return m;
  }
}


Measured memory_bytes: 105412
while True:
    x,y,s = map(int,input().split())
    if x == 0:
        break
    ans = 0
    for i in range(1,s+1):
        for j in range(i,s+1):
            komi_mae = i * (100 + x) // 100 + j * (100 + x) // 100
            if komi_mae == s:
                komi_now = i * (100 + y) // 100 + j * (100 + y) // 100
                ans = max(ans,komi_now)
    print(ans)


Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

 
void solve(){
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    vi ans;
    for(int i = 1; i <= min(a, b); i++){
        if(a % i == 0 && b % i == 0){
            ans.push_back(i);
        }
    }
    sort(all(ans));
    cout << ans[ans.size() - k];
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


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

std::vector<long long> wv[4];
long long w0;

long long v_max(int, long long);

int main()
{
	int n;
	long long w_limit;
	scanf("%d%lld", &n, &w_limit);

	for (int i = 0; i < n; i++)
	{
		long long tmp_w, tmp_v;
		scanf("%lld%lld", &tmp_w, &tmp_v);
		if (!i) w0 = tmp_w;
		wv[tmp_w - w0].push_back(tmp_v);
	}
	for (int i = 0; i < 4; i++)
		std::sort(wv[i].rbegin(), wv[i].rend());
	
	printf("%lld\n", v_max(0, w_limit));

	return 0;
}

long long v_max(int index, long long w_limit)
{
	if (index == 4) return 0;

	long long max{v_max(index + 1, w_limit)}, v_sum{};
	for (auto &e: wv[index])
	{
		v_sum += e;
		w_limit -= w0 + index;
		if (w_limit < 0) break;
		max = std::max(max, v_max(index + 1, w_limit) + v_sum);
	}
	return max;
}

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

int main(){
  int W,a,b;
  cin >> W >> a >> b;
  if(a+W <= b){
    cout << b-a-W;
  }
  else if(b+W <= a){
    cout << a-b-W;
  }
  else{
    cout <<0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        if(i%2==0 && t%2==1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;


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

    int N;int Y;
    scanf("%d %d",&N,&Y);
    bool isOk=false;

    for(int x=0;x<=N;x++){
        for(int y=N-x;y>=0;y--){
            for(int z=N-(x+y);z>=0;z--){
                if(x+y+z==N&&10000*x+5000*y+1000*z==Y){
                    printf("%d %d %d",x,y,z);
                    isOk=true;
                    goto LAST;
                }
            }
        }
    }

    printf("-1 -1 -1\n");

    LAST:


    return 0;
}

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

int main() {
	int N;
	long long W;
	cin >> N >> W;
	long long w[N], v[N];
	for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
	long long dp[110][100010] = { 0 };
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j >= w[i]) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
			else {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			}
		}
	}
	cout << dp[N][W] << endl;
}
	

Measured memory_bytes: 86144
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int n,m,pa[200005],num1[200005],num2[200005];
bool a[405][405];
ll ans;
inline bool read()
{
	char c=getchar();
	while(c!='#'&&c!='.')c=getchar();
	return c=='#';
}
int find(int x)
{
	return x==pa[x]?x:pa[x]=find(pa[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	{
		a[i][j]=read();
		if(a[i][j])num1[i*m+j+1]++;
		else num2[i*m+j+1]++;
		pa[i*m+j+1]=i*m+j+1;
	}
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	{
		if(i!=n-1&&(a[i][j]^a[i+1][j]))
		{
			int u=find(i*m+j+1),v=find((i+1)*m+j+1);
			if(u!=v)
			{
				num1[u]+=num1[v];
				num2[u]+=num2[v];
				pa[v]=u;
			}
		}
		if(j!=m-1&&(a[i][j]^a[i][j+1]))
		{
			int u=find(i*m+j+1),v=find(i*m+j+1+1);
			if(u!=v)
			{
				num1[u]+=num1[v];
				num2[u]+=num2[v];
				pa[v]=u;
			}
		}
	}
	for(int i=1;i<=n*m;i++)
	  if(find(i)==i)
	    ans+=1ll*num1[i]*num2[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176