akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

std::vector<int> bipartite(std::vector<std::pair<int,int>> edge){
    int E = edge.size();
    if(E==0)return {};
    int V = 0;
    for(int i=0;i<E;i++){
        V=std::max(V,edge[i].first+1);
        V=std::max(V,edge[i].second+1);
    }
    std::vector<int> R(V,-1);
    std::vector<int> S(0);
    std::vector<std::vector<int>> es(V,std::vector<int>(0));
    for(int i=0;i<E;i++){
        es[edge[i].first].push_back(edge[i].second);
        es[edge[i].second].push_back(edge[i].first);
    }
    std::queue<int> Q;
    std::vector<bool> visited(V,false);
    for(int j=0;j<V;j++){
        if(visited[j])continue;
        Q.push(j);
        R[j]=0;
        visited[j]=true;
        while(!Q.empty()){
            int q=Q.front();
            Q.pop();
            visited[q]=true;
            for(int i=0;i<es[q].size();i++){
                if(R[es[q][i]]==R[q]){
                    return S;
                }
                if(visited[es[q][i]])continue;
                Q.push(es[q][i]);
                R[es[q][i]]=1-R[q];
            }
        }
    }
    return R;
}

signed main(void){
    int N,M,a,b;
    vector<pair<int,int>> AB;
    cin >> N >> M;
    REP(i,M){
        cin >> a >> b;
        a--;b--;
        AB.push_back({a,b});
    }
    vector<int> E = bipartite(AB);
    int x=0,y=0;
    REP(i,E.size()){
        if(E[i]==0){
            x++;
        }else{
            y++;
        }
    }
    if(x==0 || y==0){
        cout << N*(N-1)/2 - M << endl;
    }else{
        cout << x*y - M << endl;
    }
    return 0;
}



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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        bool l=false,r=false,p=false;
        int cnt = 0;
        REP(i,n){
            string s;
            cin >> s;
            if(s[0]=='l'){
                if(s[1]=='u'){
                    l = true;
                }
                else{
                    l = false;
                }
            }
            else{
                if(s[1]=='u'){
                    r = true;
                }
                else{
                    r = false;
                }
            }
            if(l==r && l!=p){
                cnt++;
                p=l;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}



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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int gcd(int a, int b) {
	if (a == 0 || b == 0)
		return a + b;
	return gcd(b, a % b);
}

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	int n, k;
	cin >> n >> k;
	int g = 0;
	int maxx = 0;
	forn(i, n) {
		int a;
		cin >> a;
		umx(maxx, a);
		g = gcd(g, a);
	}
	if (maxx >= k && (maxx - k) % g == 0) {
		puts("POSSIBLE");
	} else {
		puts("IMPOSSIBLE");
	}
	
	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++)
			sb.append('x');
		pw.println(sb);
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define MOD 998244353

using namespace std;

int main()
{
    IOS;
    int n,d;
    cin>>n>>d;
    int x[n][d];
    repf(i,0,n) 
    {
        repf(j,0,d) cin>>x[i][j];
    }
    int ans=0;
    repf(i,0,n)
    {
        repf(j,i+1,n)
        {
            ll v=0;
            repf(k,0,d) v+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            ll srt=sqrt(v);
            if(srt*srt==v) ans++;
        }
    }
    cout<<ans<<endl;
}
 

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#define maxn 131080
#define LL long long
#define x first
#define y second
using namespace std;
typedef pair<LL,LL> PLL;
int n,fa[maxn];
LL mv[maxn];
vector<PLL> f[maxn];
struct node { int v,w; node *nxt; } edge[maxn],*head[maxn],*ncnt;
void addedge(int u,int v,int w)
{
	ncnt++;
	ncnt->v=v,ncnt->w=w,ncnt->nxt=head[u];
	head[u]=ncnt;
}
bool cmpx(PLL a,PLL b){return a.first<b.first;}
bool cmpy(PLL a,PLL b){return a.second<b.second;}
void work(vector<PLL> &ls,vector<PLL> &rs,vector<PLL> &f,LL mid)
{
    if(ls.size()>rs.size()) swap(ls,rs);
    int el=ls.size(),er=rs.size();
    sort(ls.begin(),ls.end(),cmpy);
    sort(rs.begin(),rs.end(),cmpx);
    mv[0]=rs[0].second;
    for(int i=1;i<er;i++) mv[i]=min(mv[i-1],rs[i].second);
    for(int i=0,j=er-1;i<el;i++)
    {
        while(j>=0&&ls[i].second+rs[j].first>mid) j--;
        if(j>=0) f.push_back(PLL(ls[i].first,mv[j]));
    }
    sort(ls.begin(),ls.end(),cmpx);
    sort(rs.begin(),rs.end(),cmpy);
    mv[0]=rs[0].first;
    for(int i=1;i<er;i++) mv[i]=min(mv[i-1],rs[i].first);
    for(int i=0,j=er-1;i<el;i++)
    {
        while(j>=0&&ls[i].first+rs[j].second>mid) j--;
        if(j>=0) f.push_back(PLL(mv[j],ls[i].second));
    }
}
void dfs(int u,LL mid)
{
	f[u].clear();
	if(!head[u]) { f[u].push_back(PLL(0,0)); return; }
	int lc=head[u]->v,rc=head[u]->nxt->v;
	int lw=head[u]->w,rw=head[u]->nxt->w;
	dfs(lc,mid); dfs(rc,mid);
	vector<PLL> &ls=f[lc];
	for(int i=0,siz=ls.size(),c=lw;i<siz;i++)
		ls[i].first+=c,ls[i].second+=c;
	vector<PLL> &rs=f[rc];
	for(int i=0,siz=rs.size(),c=rw;i<siz;i++)
		rs[i].first+=c,rs[i].second+=c;
	work(ls,rs,f[u],mid);
	ls.clear(); rs.clear();
}
LL BS()
{
	LL l=-1,r=(LL)1e10;
	while(l+1<r)
	{
		int mid=(l+r)/2; dfs(1,mid);
		if(f[1].empty()) l=mid;
		else r=mid;
	}
	return r;
}
int main()
{
	ncnt=&edge[0];
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int w;
		scanf("%d%d",&fa[i],&w);
		addedge(fa[i],i,w);
	}
	printf("%lld\n",BS());
}

