akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N,M;
  cin>>N;
  vector<int>D(N);
  for(int i=0;i<N;i++){
    cin>>D[i];
  }
  cin>>M;
  vector<int>T(M);
  for(int i=0;i<M;i++){
    cin>>T[i];
  }
 // if(N<M){cout<<"NO"<<endl;return 0;}

  map<int,int>Q;
  for(int i=0;i<N;i++){
    Q[D[i]]++;
  }
  map<int,int>cnt;
  for(int i=0;i<M;i++){
    cnt[T[i]]++;
  }
  
  for(int i=0;i<M;i++){
    if(cnt[T[i]]>Q[T[i]]){cout<<"NO"<<endl;return 0;}
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 23460
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '(L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int main(){
 string s;
 cin>>s;
    cout<<s.substr(0,s.size()-8)<<endl;






}



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

int32_t main(){
	int n;
	int c=0;
	cin>>n;
	vector<string> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		sort(a[i].begin(),a[i].end());
	}
	map<string,int> data;
	for(int i=0;i<n;i++){
		data[a[i]]++;
	}
	for(map<string,int>::iterator it=data.begin();it!=data.end();it++){
		c+=it->second*(it->second-1)/2;
	}
	cout<<c;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define N 200005
using namespace std;
struct node{
	int A,B;
}s[N];
bool cmp(node a,node b){
	return a.B<b.B;
}
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&s[i].A,&s[i].B);
	sort(s+1,s+1+n,cmp);
	int t=0;
	for(int i=1;i<=n;i++){
		t+=s[i].A;
		if(t>s[i].B)return !puts("No");
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1792
from itertools import permutations

n=int(input())

l=[]
for i in range(n):
  x,y=map(int,input().split())
  l.append([x,y])

total=0
for i in list(permutations(l)):
  for j in range(len(i)-1):
    total +=((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
    
print(total/len(list(permutations(l))))

Measured memory_bytes: 8052
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<u32>();
    let mut count = 0;
    for i in 0..n {
        let mut mini = i;
        for j in i..n {
            if a[j] < a[mini] {
                mini = j;
            }
        }
        if i != mini {
            let tmp = a[i];
            a[i] = a[mini];
            a[mini] = tmp;
            count += 1;
        }
    }
    let ans = a
        .into_iter()
        .map(|i| i.to_string())
        .collect::<Vec<String>>()
        .join(" ");
    println!("{}\n{}", ans, count);
}



Measured memory_bytes: 5036
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int k = getInt();

  const int t = 'z' - 'a' + 1;
  vector<int> v(t);

  REP(i,n) {
    char buff[16];
    scanf("%s", buff);
    v[buff[0] - 'A']++;
  }

  int ans = 0;
  while (true) {
    sort(v.rbegin(), v.rend());
    if(v[k - 1] == 0) break;
    ans++;
    REP(i,k) v[i]--;
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
using namespace std;
void File(){
	freopen("ARC97E.in","r",stdin);
	freopen("ARC97E.out","w",stdout);
}
#define REP(i,a,b) for(register int i = a;i <= b;++i)
#define DREP(i,a,b) for(register int i = a;i >= b;--i)
#define MREP(i,x) for(register int i = beg[x];i;i = E[i].last)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define inf INT_MAX
const int maxn = 2000 + 10;
int n,c[maxn << 1],a[maxn << 1],pos0[maxn],pos1[maxn];
int dp[maxn][maxn],cost0[maxn << 1][maxn],cost1[maxn << 1][maxn];
int main(){
	//File();
	scanf("%d",&n);
	REP(i,1,n * 2){
		char s[5];
		scanf("%s%d",s,&a[i]);
		c[i]= s[0] == 'W' ? 0 : 1;
		if(c[i] == 0)pos0[a[i]] = i;
		else pos1[a[i]] = i;
	}
	REP(i,1,n * 2){
		REP(j,0,n){
			cost0[i][j]=cost0[i - 1][j] + (a[i - 1] > j && c[i - 1] == 0);
			cost1[i][j]=cost1[i - 1][j] + (a[i - 1] > j && c[i - 1] == 1);
		}
	}
	dp[0][0]=0;
	REP(i,0,n)
		REP(j,0,n){
			if(i == 0 && j == 0)continue;
			dp[i][j]=inf/2;
			if(i)dp[i][j] = min(dp[i][j],dp[i - 1][j] + cost0[pos0[i]][i - 1] + cost1[pos0[i]][j]);
			if(j)dp[i][j] = min(dp[i][j],dp[i][j - 1] + cost0[pos1[j]][i] + cost1[pos1[j]][j - 1]);
		}
	printf("%d\n",dp[n][n]);
	return 0;
}


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

using namespace std;

typedef long long LL;
#define N 1200000

const LL mod=1000000007;
LL n,f[N],g[N],sum,ans;

void upd(LL &x,LL y){x=(x+y)%mod;}

int main(){
	scanf("%lld",&n);
	upd(ans,(n-1)*n+1);
	f[0]=g[0]=1;
	for (LL i=1;i<=n;++i){
		if (i>=3) upd(sum,g[i-3]);
		f[i]=sum+1;
		g[i]=(g[i-1]+f[i])%mod;
		if (i<n) upd(ans,f[i]*(n-1));
		if (i<n-1) upd(ans,f[i]*(n-1)%mod*(n-1));
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 18688
def abc115_c():
    n, k = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    h.sort()

    diff = h[-1] - h[0]
    for i in range(n-k+1):
        if h[i+k-1]-h[i] < diff:
            diff = h[i+k-1]-h[i]

    print(diff)


abc115_c()

Measured memory_bytes: 7384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a,b;
	cin>>a>>b;
	int c;
	int dp[2];
	dp[0] = 0;
	dp[1] = abs(b-a);
	for(int i=2;i<n;i++)
	{
		int x;
		cin>>x;
		c = min( abs(x-a) + dp[0],abs(x-b) + dp[1]);
		dp[0] = dp[1];
		dp[1] = c;
		a = b;
		b = x;
	}
	cout<<dp[1]<<endl;
	return 0;
}

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

int r[20][101010];

int f(int s, int t, int x){
  int cur=s;
  rep(i,18) if((x>>i)&1){
    cur=r[i][cur];
  }
  if(cur>=t) return 1;
  else return 0;
}

int main(){
  int N;cin>>N;
  int X[N];
  rep(i,N) cin>>X[i];
  int L; cin>>L;
  rep(i,N){
    int x=upper_bound(X,X+N,X[i]+L)-X;
    r[0][i]=x-1;
  }
  rep(i,18) rep(j,N) r[i+1][j]=r[i][r[i][j]];
  int Q; cin>>Q;
  rep(i,Q){
    int a,b; cin>>a>>b; a--,b--;
    if(a>b) swap(a,b);
    int ok=N,ng=0;
    while(abs(ok-ng)>1){
      int mid=(ok+ng)/2;
      if(f(a,b,mid)) ok=mid;
      else ng=mid;
    }
    cout<<ok<<endl;
  }
  return 0;
}


Measured memory_bytes: 8704
from collections import deque
n, k = map(int, input().split())
d = deque()
for _ in range(n):
    a, b = map(int, input().split())
    d.append([a, b])
x = sorted(list(d))
for i in range(n):
    k -= x[i][1]
    if k < 1:
        print(x[i][0])
        break


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String r = scan.next();
		String g = scan.next();
		String b = scan.next();
		String color = r + g + b;
		int colornum = Integer.parseInt(color);

		if(colornum%4 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}


	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <map>
#include <cstring>
#include <algorithm>

using namespace std;

typedef pair<int, int> pii;
typedef map<int, int> mii;

const int Z = 998244353;

void upd(int bit[], int n, int x) {
    for (; x <= n; x += x & -x) {
        bit[x]++;
    }
}

int qry(int bit[], int x) {
    int r = 0;
    for (; x; x -= x & -x) {
        r += bit[x];
    }
    return r;
}

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

    int n;
    cin >> n;
    pii xy[n];
    for (int i = 0; i < n; i++) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy, xy+n);

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

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

    int q = 0;
    for (auto p : xx) {
        xx[p.first] = ++q;
    }

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

    int l[n], r[n], u[n], d[n], lu[n], ru[n], ld[n], rd[n];

    int bit[n+1];
    memset(bit, 0, sizeof(bit));
    for (int i = 0; i < n; i++) {
        ld[i] = qry(bit, a[i]);
        lu[i] = i - ld[i];
        upd(bit, n, a[i]);
    }

    memset(bit, 0, sizeof(bit));
    for (int i = n - 1; i >= 0; i--) {
        rd[i] = qry(bit, a[i]);
        ru[i] = n - 1 - i - rd[i];
        upd(bit, n, a[i]);
    }

    int p2[n+1];
    for (int i = 0; i <= n; i++) {
        p2[i] = i == 0 ? 1 : p2[i-1] * 2 % Z;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        l[i] = i;
        r[i] = n - 1 - i;
        u[i] = lu[i] + ru[i];
        d[i] = ld[i] + rd[i];

        ans = (4ll * Z + ans + p2[n] - 1
              - p2[l[i]] - p2[r[i]] - p2[u[i]] - p2[d[i]]
              + p2[lu[i]] + p2[ld[i]] + p2[ru[i]] + p2[rd[i]]) % Z;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    set<string>st;
    int n;
    cin>>n;
    while(n--){
        string s,t;
        cin>>s>>t;
        if(s=="insert")st.insert(t);
        else cout<<(st.count(t)?"yes":"no")<<endl;
    }
}


Measured memory_bytes: 32152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

struct edge {
    ll u, v, s;
};

vector<edge> g;
vector<vector<int>> t(100010);
vector<ll> val(100010);
vector<bool> pls(100010), used(100010), was(100010);

void dfs(int v, int p = -1) {
    for (int i : t[v]) {
        edge e = g[i];
        int u = e.u + e.v - v;
        if (was[u]) continue;
        was[u] = used[i] = true;
        pls[u] = !pls[v];
        val[u] = e.s - val[v];
        dfs(u, v);
    }
}

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

    int n, m;
    cin >> n >> m;
    rep(i, 0, m) {
        int u, v, s;
        cin >> u >> v >> s;
        u--, v--;
        t[u].emplace_back(i);
        t[v].emplace_back(i);
        g.push_back({u, v, s});
    }
    pls[0] = was[0] = true;
    dfs(0);
    ll pmn = 0, nmn = 1e18;
    rep(i, 0, n) {
        if (pls[i])
            pmn = min(pmn, val[i]);
        else
            nmn = min(nmn, val[i]);
    }
    pmn = 1ll - pmn;
    if (pmn >= nmn) {
        cout << 0 << endl;
        return 0;
    }
    set<ll> nd;
    rep(i, 0, m) if (!used[i]) {
        edge e = g[i];
        if (pls[e.u] != pls[e.v]) {
            if (val[e.u] + val[e.v] != e.s) {
                cout << 0 << endl;
                return 0;
            }
        } else {
            ll foo = e.s - val[e.u] - val[e.v];
            if (foo % 2) {
                cout << 0 << endl;
                return 0;
            }
            foo /= 2;
            if (pls[e.u]) {
                nd.insert(foo);
            } else {
                nd.insert(-foo);
            }
        }
    }
    if (nd.size() > 1) {
        cout << 0 << endl;
        return 0;
    } else if (nd.size() == 1) {
        if (pmn <= *nd.begin() && *nd.begin() < nmn)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }
    cout << nmn - pmn << endl;

    return 0;
}

Measured memory_bytes: 17072
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ');
  buildMaxHeap(arr);
  console.log(' ' + arr.join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = (2 * i + 1)|0;
    right = (2 * i + 2)|0;
    if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left|0;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right|0;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };
  for (let i = Math.floor(n / 2 - 1); i >= 0; i=(i-1)|0) maxHeapify(i);
}



Measured memory_bytes: 88304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();


int main(){
    ll n;
    int k;
    int h[100001];
    cin >> n >> k;

    int cnt = 0;

    rep(i,n) {
        cin >> h[i];
        if (h[i] >= k) cnt++;        
    }
    
    cout << cnt << endl;

    return 0;
    
}

Measured memory_bytes: 3892
#include <complex>
#include <cmath>
#include <vector>
#include <cstdio>

using namespace std;

const double EPS = 1e-6;

typedef complex<double> P;
namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}