Measured memory_bytes: 29172
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.BitSet;
import java.io.IOException;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.lang.StringBuffer;
import java.lang.String;
import java.lang.StringBuilder;


public class Main {

    static BigInteger modulo = new BigInteger("1000000007");
//    Nested ststic class FastReaders

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

        public String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException io) {
                io.printStackTrace();
            }
            return s;
        }
    }

    static BigInteger exponentialModulo(BigInteger a, BigInteger b) {
        BigInteger previousNumber = BigInteger.ONE;
        while (!(b.equals(BigInteger.valueOf(0)))) {
            if (b.testBit(0)) {
                previousNumber = previousNumber.multiply(a).mod(modulo);
            }
            b = b.shiftRight(1);
            a = a.modPow(BigInteger.valueOf(2), modulo);
        }
        return previousNumber;
    }

    public static int encodeInteger(int x, int n) {
        n = n << (1 << (1 << (1 << 1)));
        x = x | n;
        return x;
    }

    public static void encodeArray(int[] A, int[] B, int n) {
        for (int i = 0; i < n; i++) {
            A[i] = encodeInteger(A[i], B[i]);
        }
    }

    public static void main(String[] args) throws IOException {
        FastReader input = new FastReader();      
        int n = input.nextInt();
        int k = input.nextInt();
        System.out.println(n-k+1);      
    }

}


Measured memory_bytes: 21332
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  ll n, m;
  ll sum = 0;
  cin >> n >> m;
  if (2 * n == m) {
    sum = n;
  } else if (2 * n > m) {
    sum = m / 2;
  } else {
    m = m - 2 * n;
    sum = n + m / 4;
  }

  cout << sum << endl;
}

Measured memory_bytes: 3604
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine

simulate table a b c = do
  let s = ((a + b) ^ 2 + (b + c) ^ 2 + (c + a) ^ 2) `div` 2
  if s <= 10000
    then do
      p <- VUM.read table s
      if a == b && b == c
        then VUM.write table s (p + 1)
        else
          if a == b || b == c
            then VUM.write table s (p + 3)
            else VUM.write table s (p + 6)
      simulate table a b (c + 1)
    else do
      let s' = ((a + b + 1) ^ 2 + (b + b + 1) ^ 2 + (b + 1 + a) ^ 2) `div` 2
      if s' <= 10000
        then simulate table a (b + 1) (b + 1)
        else do
          let s'' = (a * 2 + 1) ^ 2 `div` 2
          when (s'' <= 10000) $ simulate table (a + 1) (a + 1) (a + 1)

main = do
  n <- getInt
  let n2 = [1 .. 100]
  table <- VUM.replicate 100001 0 :: IO (VUM.IOVector Int)
  simulate table 1 1 1
  vu <- VU.freeze table
  VU.mapM_ print (VU.take n (VU.tail vu))