double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

struct L : public vector<P> {
    L(const P &a, const P &b) {
        push_back(a); push_back(b);
    }
};

P projection(const L &l, const P &p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
    return p + 2.0 * (projection(l, p) - p);
}

int main(){
    double x1,y1,x2,y2,xq,yq;
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",
                &x1,&y1,&x2,&y2,&xq,&yq)!=EOF){
        P p1=P(x1,y1),p2=P(x2,y2),q=P(xq,yq);
        auto ans=reflection(L(p1,p2),q);
        printf("%.5f %.5f\n",ans.real(),ans.imag());
    }
}

Measured memory_bytes: 1096
N=int(input())
L=list(map(int,input().split()))
L.sort()

dp=[0]*(N+1)
ans=0
for i in range(3,N+1):
  r=i-2
  l=0
  c=0
  while r>l:
    if L[r]+L[l]>L[i-1]:
      c+=r-l
      r-=1
    else:
      l+=1
  dp[i]=dp[i-1]+c

print(dp[-1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define ld double
#define pb push_back
#define EPS 1e-9
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

int D, G, p[15], c[15], dp[15][1010];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> D >> G;
    FOR(i,1,D) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    G /= 100;
    dp[0][0] = 0;
    FOR(j,1,1000) dp[0][j] = -1000000000;
    FOR(i,1,D)
        FOR(j,0,1000)
            FOR(k,0,p[i])
                if (j - k >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-k] + k * i + (k == p[i] ? c[i] : 0));
    FOR(j,0,1000) if (dp[D][j] >= G) {
        cout << j;
        return 0;
    }
    return 0;
}


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