Measured memory_bytes: 6304
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    if (n % 2 == 1) {
        for (int i = 0; i < m; i++) {
            cout << i + 1 << " " << n - i << "\n";
        }
    } else {
        int m1 = (m + 1) / 2;
        int m2 = m - m1;
        for (int i = 0; i < m1; i++) {
            cout << i + 1 << " " << 2 * m1 - i << "\n";
        }
        for (int i = 0; i < m2; i++) {
            cout << 2 * m1 + i + 1 << " " << 2 * m1 + 2 * m2 + 1 - i << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s, t; cin>>s>>t;
	int ans=0;
	for(int i=0; i<3; i++){
		if(s[i]==t[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//
// Created by chuan on 2020-04-10.
//

#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <numeric>

using ll = long long;
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);

    int N,M; cin>>N>>M;
    vector<int> A(M);
    for (auto& a: A) {
        cin>>a;
    }

    int s = accumulate(A.begin(), A.end(), 0);
    if (s <= N) cout<<N-s<<endl;
    else cout<<"-1"<<endl;

    return 0;
}



Measured memory_bytes: 3660
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  let height_list = [0];
  let current_height = 0;

  // 初めの上昇を削除
  while(line[0] === '/')line.shift();
  // 終わりの下降を削除
  while(line[line.length - 1] === '\\')line.pop();
  line.forEach(function(e, i){
      if (e === '\\') current_height -= 1
      else if (e === '_') current_height += 0
      else current_height += 1
      height_list.push(current_height);
  });

  // console.log(height_list.join(','));
  let sum = 0;
  let holes = [];
  for (;height_list.length > 1;) {
    let h = makeHole(height_list);
    if (h > 0) {
      sum += h;
      holes.push(h);
      // console.log(h, height_list.join(','));
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (begin <= list.reduce((a, b) => Math.max(a, b), -100000)) {
      area = 0;
      while (true) {
      if (list.length == 0 || begin <= list[0]) break;
        area += begin - list.shift();
      }
      return area;
    } else {
      return 0;
    }
}



Measured memory_bytes: 21044
N,A = map(int,input().split())
ls1 = [0] + list(map(int,input().split()))

dp = [[[0 for k in range(2600)] for j in range(51) ] for i in range(51)]
for i in range(51):
    dp[i][0][0] = 1
for j in range(1,N+1):
    for k in range(1,j+1):
        for s in range(2600):
            if s < ls1[j]:
                dp[j][k][s] = dp[j-1][k][s]
            elif s >= ls1[j]:
                dp[j][k][s] = dp[j-1][k-1][s-ls1[j]] + dp[j-1][k][s]
ans = 0
for k in range(1,N+1):
    ans += dp[N][k][k*A]
print(ans)


Measured memory_bytes: 71656
#include <bits/stdc++.h>
#define NMAX 1009
using namespace std;
int n,m;
int nrop;
char a[NMAX][NMAX];
int uz[NMAX][NMAX];
int dl[]={-1,0,1,0};
int dc[]={0,1,0,-1};
char c;
int i,j;
int cate;
void lee();
void bord();
struct poz{int lin; int col;};
poz C[NMAX*NMAX];
int inc=1,sf=0;
bool e=0;
int main()
{cin>>n>>m;
 bord();
 for(i=1;i<=n;i++)
     for(j=1;j<=m;j++)
        {
         cin>>a[i][j];
         ///. e white
        }

 for(i=1;i<=n;i++)
     for(j=1;j<=m;j++)
        {
         if(a[i][j]=='#')
         {e=0;
             for(int ct=0;ct<4;ct++)
                     if(a[i+dl[ct]][j+dc[ct]]=='.')
                         e=1;
           if(e)
           {C[++sf]={i,j};uz[i][j]=0;}
         ///. e white
        }
        }
  lee();
  for(i=1;i<=n;i++)
    {for(j=1;j<=m;j++)
         if(uz[i][j]>cate)
            cate=uz[i][j];
    }
  cout<<cate;
    return 0;
}

void bord()
{
  int i;
  for(i=0;i<=n+1;i++)
         uz[i][0]=uz[i][m+1]=1;

  for(i=0;i<=m+1;i++)
         uz[0][i]=uz[n+1][i]=1;
}
void lee()
{int i;
  while(inc<=sf)
        {
         poz act;
         act=C[inc++];
         for(i=0;i<4;i++)
             if(a[act.lin+dl[i]][act.col+dc[i]]=='.')
                {
                 a[act.lin+dl[i]][act.col+dc[i]]='#';
                 uz[act.lin+dl[i]][act.col+dc[i]]=uz[act.lin][act.col]+1;
                 C[++sf]={act.lin+dl[i],act.col+dc[i]};
                }
        }
}


Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
int main(int argc, char* argv[] ){
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll m = max( {A,B,C} );
  cout << ( (m<<K) + ( A+B+C ) - m ) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> tup;

int main(){
    int N;  cin >> N;
    vector<tup> infs(N);
    for(int i=0; i<N; i++){
        int x, y, h;  cin >> x >> y >> h;
        infs[i] = tup(h,x,y);
    }
    sort(infs.begin(), infs.end());

    for(int iCx=0; iCx<=100; iCx++){
        for(int iCy=0; iCy<=100; iCy++){
            int h = get<0>(infs[N-1]);
            int x = get<1>(infs[N-1]);
            int y = get<2>(infs[N-1]);

            int dH = abs(iCx-x) + abs(iCy-y);
            int H = h + dH;
            bool flag = true;
            for(int i=0; i<N-1; i++){
                int hi = get<0>(infs[i]);
                int xi = get<1>(infs[i]);
                int yi = get<2>(infs[i]);
                if(hi != max( H - abs(xi-iCx) - abs(yi-iCy) ,0)){
                    flag = false;
                    break;
                }
            }
            if(flag){
                cout << iCx << " " << iCy << " " << H << endl;
            }
        }
    }
}


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

int main() {
	long long		a,b,c,i,j,k,n,m,x,y,ans = 0;
	
	
	cin >> n >> a >> b;
	
	c = n / (a + b);
	i = n % (a + b);
	
	if ( i >= a  ) {
		ans = c * a + a;
	} else {
		ans = c * a + i;
	}
	
	cout << ans << endl;


}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

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

		 int n = s.nextInt();
		 HashMap map = new HashMap();

		 int tmp = 0;
		 for(int x = 1; x < 100; x++) {
			 for(int y = 1; y < 100; y++) {
				 for(int z = 1; z < 100; z++) {
					 tmp = x*x + y*y + z*z + x*y + y*z + z*x;
					 if(tmp > n) {
						 break;
					 }
					 Integer val = (Integer)map.get(Integer.valueOf(tmp));
					 if(val == null) {
						 val = 1;
					 } else {
						 val++;
					 }
					 map.put(tmp, val);
				 }
			 }
		 }

		 for(int i = 1; i <= n; i++) {
			 Integer val = (Integer)map.get(Integer.valueOf(i));
			 if(val == null) {
				 val = 0;
			 }
			 System.out.println(val);
		 }
	}
}

Measured memory_bytes: 38420
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
int X[4]={0,0,1,-1};
int Y[4]={1,-1,0,0};
int main(){
    int n,m,k;
    scanf("%d %d %d",&n,&m,&k);
    char c[1005][1005];
    MEM(c);
    pii s;
    for(int i = 1;i<=n;i++){
        scanf("%s",c[i]+1);
        for(int j=1;j<=m;j++){
            if(c[i][j]=='S')
                s=mp(i,j);
        }
    }
    int dis[805][805];
    MEMS(dis);
    queue<pii> q;
    q.push(s);
    dis[s.x][s.y]=0;
    while(!q.empty()){
        pii p=q.front();
        q.pop();
        for(int i = 0;i<4;i++){
            int x=p.x+X[i],y=p.y+Y[i];
            if(dis[x][y]==-1&&c[x][y]=='.'){
                dis[x][y]=dis[p.x][p.y]+1;
                q.push(mp(x,y));
            }
        }
    }
    int ans=1e9;
    for(int i = 1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(dis[i][j]<=k&&dis[i][j]!=-1){
              //  q.push(mp(i,j));
            //  printf("%d %d\n",i,j);
                int Min=min(min(i-1,n-i),min(j-1,m-j));
                ans=min((Min+k-1)/k+1,ans);
            }
            //dis[i][j]=-1;
        }
    }
    printf("%d\n",ans);
}
/*
1-n 0
2-n 1
3-n 2
-3 0
-2 1
-1 2
0 3
*/
/*
1 0
2 -10  01
3 -20 -1 1 0 2


*/
/*

k*cnt[i]-k*cnt[j]=i-j;
k*cnt[i]-i=k*cnt[j]-j
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5    3
1 2 3 5 6    4 
1 2 3 4 6
3
0 1 2
0 2 2.5

1 2 3 4 5
1 2 3 4 5
1 3
1 4
1
*/
/*
AC
AGCG
AGCGU
AT
*/

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    const ll MOD = 998244353;
    ll N, S;
    cin >> N >> S;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;

    vector<ll> dp(S+1);
    ll ans = 0;
    for(int i=0; i<N; i++){
        ll p = dp[S];
        for(int j=S; j>=0; j--){
            if(j-A[i]>0) dp[j] += dp[j-A[i]];
            if(j-A[i]==0) dp[j] += i+1;
            dp[j] %= MOD;
        }
        ll n = dp[S] - p;
        if(n<0) n += MOD;
        ans += n * (N-i);
        ans %= MOD;
        // debug(dp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


template <typename T>
T gcd(T a, T b) {
    while (b != 0) {
        T c = a;
        a = b;
        b = c % b;
    }
    return a;
}

template <typename T>
vector<T> prime_factorize(T num) {
    assert(num > 1);
    vector<T> factor;
    T n = sqrt(num) + 1;
    for (T i = 2; i < n; ++i) {
        while (num % i == 0) {
            num /= i;
            factor.push_back(i);
        }
    }
    if (num > 1) {
        factor.push_back(num);
    }
    return factor;
}

map<ll, vector<ll>> cache;
map<ll, vector<ll>> F;

int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A;
    rep (i, N) {
        ll a;
        cin >> a;
        A.pb(a);
    }
    for (ll a : A) {
        if (a > 1) {
            if (!cache.count(a)) {
                cache[a] = prime_factorize(a);
            }
            for (ll p : cache[a]) {
                F[p].pb(a);
            }
        }
        F[1].pb(a);
    }
    ll ans = 1;
    for (auto f : F) {
        if (f.snd.size() >= A.size() - 1) {
            ll g = f.snd[0];
            for (ll x : f.snd) {
                g = gcd(g, x);
            }
            ans = max(ans, g);
        }
    }
    cout << ans << endl;
}


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

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

typedef long long LL;
struct Edge {
    int u, v;
    LL cap, flow;
    Edge() {}
    Edge(int u, int v, LL cap): u(u), v(v), cap(cap), flow(0) {}
};

struct Dinic{
    int N;
    vector<Edge> E;
    vector<vector<int>> g;
    vector<int> d, pt;
  
    Dinic(int N): N(N), E(0), g(N), d(N), pt(N) {}

    void AddEdge(int u, int v, LL cap){
        if (u != v){
            E.emplace_back(Edge(u, v, cap));
            g[u].emplace_back(E.size() - 1);
            E.emplace_back(Edge(v, u, 0));
            g[v].emplace_back(E.size() - 1);
        }
    }

    bool BFS(int S, int T){
        queue<int> q({S});
        fill(d.begin(), d.end(), N + 1);
        d[S] = 0;
        while(!q.empty()){
            int u = q.front(); q.pop();
            if (u == T) break;
            for (int k: g[u]) {
                Edge &e = E[k];
                if (e.flow < e.cap && d[e.v] > d[e.u] + 1){
                    d[e.v] = d[e.u] + 1;
                    q.emplace(e.v);
                }
            }
        }
        return d[T] != N + 1;
    }

    LL DFS(int u, int T, LL flow = -1){
        if (u == T || flow == 0) return flow;
        for (int &i = pt[u]; i < g[u].size(); ++i){
            Edge &e = E[g[u][i]];
            Edge &oe = E[g[u][i]^1];
            if (d[e.v] == d[e.u] + 1){
                LL amt = e.cap - e.flow;
                if (flow != -1 && amt > flow) amt = flow;
                if (LL pushed = DFS(e.v, T, amt)) {
                    e.flow += pushed;
                    oe.flow -= pushed;
                    return pushed;
                }
            }
        }
        return 0;
    }

    LL MaxFlow(int S, int T){
        LL total = 0;
        while (BFS(S, T)){
            fill(pt.begin(), pt.end(), 0);
            while (LL flow = DFS(S, T)) total += flow;
        }
        return total;
    }
};
char s[105][105];
int main(){
    int h, w, sy, sx, ty, tx;
    scanf("%d%d", &h, &w);
    for(int i=1;i<=h;i++){
        scanf("%s", s[i]+1);
        for(int j=1;j<=w;j++){
            if(s[i][j] == 'S') sy = i, sx = j;
            else if(s[i][j] == 'T') ty = i, tx = j;
        }
    }
    if(sy == ty || sx == tx) printf("-1\n");
    else{
        Dinic dinic(h+w+2);
        int source = 0, sink = h+w+1;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(s[i][j] == 'o'){
                    dinic.AddEdge(i, h+j, 1);
                    dinic.AddEdge(h+j, i, 1);
                }
                else if(s[i][j] == 'S'){
                    dinic.AddEdge(source, i, 1e9);
                    dinic.AddEdge(source, h+j, 1e9);
                }
                else if(s[i][j] == 'T'){
                    dinic.AddEdge(i, sink, 1e9);
                    dinic.AddEdge(h+j, sink, 1e9);
                }
            }
        }
        printf("%lld\n", dinic.MaxFlow(source, sink));
    }
}

Measured memory_bytes: 1940
S = input()
K = int(input())

ans = ""
for i in range(len(S)):
    if ord("z") - ord(S[i]) + 1 <= K and i != len(S) - 1:
        ans += "a"
        if S[i] == "a":
            continue
        K -= ord("z") + 1 - ord(S[i])
    elif i == len(S) - 1:
       K %= 26
       if ord("z") - ord(S[i]) + 1 <= K:
            K -= ord("z") + 1 - ord(S[i]) 
            ans += chr(ord("a") + K)
       else:
            ans += chr( ord(S[i]) + K)
    else:
        ans += S[i]

print(ans)


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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int []X = new int[N];
		for(int i = 0; i < N; i++) {
			X[i] = scan.nextInt();
		}
		scan.close();
		int []A = new int[N];
		System.arraycopy(X, 0, A, 0, N);
		Arrays.sort(A);
		int m1 = A[N / 2 - 1];
		int m2 = A[N / 2];
		for(int i = 0; i < N; i++) {
			if(X[i] > m1) {
				System.out.println(m1);
			}else {
				System.out.println(m2);
			}
		}

	}
}

Measured memory_bytes: 89408
burgerLens = [1 + 4 * (1 - 2**i)/(1-2) for i in range(0,51)]
numPatties = [1 + 2 * (1 - 2**i)/(1-2) for i in range(0,51)]