int main(){
  int N, X;
  cin >> N >> X;
  
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L.at(i);
  }
  
  int cnt=1;
  vector<int> D(N+1);
  for(int j=0; j<N; j++){
    D.at(j+1) = D.at(j) + L.at(j);
    if(D.at(j+1)>X) break;
    else cnt++;
  }
  cout << cnt << endl;    
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
const int MAXN=100010,inf=999999999;
int n,m,k;
int a[MAXN],b[MAXN];
int ans=inf;
int main()
{
    read(n),read(m),read(k);
    for(int i=1;i<=n;i++) read(a[i]);
    for(int i=1;i<=m;i++) read(b[i]);
    for(int i=1;i<=k;i++)
    {
        int x,y,z;
        read(x),read(y),read(z);
        ans=min(ans,a[x]+b[y]-z);
    }
    sort(a+1,a+n+1),sort(b+1,b+m+1);
    ans=min(ans,a[1]+b[1]);
    write(ans),putchar('\n');
	return 0;
}


Measured memory_bytes: 1024
import itertools


def main():
    n = int(input())

    a = []
    for i in range(n):
        a.append(int(input()))
    a.sort()
    if n == 2:
        print(abs(a[0] - a[1]))
        return
    if n == 3:
        tmp1 = abs(a[0] - a[1]) + abs(a[0] - a[2])
        tmp2 = abs(a[0] - a[2]) + abs(a[1] - a[2])
        print(max([tmp1, tmp2]))
        return
    if n < 10:
        ans = 0
        for a in itertools.permutations(a):
            tmp = 0
            for i in range(len(a) - 1):
                tmp += abs(a[i] - a[i + 1])
            ans = max([ans, tmp])
        print(ans)
        return
    ret1 = a[:n // 2 + (1 if n % 2 == 1 else 0)]
    ret2 = a[n // 2 + (1 if n % 2 == 1else 0):]
    ret1 = [ret1[-1]] + ret1[:-2] + [ret1[-2]]
    ret2 = ret2[1:] + [ret2[0]]
    ans = 0

    ans += abs(ret1[-1] - ret2[-1])
    for i in range(len(ret2) - 1):
        ans += abs(ret1[i] - ret2[i])
        ans += abs(ret1[i + 1] - ret2[i])
    if len(ret1) != len(ret2):
        ans += abs(ret1[-2] - ret2[-1])

    if n % 2 == 0:
        print(ans)
        return
    ans1 = ans

    ret1 = a[:n // 2 + (0 if n % 2 == 1 else 1)]
    ret2 = a[n // 2 + (0 if n % 2 == 1else 1):]
    # ret1 = ret1[1:] + [ret1[0]]
    ret2 = [ret2[0]] + ret2[2:] + [ret2[1]]
    ans = 0

    ans += abs(ret1[-1] - ret2[-1])
    for i in range(len(ret1) - 1):
        ans += abs(ret2[i] - ret1[i])
        ans += abs(ret2[i + 1] - ret1[i])
    if len(ret1) != len(ret2):
        ans += abs(ret1[-1] - ret2[-2])
    print(max([ans, ans1]))


main()


Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 1e5 + 10;
const int MAXM = 1e6 + 10;
const ll mod = 1e9 + 7;

int n,dp[MAXN];
vector<int>vec[MAXN];

void dfs(int u,int p) {
    int flag = 0;
    for(int i=0; i<vec[u].size(); i++) {
        int v = vec[u][i];
        if(v == p) continue;
        dfs(v,u);
        dp[u] += dp[v];
        if(!dp[v]) {
            if(!flag) flag = 1;
            else dp[u]++;
        }
    }
}

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    scanf("%d",&n);
    for(int i=1; i<n; i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    int f = -1;
    for(int i=0; i<n; i++) {
        if(vec[i].size() >= 3) {
            f = i;
            break;
        }
    }
    if(f == -1) {
        puts("1");
        return 0;
    }
    dfs(f,-1);
    printf("%d\n",dp[f]);
    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <vector>

#define MOD 1000000007

using namespace std;

typedef long long int ll;

int n, k;
int a[510];
int dp[100010], fake[100010];

void add_self(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }
void sub_self(int &a, int b) { a -= b; if (a < 0) a += MOD; }

int main() {

	scanf("%d %d", &n, &k);

	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	dp[0] = 1;

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

		for (int j = k; j >= 0; j--) {

			// add the same value (dp[j]) to an interval 
			//for (int l = 1; l <= min(a[i], k - j); l++)
			//	add_self(dp[j + l], dp[j]);

			int l = j + 1;
			int r = j + min(a[i], k - j);

			add_self(fake[l], dp[j]);
			sub_self(fake[r + 1], dp[j]);
		}

		int cur_sum = 0;

		for (int j = 0; j <= k; j++) {

			add_self(cur_sum, fake[j]);
			add_self(dp[j], cur_sum);

			fake[j] = 0;
		}
	}

	printf("%d", dp[k]);

	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
ss = input()
*s, = map(int,ss)

if len(s)%2 == 0:
    s0 = [0,1] *(len(s)//2)
    s1 = [1,0] *(len(s)//2)
else:
    s0 = [0,1] *(len(s)//2)
    s0.append(0)
    s1 = [1,0] *(len(s)//2)
    s1.append(1)

sum0 = 0
sum1 = 0
for i in range(len(s)):   
    if s0[i] != s[i]:
        sum0 = sum0 +1
    if s1[i] != s[i]:
        sum1 = sum1 +1

ans = min(sum0, sum1)
print(ans)

Measured memory_bytes: 5620
n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]

t.sort()
passenger = 0
start = t[0]
ans = 1


for i in t:
    if i - start > k or passenger == c:
        ans += 1
        passenger = 1
        start = i
    else:
        passenger += 1


print(ans)


Measured memory_bytes: 7384
def d_leaping_tak(MOD=998244353):
    from bisect import bisect_left, bisect_right
    N, K = [int(i) for i in input().split()]
    Ranges = sorted([[int(i) for i in input().split()] for j in range(K)])

    dp = [0] * (N + 1)  # dp[i]: マス i への行き方
    dp[1] = 1
    cumsum_dp = dp[:]
    for i in range(2, N + 1):
        for l, r in Ranges:
            if i - l < 0:
                continue
            if i - r < 0:
                r = i

            dp[i] += cumsum_dp[i - l] - cumsum_dp[i - r - 1]
        dp[i] %= MOD
        cumsum_dp[i] = cumsum_dp[i - 1] + dp[i]
    # print(dp)
    # print(cumsum_dp)
    return dp[N]

print(d_leaping_tak())

Measured memory_bytes: 71068
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  string s;
  cin>>s;
  ll ans=0;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1])ans++;
  }
  //if(n>1&&s[n-2]!=s[n-1])ans++;
  cout<<max(1LL,ans+1)<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    int N;
    long long int H[100005];
    int dp[100005];
    cin>>N;
    for(int i=0; i<100005; i++)
    {
        dp[i]=0;
    }
    for(int i=0; i<N; i++)
    {
        cin>>H[i];
    }
    int max=1;
    int v=0;
    for(int i=0; i<N-1; i++)
    {
        if(H[i]>=H[i+1])
            {dp[i]=1;
            v=1;
            }
    }
    if(v==0) cout<<0;
    else{
    int x=0;

    for(int i=0; i<N; i++)
    {

        if(dp[i]==1&&dp[i+1]==1)
        {
if(x==0) x=2;

           else x++;
            if(x>max)
                max=x;
        }
        else
            x=0;

    }
    cout<<max;
    }
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {   
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ans(n);
    }
    public static void ans(int n) {
        if(n%2 == 0) {
            System.out.println(n);
        }
        else {
            System.out.println(n*2);
        }
    }
}

Measured memory_bytes: 21844
import java.io.*;

public class Main{ 
        public static void main(String[] args){
            int i,m,kazu,k,a,count=0,c,d;
            String kard;
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{ 
                int[] kard1=new int[100];
                int[][] temp=new int[1000][100];
                while(true){
                    kard=reader.readLine();
                    String suuti[] = kard.split(" ");
                     c = Integer.parseInt(suuti[0]);
                     kazu = Integer.parseInt(suuti[1]);
                    if(c==0){
                        break;
                    }
                    int e = c;
                    for(i=0;i<c;i++){
                        kard1[i]=e;
                        e--;
                    }
                    for(m=0;m<kazu;m++){
                        String al=reader.readLine();
                        String suuti1[] = al.split(" ");
                        a = Integer.parseInt(suuti1[0]);
                        d = Integer.parseInt(suuti1[1]);
                        k=0;
                        for(i=a-1;i<a-1+d;i++){
                            temp[count][k]=kard1[i];
                            k++;
                        }
                        for(i=0;i<a-1;i++){
                            temp[count][k]=kard1[i];
                            k++;
                        }
                        for(i=a+d-1;i<c;i++){
                            temp[count][k]=kard1[i];
                            k++;
                        }
                        for(i=0;i<c;i++){
                            kard1[i]=temp[count][i];
                        }
                    }
                    count++;
                }
                i=0;
                while(count>i){
                    System.out.println(temp[i][0]);
                    i++;
                }
            } catch (IOException e){
                System.out.println(e);
            }
        }
    }


Measured memory_bytes: 29052
#include <bits/stdc++.h>
#define FORUP(i, start, end) for (int i = start; i <= end; i++)
#define FORDOWN(i, end, start) for (int i = end; i >= start; i--)
#define mem(a, v) memset(a, v, sizeof a)
#define ll long long
#define ld long double
#define pir pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const ll MAX = 100009, MOD = 1000000007, BASE = 311, inf  = 1e9;

int du[] = {1, -1, 0, 0}, dv[] = {0, 0, -1, 1};
using namespace std;

ll n, k, a[109], f[109][MAX];

int main()
{
    //freopen("SUBXOR.inp", "r", stdin);
    //freopen("SUBXOR.out", "w", stdout);
    cin >> n >> k;
    FORUP(i, 1, n) cin >> a[i];

    f[0][0] = 1;
    FORUP(i, 1, n) {
        vector<ll> sum(k+9, 0);
        sum[0] = f[i-1][0];
        FORUP(j, 1, k) sum[j] = (sum[j-1] + f[i-1][j]) % MOD;
        FORUP(j, 0, k) {
            ll pos = j-a[i]-1;
            if(pos >= 0) f[i][j] = (sum[j] - sum[pos] + MOD*MOD) % MOD;
            else f[i][j] = sum[j] % MOD;
        }
    }

    cout << f[n][k] << endl;

    return 0;
}


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

int n;

int main() {
	cin >> n; string S = to_string(n);
	int s = 0; for (int i = 0; i < S.size(); i++) s += (S[i] - '0');
	if (n%s == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
//typedef complex<long double> com;
 
//const ll mod = 1e9+7;
 
void setIO(string name) {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
 
//setIO("sleepy");


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//setIO("shortcut");
	bool ok = true;
	ll n;
	cin >> n;
	for (int z=0;z<n;z++){
		ll temp; cin >> temp;
		if (temp & 1) continue;
		if (temp % 3 == 0) continue;
		if (temp % 5 == 0) continue;
		ok = false;
	}
	if (ok) {
		cout << "APPROVED" << endl;
	} else {
		cout << "DENIED" << endl;
	}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
N=int(input())
G=[[] for i in range(N)]
for _ in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w%2])
    G[v-1].append([u-1,w%2])
color=[0 for i in range(N)]
seen=[False for i in range(N)]
color[0]=1
def dps(i):
    seen[i]=True
    for g in G[i]:
        if seen[g[0]]:
            continue
        else:
            if g[1]==0:
                color[g[0]]=color[i]
            else:
                color[g[0]]=color[i]*-1
            dps(g[0])
dps(0)
for i in range(N):
    print(1 if color[i]==1 else 0)

Measured memory_bytes: 83068
fun main(args: Array<String>) {
    val n = readInteger()
    val s = readLine()!!

    var ans = 0
    for (i in 0..9) {
        for (j in 0..9) {
            for (k in 0..9) {
                if (existedOn(s, i, j, k)) {
                    ans++
                }
            }
        }

    }
    ans.let(::println)
}

fun existedOn(s: String, i: Int, j: Int, k: Int): Boolean {
    val a = s.indexOf(i.toString())
    if (a == -1 || a == s.length - 1) { return false }

    val b = s.indexOf(j.toString(), a + 1)
    if (b == -1 || b == s.length - 1) { return false }

    val c = s.indexOf(k.toString(), b + 1)
    if (c == -1) { return false }

    return true
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int len=S.size();
    for(int i=0; i<len; i++){
        int x=S.at(i)-'A';
        x=(x+N)%26;
        S.at(i)='A'+x;
    }
    cout << S << endl;
    
}


Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vl acc(N+1);
    vl A(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        acc[i+1]=acc[i]+A[i];
        acc[i+1]%=MOD;
    }
    ll ans=0;
    rep(i,N){
        ans+=A[i]*acc[i];
        ans%=MOD;
    }
    cout << ans << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 6348
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

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

X,N = LI()
p = LI()

p.sort()
v = 0
while True:
    pl = bisect_left(p,X-v)
    if pl >= N or p[pl] != X-v:
        print(X-v)
        exit()
    pl = bisect_left(p,X+v)
    if pl >= N or p[pl] != X+v:
        print(X+v)
        exit()
    v += 1

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

A, B, K = map(int, input().split())

ans = []

# 以内の判定
for i in range(A, A + K):
    if i <= B:
        ans.append(i)

for j in range(B, B - K, -1):
    if j >= A:
        ans.append(j)

ans = sorted(set(ans))

for x in ans:
    print(x)

Measured memory_bytes: 9156
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;
string s[300];

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> s[j];
    }

    int ans = 0;

    for (int a = 0; a < N; ++a) {
        bool sym = true;
        for (int j = 0; j < N; ++j) {
            for (int k = 0; k < N; ++k) {
                if (s[(j+a)%N][k] != s[(k+a)%N][j])
                    sym = false;
            }
        }
        if (sym) ans += N;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
a_yen, b_yen, c_yen, x, y = map(int, input().split())

amax = x
bmax = y
cmax = max(x,y) * 2

nedan = 10**10

for i in range(cmax//2+1):
    c=i*2
    
    a=max(amax-c//2,0)
    b=max(bmax-c//2,0)
    
    yen = a_yen * a + b_yen * b +c_yen * c
    # print(a,b,c,yen)
    nedan = min(nedan,yen)

print(nedan)

Measured memory_bytes: 66288
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	ll s = 0;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	int x = 0;
	for (int i = 0; i < n; i++) {
		if (4 * m * a[i] >= s)x++;
	}
	cout << (x >= m ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	string N;
	int K;
	cin >> N >> K;

	vector<bool> dv(10,0);
	for(int i = 0; i < K; i++) {
		 int x; 
		 cin >> x; 
		 dv[x] = 1; 
	}

	bool can = 1;
	string ans = "";

	for(int i = 0; i < N.size(); i++){
		
		int find = N[i] - '0';

		if(dv[find]){
			can = 0;
			break;
		}

		ans += (find + '0');		

	}

	if(can){
		cout << ans << endl;
		return 0;
	}
	else{
		bool found = 0;		

		can = 1;

		ans = "";

		for(int i = 0; i < N.size(); i++){
			
			int tg = N[i] - '0';

			if(found){
				for(int j = 0; j < 10; j++){
					if(!dv[j]){
						ans += (j + '0');
						break;
					}
				}
			}
			else{
				for(int j = tg + 1; j < 10; j++){
					if(!dv[j]){
						ans += (j + '0');
						found = 1;
						break;
					}
				}
				if(!found){
					if(dv[tg]) can = 0;
					else ans += (tg + '0');
				}
			}
		}

		if(can){
			cout << ans << endl;
			return 0;
		}

	}

	int x1 = -1;

	for(int i = 1; i < 10; i++){
		if(!dv[i]){
			x1 = i;
			break;
		}
	}

	assert(x1 != -1);

	if(dv[0]){
		for(int i = 0; i <= N.size(); i++) cout << x1;
		cout << endl;
	}
	else{
		cout << x1;
		for(int i = 1; i <= N.size(); i++) cout << 0;
		cout << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void print_a_b(char str[],int a,int b);
void reverse(char str[],int a,int b);
void replace(char str[],int a,int b,char p[]);

char str[1005];
char p[1005];

int main(){

    char op[10];
    int q;//命令の回数
    int a, b, ord;
    scanf("%s%d",str,&q);

    for(int i = 0;i < q;i++){
        //printf("%d回目",i+1);
        scanf("%s%d%d",op,&a,&b);
        if(op[2]=='i'){//print
            print_a_b(str,a,b);
        }else if(op[2]=='p'){
            scanf("%s",p);
            replace(str,a,b,p);
        }else if(op[2]=='v'){
            scanf("%d %d",&a,&b);
            reverse(str,a,b);
        }
    }
    return 0;
}

void print_a_b(char str[],int a,int b){
    while(a <= b){
        printf("%c",str[a]);
        a++;
    }
    printf("\n");
}

void reverse(char str[],int a,int b){
    int n=(b-a)/2+1;
    char p;
    for(int i = 0;i < n;i++){
        p=str[a+i];
        str[a+i]=str[b-i];
        str[b-i]=p;
    }
}
void replace(char str[],int a,int b,char p[]){
    for(int i = 0;i < strlen(p);i++){
        str[a+i] = p[i];
    }
}



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

char to_lower(char c)
{
  if ( c >= 'A' && c <= 'Z' )
    {
      c += 0x20;
    }
  return c;
}

int main()
{
  string w;
  string t;
  int cnt = 0;

  cin >> w;
  
  while ( cin >> t )
    {
      transform( t.begin(), t.end(), t.begin(), to_lower );
      if ( t == w ) cnt++;
    }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1184
import java.util.Scanner;

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

    private static void solve(Scanner in) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                System.out.println(i + "x" + j + "=" + i * j);
            }
        }
    }
    /*
     * 1x1=1 1x2=2 . . 9x8=72 9x9=81
     */
}

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

void dfs(int x,int y);
int dx[12]={0,0,0, 0, 0, 0,1,2,3,-1,-2,-3};
int dy[12]={1,2,3,-1,-2,-3,0,0,0, 0, 0, 0};
char maps[8][8];

int main(){
  int n,sx,sy;
  cin >> n;
  for(int cas=1;cas<=n;cas++){
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
	cin >> maps[i][j];
      }
    }
    cin >> sx >> sy;
    dfs(sx-1,sy-1);
    cout << "Data " << cas<< ":" << endl;
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
	cout << maps[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

void dfs(int x,int y){
  int nx,ny;
  for(int i=0;i<12;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    maps[y][x]='0';
    if(0<=nx && nx<8 && 0<=ny && ny<8 && maps[ny][nx]=='1'){
      dfs(nx,ny);
    }
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
int a,b;
using namespace std;
int main()
{
    char x;
	cin>>a>>x>>b;
	if(x=='+')
	cout<<a+b;
	else
	cout<<a-b;



 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  deque<ll> q;
  for(ll i=0;i<n;i++) {
    if(n%2) {
      if(i%2) {
        q.push_back(a[i]);
      }
      else {
        q.push_front(a[i]);
      }
    }
    else {
      if(i%2) {
        q.push_front(a[i]);
      }
      else {
        q.push_back(a[i]);
      }
    }
  }
  ll f=0;
  for(auto p:q) {
    if(f)cout << " ";
    cout << p;
    f=1;
  }
  cout << endl;
}

Measured memory_bytes: 5376
fn main() {
    proconio::input! {
        a: usize,
        mut b: usize,
        mut c: usize,
        mut k: usize,
    }
    while a>=b && k>0 {
        b*=2;
        k-=1;
    }
    while b>=c && k>0 {
        c*=2;
        k-=1;
    }
    println!("{}",if a<b && b<c {"Yes"} else {"No"});
}

Measured memory_bytes: 2136
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main(){
    int N,K;
    cin >> N >> K;
    vector<int> D(K);
    REP(i,K){
        cin >> D[i];
    }
    int o=0;
    for(int i=N;i<100000;i++){
        int i2=i;
        int ps=0;
        while(1){
            int p,c=0;
            int i3=i2%10;
            if(i2==0){
                    cout << i << endl;
                    o++;
                    break;
                }
            else{
                ps=0;
            }
            REP(k,K){
                if(D[k]==i3){
                    c++;
                    break;
                }
            }
            if(c==1){
                break;
            }
            i2=i2/10;
        }
        if(o!=0){
            break;
        }
    }
        
    return 0;
}

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

int main(){
	int w, h, x, y;
  	cin >> w >> h >> x >> y;
  	if(w == x * 2 && h == y * 2) cout << (double)w * h / 2 << " 1" << endl;
  	else cout << (double)w * h / 2 << " 0" << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i < n; i++)
#define fst first
using ll = long long int;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  map<ll,ll> b,c;
  rep(i, n){b[i-a[i]]++;c[a[i]+i]++;}
  ll ans = 0;
  
  for(auto p:b){
  	ans += b[p.fst]*c[p.fst];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 39076
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N;
  string S;
  cin >> N >> S;

  vector<vector<int>> m(10);
  for (int i = 0; i < N; i++) m[S[i] - '0'].push_back(i);

  set<string> ans;
  for (int i = 0; i < N; i++) {
    for (const auto& v : m) {
      auto it = lower_bound(v.begin(), v.end(), i + 1);
      if (it == v.end()) continue;
      int j = *it;
      for (const auto& vv : m) {
        auto it = lower_bound(vv.begin(), vv.end(), j + 1);
        if (it == vv.end()) continue;
        int k = *it;
        string t = ""s + S[i] + S[j] + S[k];
        ans.insert(t);
      }
    }
  }
  cout << ans.size() << endl;
}


Measured memory_bytes: 768
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;

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

  vector<vector<int>> a(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }

  int n;
  cin >> n;
  while (n--) {
    int b;
    cin >> b;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        if (a[i][j] == b) {
          a[i][j] = 0;
        }
      }
    }
  }

  for (int i = 0; i < 3; ++i) {
    if (!a[i][0] && !a[i][1] && !a[i][2]) {
      cout << "Yes";
      return 0;
    }
    if (!a[0][i] && !a[1][i] && !a[2][i]) {
      cout << "Yes";
      return 0;
    }
  }

  bool can = 1;
  for (int i = 0; i < 3; ++i) {
    if (a[i][i]) {
      can = 0;
      break;
    }
  }
  if (can) {
    cout << "Yes";
    return 0;
  }

  can = 1;
  for (int i = 0; i < 3; ++i) {
    if (a[i][2 - i]) {
      can = 0;
      break;
    }
  }
  if (can) {
    cout << "Yes";
    return 0;
  }

  cout << "No";
}

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

int main(){
  //小数点以下12桁を表示させるためのおまじない。
  cout << fixed << setprecision(12);
  
  int a, b;
  cin>>a>>b;

  cout<< a * b <<" "<< (a + b) * 2 <<endl;
  return 0;
}



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

int main(){
    int n;
    ll k,ans1 = 0,ans2 = 0, ans = 0;
    cin >> n >> k;
    int a[n],b[n*2];
    for(ll i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            if(a[i] > a[j]) ans1++;
        }
    }//１配列の転倒数
    ans1 = ans1 * k % 1000000007;
    for(int i = 0; i < n*2; i++) b[i] = a[i%n];
    //2配列間の転倒数
    for(int i = 0; i < n; i++){
        for(int j = n; j < n*2; j++){
            if(b[i] > b[j]) ans2++;
        }
    }
    ll mk = k*(k-1)/2 % 1000000007;
    ans2 = (ans2 *mk) % 1000000007;
    ans = (ans1 + ans2) % 1000000007;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> a;
    int in;
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        a.emplace_back(in);
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (a[a[i] - 1] == i + 1)
        {
            ans += 1;
        }
        
    }
    
    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 892