def recurse(n,k):
    if n == 0:
        return numPatties[0]
    if k <= n:
        return 0
    
    mid = burgerLens[n] // 2 + 1
    if k == mid:
        return 1 + numPatties[n-1]
    if k < mid:
        return recurse(n-1,k-1)
    if k > mid:
        return 1 + numPatties[n-1] + recurse(n-1,k-2-burgerLens[n-1])
    
N,K = map(int,input().split())
print(int(recurse(N,K)))

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = s[0];
            int B = s[1];
            if (A>=13)
            {
                WriteLine(B);
            }
            else if (A>=6)
            {
                WriteLine(B / 2);
            }
            else
            {
                WriteLine(0);
            }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N, K;
	cin >> N >> K;
	vector<ll>num(K, 0);
	for (int i = 1; i <= N; ++i) {
		num[i%K]++;
	}
	ll res = 0;
	for (int a = 0; a < K; ++a) {
		int b = (K - a) % K;
		int c = (K - a) % K;
		if ((b + c) % K != 0)continue;
		res += num[a] * num[b] * num[c];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array

main :: IO ()
main = do
  n <- getl toInt
  when (n /= 0) $ do
    m <- getl toInt
    l <- getl toInt
    d <- getl toInt
    xs <- rgetl d id
    putStrLn $ solve n m l d xs
    main
    
solve :: Int -> Int -> Int -> Int -> [String] -> String
solve n m l d xs
  | goal lots d m == l = "0"
  | null rs = "1"
  | otherwise = (show .fst . head) rs ++ " " ++ (show . snd . head) rs
  where
    rs = [(i,j) | i <- [1..d], j <- [1..n-1], lots ! (i, j-1) == '0', lots ! (i, j) == '0', lots ! (i, j+1) == '0', goal (lots // [((i,j),'1')]) d m == l ]
    lots = array ((1,0),(d,n)) els
    els = [((i,0),'0')|i <- [1..d]] ++ [((i,n),'0')|i <- [1..d]] ++ [((i,j), xs !! (i-1) !! (j-1))|i <- [1..d], j <- [1..n-1]]

goal :: Array (Int,Int) Char -> Int -> Int -> Int
goal arr d s = foldl f s [1..d]
  where
    f c r
      | arr ! (r, c-1) == '1' = c-1
      | arr ! (r, c) == '1' = c+1
      | otherwise = c
          
toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

rgetl :: Int -> (String -> a) -> IO [a]
rgetl n f = map f <$> replicateM n getLine

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

string s[12];
int r[12],c[12];

int n,m;
bool dfs2(int x){
	if(x==m)
		return true;
	if(c[x]!=-1)
		return dfs2(x+1);
	int parity=0;
	for(int i=x;i<m;i++)
		if(c[i]==-1)
			parity++;
	for(int i=x;i<m;i++){
		if(c[i]==-1){
			bool available=true;
			c[i]=x;c[x]=i;
			for(int j=0;j<n;j++)
				if(s[j][i]!=s[r[j]][x]||s[r[j]][i]!=s[j][x]){
					available=false;
					break;
				}
			if(available)
				if((parity&1)||i!=x)
					if(dfs2(x+1))
						return true;
			c[i]=c[x]=-1;
		}
	}
	return false;
}
bool dfs1(int x){
	if(x==n)
		return dfs2(0);
	if(r[x]!=-1)
		return dfs1(x+1);
	int parity=0;
	for(int i=x;i<n;i++)
		if(r[i]==-1)
			parity++;
	for(int i=x;i<n;i++){
		if(r[i]==-1){
			r[x]=i;r[i]=x;
			if((parity&1)||i!=x)
				if(dfs1(x+1))
					return true;
			r[x]=r[i]=-1;
		}
	}
	return false;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	memset(r,-1,sizeof r);
	memset(c,-1,sizeof c);
	if(dfs1(0))
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define NUM_COUNT 3

int asc(const void* p1, const void* p2){
	return (*(int*)p1) - (*(int*)p2);
}

int main(int argc, char **argv){
	int data[NUM_COUNT];
	int i;
	
	for(i=0;i<NUM_COUNT;i++){
		scanf("%d",data+i);
	}
	
	qsort( data, NUM_COUNT, sizeof(int), asc);

	for(i=0;i<NUM_COUNT;i++){
		if( i < NUM_COUNT-1 ){
			printf("%d ",data[i]);
		} else {
			printf("%d\n",data[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+4;
typedef long long ll;
int n;
ll ans;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

int main() {
	n=read();
	for (register int i=1;i<=n;++i)
		ans+=1ll*i*(n-i+1);
	for (register int i=1;i<n;++i) {
		int u=read(),v=read();
		if (u>v) u^=v^=u^=v;
		ans-=1ll*u*(n-v+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int n,a[11];
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	int sum=0;
	int mx=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
		mx=max(mx,a[i]);
	}sum-=mx;
	if(mx<sum)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
#include <string.h>

using namespace std;

const int MOD = 998244353;

int me[3001][3001];
int a[3000];
int n,s;

int dp(int ac, int r){
	if(me[ac][r]!=-1)return me[ac][r];
	if(r==0)return me[ac][r]=n-ac+1;
	if(ac==n)return me[ac][r]=0;
	me[ac][r] = dp(ac+1,r);
	if(a[ac]<=r)me[ac][r] = (me[ac][r] + dp(ac+1,r-a[ac]))%MOD;
	return me[ac][r];
}

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin>>n>>s;
	for(int i=0;i<n;i++)cin>>a[i];
	long long res = 0,i;
	memset(me,-1,sizeof me);
	for(i=0;i<n;i++)if(a[i]<=s){
		res = (res + (i+1)*dp(i+1,s-a[i]))%MOD;
	}
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 36088
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}


bool isPrime(ll n) {
  if(n == 1)return false;
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}

// TODO: write
int main() {
  int n,k,r,s,p;cin>>n>>k>>r>>s>>p;
  string t;cin>>t;
  
  ll ans = 0;
  rep(i,n){
    if(i+k < n && t[i] == t[i+k])t[i+k] = 'b';
    if(t[i] == 'r')ans+=p;
    if(t[i] == 's')ans+=r;
    if(t[i] == 'p')ans+=s;

  }
  print(ans);
  return 0; 
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N == 1 || N == 2 || N ==3 || N ==5 || N ==6 || N == 9 || N == 10
    || N == 13 || N == 17){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define Make make_pair
#define fr first
#define sc second

using namespace std;

const ll N = 400400;

ll Max(ll a,ll b);
void Update(ll k,ll x);

ll n;

ll h[N];
ll a[N];
ll IndexAfterSort[N];
pll b[N];
ll Tree[N];

ll Dp[N];

int main()
{
    cin>>n;

    for(ll i=0;i<n;i++) scanf("%I64d",h+i) , b[i] = Make(h[i],i);
    for(ll i=0;i<n;i++) scanf("%I64d",a+i);

    sort(b,b+n);

    for(ll i=0;i<n;i++) IndexAfterSort[b[i].sc] = i;

    for(ll i=n-1;i>=0;i--)
    {
        ll I = IndexAfterSort[i];

        Dp[i] = a[i] + Max(I+1,n-1);

        Update(I,Dp[i]);
    }

    cout<<*max_element(Dp,Dp+n);
}

ll Max(ll a,ll b)
{
    ll Res = 0;

    for( a += n , b += n ; a<=b ; a /= 2 , b /= 2 )
    {
        if (a%2 == 1) Res = max( Res , Tree[a++] );
        if (b%2 == 0) Res = max( Res , Tree[b--] );
    }

    return Res;
}

void Update(ll k,ll x)
{
    k += n;
    Tree[k] = x;

    for( k /= 2 ; k >= 1 ; k /= 2 ) Tree[k] = max( Tree[2*k] , Tree[2*k+1] );
}

Measured memory_bytes: 18304
#include<iostream>

using namespace std;

int main()
{
	while (1) {
	int a, b,ans;
	string o;
	
		cin >> a >> o >> b;
		if (o == "?" )break;
		if (o == "+") { ans = a + b; }
		else if (o == "-") { ans = a - b; }
		else if (o == "*") { ans = a * b; }
		else if (o == "/") { ans = a / b; }
		cout << ans << endl;
	}
    return 0;
}




Measured memory_bytes: 3132
//誤読～♪
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
using namespace std;

int n;
int d[24];
int cnt[13];
bool used[25];	//used[i] = i時が存在するか？

int calc() {
	vector<int> x;
	for (int i = 0; i < 24; i++) if (used[i]) x.push_back(i);
	for (int i = 0; i < 24; i++) if (used[i]) x.push_back(24 + i);
	
	int score = 114514;
	for (int i = 0; i < (int)x.size(); i++) {
		//cout << x[i] << " ";
		if (i + 1 < (int)x.size()) score = min(score, x[i + 1] - x[i]);
	}
	//cout << endl;
	//cout << "score = " << score << endl;
	return score;
}

int dfs(int id) {
	if (id == n) { return calc(); }
	
	int a = d[id];
	int b = 24 - d[id];
	
	int ret = 1;
	int res;
	if (!used[a - 1] && !used[a] && !used[a + 1]) {
		used[a] = true;
		res = dfs(id + 1);
		ret = max(ret, res);
		used[a] = false;
	}
	if (!used[b - 1] && !used[b] && !used[b + 1]) {
		used[b] = true;
		res = dfs(id + 1);
		ret = max(ret, res);
		used[b] = false;
	}
	return ret;
}

int main() {
	int i;
	
	cin >> n;
	if (n >= 25) { cout << 0 << endl; return 0; }
	for (i = 0; i < n; i++) { cin >> d[i]; cnt[d[i]]++; }
	if (cnt[0] >= 1) { cout << 0 << endl; return 0; }
	for (i = 1; i <= 12; i++) { if (cnt[i] >= 3) { cout << 0 << endl; return 0; } }
	sort(d, d + n);
	
	//答え≧1が保障された状態で探索する
	used[0] = true;
	cout << dfs(0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   int a,b,c,d,x,y,z;
   cin>>a>>b>>c>>d;
   x=abs(c-a);
   y=max(abs(b-a),abs(c-b));
   z=min(x,y);
   if(z<=d)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    char hyou[n]; 
    int flag=1;
    vector<pair<char,int> > a;
    for(int i=0;i<26;i++){
      a.push_back(make_pair(i+'A',0));
    }
    for(int i=0;i<n;i++){
      cin>>hyou[i];
     
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<26;j++){
	if(hyou[i]==a[j].first){
	  a[j].second++;
	  break;
	}
      }
      for(int s=0; s < 25; s++ ) {
        for( int t = 25; t > s; t-- ) {
	  if( a[t-1].second < a[t].second ) {    
	    pair<char,int> temp = a[t];
	    a[t] = a[t-1];
	    a[t-1] = temp;
	    //cout<<"!"<<endl;
	  }
        }	
      }
    
      //for(int s=0;s<26;s++)
      //cout<<a[s].first<<" "<<a[s].second<<endl;
      if((a[0].second-a[1].second)>(n-i-1)){
	cout<<a[0].first<<" "<<i+1<<endl;
	flag=0;break;
      }
    }
    if(flag)
      cout<<"TIE"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        final long B = sc.nextLong();
        if (A == 0) {
            if (B == 0) {
                System.out.println(0);
                System.out.flush();
                sc.close();
                return;
            } else {
                A++;
            }
        }

        System.out.println(f(B)^f(A - 1));
        System.out.flush();
        sc.close();
    }

    private static long f(final long A) {
        long res[] = new long[] {A, 1l, A + 1, 0l};
        return res[(int) (A%4)];
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
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; }
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N, M;
    cin >> N >> M;
    vector<bool> ac(N + 1, false);
    vector<int> pena(N + 1, 0);
    int count = 0, waunt = 0;
    rep(i, 0, M){
        int p;
        string S;
        cin >> p >> S;
        if (S == "AC"){
            if(!ac.at(p)){
                ac.at(p) = true;
                count++;
                waunt += pena.at(p);
            }
        }
        if (S == "WA"){
            if(!ac.at(p)){
                pena.at(p)++;
            }
        }
    }
    cout << count << " " << waunt << endl;
}

Measured memory_bytes: 768
import sys
sys.setrecursionlimit(10**8)
N = int(input())
X = input()
if X == '0':
    for _ in range(N):
        print(1)
        exit()

mem = [None] * (200005)
mem[0] = 0
def f(n):
    if mem[n] is not None: return mem[n]
    c = bin(n).count('1')
    r = 1 + f(n%c)
    mem[n] = r
    return r

for i in range(200005):
    f(i)

cnt = X.count('1')
a,b = cnt+1, cnt-1

ans = [None] * N
x = int(X,2)

n = x % a
for i,c in reversed(list(enumerate(X))):
    if c=='1': continue
    ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1

if b:
    n = x % b
    for i,c in reversed(list(enumerate(X))):
        if c=='0': continue
        ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1
else:
    for i in range(N):
        if ans[i] is None:
            ans[i] = 0

print(*ans, sep='\n')

Measured memory_bytes: 33100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
  ll n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  ll point=0;
  vector<ll>v1(t.size());
  
  for(ll i=0;i<t.size();i++){
    if(t[i]=='r'){
      point+=p;
    }
    else if(t[i]=='s'){
      point+=r;
    }
    else{
      point+=s;
    }
  }
  
  
  for(ll i=t.size()-1;i>=k;i--){
    if(t.at(i)==t.at(i-k)){
      if(v1.at(i)%2==0){
      v1.at(i-k)+=v1.at(i)+1; 
        if(t[i]=='r'){
      point-=p;
    }
        else if(t[i]=='s'){
      point-=r;
    }
        
        else{
      point-=s;
        }
        
      }
      
      else{
        v1.at(i-k)+=v1.at(i)+1;
      }
    }
       
  }
       cout<<point<<endl;
       
     
       
}
       
        
      
  
    

Measured memory_bytes: 4288
#include <stdio.h>

int main(void)
{
	int i , counta = 0, countb = 0;
	char c1, c2;
	char s[5];
	
	scanf("%s", s);
	
	c1 = s[0];
	c2 = s[1];
	
	if (c1 == c2){
		c2 = s[2];
	}
	
	for (i = 0; s[i] != '\0'; i++){
		if (c1 == s[i]){
			counta++;
		}
		else if (c2 == s[i]){
			countb++;
		}
	}
	if (counta == 2 && countb == 2){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return (0);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[210000];
int t[210000];
int c[20];
int d[20];
int p[210000];
int q[210000];
int dp[1<<15];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d%d",p+i,q+i);
		s[i+1]=s[i]+p[i];
		t[i+1]=t[i]+q[i];
	}
	for(int i=0;i<b;i++)scanf("%d%d",c+i,d+i);
	for(int i=0;i<(1<<b);i++)dp[i]=-999999999;
	dp[0]=0;
	
	for(int i=0;i<(1<<b);i++){
		for(int j=0;j<b;j++){
			if(i&(1<<j))continue;
			int to=min(upper_bound(s,s+a+1,s[dp[i]]+c[j])-s-1,upper_bound(t,t+a+1,t[dp[i]]+d[j])-t-1);
			dp[i+(1<<j)]=max(dp[i+(1<<j)],to);
		}
	}
	printf("%d\n",dp[(1<<b)-1]);
}

Measured memory_bytes: 4284