akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


int main(){

  int n, x, y, w, h, N, i, j, cx, cy, count;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    count = 0;

    scanf("%d %d %d %d", &x, &y, &w, &h);
    scanf("%d", &N);

    for(j=0;j<N;j++){
      
      scanf("%d %d", &cx, &cy);

      if(cx>=x && cx<=x+w && cy>=y && cy<=y+h) count++;

    }
    
    printf("%d\n", count);

  }

  
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
//型名省略
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<long long>> vll;
typedef vector<char> vc;
typedef vector<vector<char>> vcc;
typedef vector<string> vs;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rep2(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}

int main() {
    ll a,b,c,k; cin >> a >> b >> c >> k;

    if(k <= a) cout << k << endl;
    else if(k <= a + b)cout << a << endl;
    else cout << a - (k - (a + b)) << endl;
}

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

int main() {
  ll X;
  cin >> X;
  cout << (X/500)*1000 + ((X%500)/5)*5 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<pair<int, int>> a;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        a.emplace_back(x, i + 1);
    }
    sort(a.begin(), a.end());
    for (auto p : a) {
        cout << p.second << "\n";
    }
}


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

int main() {
  string S;
  cin>>S;
  if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  
}


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

int main()
{
  int N;
  cin >> N;
  
  vector<int> exponent_2;
  rep(i, 7)
  {
    exponent_2.push_back(pow(2, i));
  }
  
  int max_exponent_2 = 0;
  rep(i, 7)
  {
    if (exponent_2[i] <= N)
    {
      max_exponent_2 = exponent_2[i];
    }
  }
  
  cout << max_exponent_2 << endl;
    
  return 0;
}

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

int main() {
  int K;
  cin >> K;
  int a,b;
  int count = 0;
  for(int i = 1;i < K + 1;i++){
    for(int j = 1;j < K + 1;j++){
      for(int k = 1;k < K + 1;k++){
        a = min(i,min(j,k));
        for(int l = 1;l < a + 1;l++){
          if((i % l == 0)&&(j % l == 0)&&(k % l == 0)){
            b = l;
          }
            
        }
        count += b;
      }
    }
  }  
  cout << count << endl;
}




Measured memory_bytes: 3636
using System;

namespace A___Weather_Prediction
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            if (s == "Sunny")
            {
                Console.WriteLine("Cloudy");
            }
            else if (s == "Cloudy")
            {
                Console.WriteLine("Rainy");
            }
            else
            {
                Console.WriteLine("Sunny");
            }
        }
    }
}

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

const int N = 1e5 + 10;
typedef long long ll;
ll h, n, a[N], sum;

int main() {
    cin >> h >> n;
    rep(i, 1, n) scanf("%lld", &a[i]), sum += a[i];
    if (h <= sum) puts("Yes"); else puts("No");
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;


bool soin(set<int64_t> &prime, int64_t x){
  int64_t N=x;
  bool finish=true;
  if(prime.count(N)){
    prime.erase(N);
    return true;
  }
  for (int64_t i=2;i*i<=N;i++){
    if(x%i==0){
      if(prime.count(i)){
      prime.erase(i);
      }
      else{
        finish=false;
      }
      while(x%i==0)x/=i;
    }
  }
  if(prime.count(x)){
    prime.erase(x);
    return true;
  }
  if(x!=1) return false;
  return finish;
}

int main() {
  //準備
  int64_t MAX=1000000;
  vector<bool> Prime(MAX,true);
  for(int64_t i=2;i*i<=MAX;i++){
    if(Prime[i]){
      int64_t k=2;
      while(i*k<=MAX){
        Prime[i*k]=false;
        k++;
      }
    }
  }
  
  set<int64_t> prime;
  for(int64_t i=2;i<MAX;i++){
    if(Prime.at(i)){
      prime.insert(i);
    }
  }
     
  //処理
  bool coprime=true;
  int64_t N,total; cin>>N;
  rep(i,N){
    int64_t K; cin>>K;
    if(coprime){
      bool temp=soin(prime,K);
      if(!temp){
        coprime=false;
      }
    }
    if(i==0) total=K;
    else total=gcd(total,K);
  }
  
  //出力
  if(coprime) cout<<"pairwise coprime";
  else if(total==1) cout<<"setwise coprime";
  else cout<<"not coprime";
}


Measured memory_bytes: 7432
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> c(h);
    for (int i=0; i<h; i++) cin >> c[i];

    int ans = 0;
    for (int i=0; i<(1<<h); i++) {
        for (int j=0; j<(1<<w); j++) {

            int cnt = 0;
            for (int l=0; l<h; l++) {
                if ((i>>l)&1) continue;
                for (int m=0; m<w; m++) {
                    if (j>>m&1) continue;
                    if (c[l][m] == '#') cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3156
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
    int h, w;
    cin >> h >> w;
    vector<vector<char>>p(h+5,vector<char>(w+5));

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

        for(int j=1;j<w+1;j++) cin >> p[i][j];
    }

    int cnt = 0;
    int ans = 0;
    
 
        int X = 0, Y = 0;
        bool F = 0;
        for (int i = 1; i < h+1; i++) {
            for (int j = 1; j < w+1; j++) {
                if (F)break;
            //    cout << p[i][j] << endl;;
          //      cout << i << j;
              

                if (p[i][j] == '.') {
                    X = i; Y = j;
                    int t = 0;
                    queue<int>c, d;

                    c.push(X), d.push(Y);
                          bool f[25][25] = {};
                int r[25][25] = {};
      
            while (c.size()) {

                int x = c.front(), y = d.front();
                f[x][y] = 1;
                ans = max(ans, r[x][y]);
                if (!f[x + 1][y] && p[x + 1][y] == '.') { c.push(x + 1), d.push(y), r[x + 1][y] = max(r[x + 1][y], r[x][y] + 1); }
                if (!f[x - 1][y] && p[x - 1][y] == '.')c.push(x - 1), d.push(y), r[x - 1][y] = max(r[x - 1][y], r[x][y] + 1);
                if (!f[x][y + 1] && p[x][y + 1] == '.')c.push(x), d.push(y + 1), r[x][y + 1] = max(r[x][y + 1], r[x][y ] + 1);
                if (!f[x][y - 1] && p[x][y - 1] == '.')c.push(x), d.push(y - 1), r[x][y - 1] = max(r[x][y - 1], r[x][y ] + 1);

                if (!f[x + 1][y])cnt++;
                if (!f[x - 1][y])cnt++;
                if (!f[x][y + 1])cnt++;
                if (!f[x][y - 1])cnt++;



                f[x + 1][y] = 1;
                f[x - 1][y] = 1;
                f[x][y + 1] = 1;
                f[x][y - 1] = 1;

                c.pop(), d.pop();
             //   cout << x << " " << y << " " << t << endl;;

            }

            
        }
               
                }

            
        
      //  cout << X << Y << endl;
        
       


       
       

    }
    cout << ans << endl;

    
    return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}

ll fac[300001],finv[300001],inv[300001];//Nの制約
void table(){fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;for(ll i=2;i<300001;i++){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
ll comb(ll n,ll k){if(n<k) return 0;if(n<0 || k<0) return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
	table();
	//input
	ll N,M; cin>>N>>M;

	//solve
	if(abs(N-M)>1){
		cout<<0;
	}
	else{
		if(N==M){
			cout<<(2*fac[N]*fac[M])%MOD;
		}
		else{
			cout<<(fac[N]*fac[M])%MOD;
		}
	}
}

Measured memory_bytes: 7296
#include<iostream>
#include<queue>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
using namespace std;

int main()
{
	int N, H[20];
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> H[i];

	int count = 0;
	for (int i = 0; i < N; i++)
	{
		int tmp = 0;
		for (int j = 0; j < i; j++)
		{
			if (H[i] < H[j])
			{
				tmp++;
				break;
			}
		}

		if (tmp == 0)
			count++;
	}

	cout << count;
	return 0;
}

Measured memory_bytes: 256
S = input()

count = 0
ans = True

if S[0] != "A":
    ans = False
if not "C" in S[2:-1]:
    ans = False
for s in S:
    if s.isupper():
        count += 1
if count > 2:
    ans = False

print("AC" if ans else "WA")


Measured memory_bytes: 2940
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n=[],o=0;o<t;o++){var u=r[o+1].split(" "),i=Number(u[0]),f=Number(u[1]);n.push({x:i,y:f})}for(var l=[],c=0;c<t;c++){var a=r[c+1+t].split(" "),p=Number(a[0]),s=Number(a[1]);l.push({x:p,y:s})}n.sort(function(e,r){return r.x-e.x}),l.sort(function(e,r){return e.x-r.x});for(var d=0,y=0;y<t;y++){for(var b=3*t,x=-1,v=0;v<t;v++)n[y].x>=l[v].x||n[y].y>=l[v].y||l[v].y<b&&(b=l[v].y,x=v);-1!=x&&(d+=1,l[x]=-1)}console.log(d)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 7756
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

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

    vector<ll> dp(n+1);
    dp[0] = 0;
    dp[1] = 0;

    ll accum = a[0];
    IFOR(i, 2, n){
        if(i % 2 == 0){
            dp[i] = max(dp[i-2] + a[i-1], accum);
        }
        else{
            accum += a[i-1];
            dp[i] = max(dp[i-2] + a[i-1], dp[i-1]);
        }
    }

    cout << dp[n] << endl;

    
    return 0;
}

Measured memory_bytes: 6056
#include<iostream>
using namespace std;
int p[1<<17],r[1<<17];
int find(int a){return a-p[a]?p[a]=find(p[a]):a;}
int n,m;
int P[1<<17];
main()
{
	cin>>n>>m;
	for(int i=0;i++<n;)
	{
		p[i]=i;
		cin>>P[i];
	}
	for(int i=0;i<m;i++)
	{
		int x,y;cin>>x>>y;
		x=find(x);y=find(y);
		if(x-y)
		{
			if(r[x]<r[y])p[x]=y;
			else
			{
				p[y]=x;
				if(r[x]==r[y])r[x]++;
			}
		}
	}
	int cnt=0;
	for(int i=0;i++<n;)cnt+=find(P[i])==find(i);
	cout<<cnt<<endl;
}


Measured memory_bytes: 1408
from heapq import heappop, heappush, heapify

INF = float("inf")
n, m = map(int, input().split())
idx = [[i*3 + j for j in range(3)] for i in range(n)]
g = [[] for _ in range(n*3)]
for _ in range(m):
    u, v = map(lambda x: int(x)-1, input().split())
    for i in range(3):
        g[idx[u][i]].append((idx[v][(i+1) % 3], 1))
s, t = map(lambda x: int(x)-1, input().split())

def dijkstra(graph, n, s):
    d = [INF] * n
    d[s], q = 0, []
    heappush(q, (0, s))
    while q:
        dist, v = heappop(q)
        if d[v] < dist: continue
        for nv, cost in graph[v]:
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                heappush(q, (d[nv], nv))
    return d

res = dijkstra(g, n*3, idx[s][0])[idx[t][0]]
print(-1 if res == INF else res // 3)


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

using namespace std;

#define debug(x) cerr << "  - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
const int N = 1e5 + 5;

int a[N];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	int ans = 0;
	for(int i = 1; i <= n - 1; i++){
		if(a[i] == i){
			swap(a[i], a[i + 1]);
			ans++;
		}
	}
	if(a[n] == n) ans++;
	cout << ans << endl;
	return 0;
}
// 3 2 

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

int main() {
	int a;
	string s;
	cin >> s;
	a = 0;
	for(int i = 0; i < 4; i++){
		if(s[i] == '+'){
			a++;
		}else{
			a--;
		}
	}
	cout << a << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;

//struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
using namespace std;
string s;
int len;
bool dfs(int d) {
	if (d == len) return 1;
	if (d > len) return 0;
	if (s[d] == 'e') {
		if (d + 5 < len && s.substr(d, 6) == "eraser") return dfs(d + 6);
		if (d + 4 < len && s.substr(d, 5) == "erase") return dfs(d + 5);
		return 0;
	}
	else if (s[d] == 'd') {
		if (d + 6 < len && s.substr(d, 7) == "dreamer") if(dfs(d+7))return 1;
		if (d + 4 < len && s.substr(d, 5) == "dream") return dfs(d + 5);
		return 0;
	}
	return 0;
}
int main() {
	cin >> s;
	len = s.size();
	if (dfs(0)) cout << "YES" << '\n';
	else cout << "NO" << '\n';
}


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

#define M 1000000007

map<long long, long long> memo;
long long f(long long n) {
    if (n < 2) return n+1;
    if (memo.find(n) == memo.end()) {
        if (n % 2 == 0) memo[n] = (f(n/2) + 2 * f(n/2-1)) % M;
        else memo[n] = (2 * f(n/2) + f(n/2-1)) % M;
    }
    return memo[n];
}

int main() {
    long long n; cin >> n;
    cout << f(n) << endl;
}


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

const int MOD = 1e4;
int memo[501][10][2][2][500];
string S;
int N, M;

int dfs(int i, int p, bool up, bool tight, int tot) {
  if (i == N) return tot == 0;
  int& r = memo[i][p][up][tight][tot];
  if (r != -1) return r;
  int x = S[i] - '0';
  int L = 0, R = 10;
  if (up) {
    L = p + 1;
  } else {
    R = p;
  }
  if (tight) R = min(R, x + 1);
  r = 0;
  for (int j = L; j < R; j++) {
    r += dfs(i + 1, j, !up, tight && j == x, (10 * tot + j) % M);
  }
  return r %= MOD;
}

int solve(string s) {
  S = s;
  N = s.size();
  memset(memo, -1, sizeof(memo));
  int r = 0;
  for (int k = 0; k < N; k++) {
    int x = S[k] - '0';
    int L = 1, R = 10;
    if (k == 0) R = min(R, x + 1);
    for (int i = L; i < R; i++) {
      bool tight = k == 0 && i == x;
      r += dfs(k + 1, i, 1, tight, i % M);
      if (k < N - 1) { r += dfs(k + 1, i, 0, tight, i % M); }
    }
    r %= MOD;
  }
  return r;
}

string decr(string s) {
  for (int i = s.size() - 1; i >= 0 && s[i]-- == '0'; s[i++] = '9');
  return s.substr(s.size() > 1 && s[0] == '0');
}

int main() {
  string A, B;
  cin >> A >> B >> M;
  cout << (solve(B) + MOD - solve(decr(A))) % MOD << endl;
}

Measured memory_bytes: 42408
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = 0;
		// 文字列の入力
		int[] d = new int[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
		} 
		for(int i = 0; i < a; i++){
			if(d[i] >= b){
				c ++;
			}
		}
		System.out.println(c);
		
		
	}
}

Measured memory_bytes: 59152
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
vector<string> vs(8);
string t = "ox";
int MAX, MAXy, MAXx, my, op;
int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dx[8] = {1, 0, -1, -1, 1, 1, -1, 0};

bool contain(int y, int x) {
  return (0 <= y && y < 8 && 0 <= x && x < 8);
}

void check(int y, int x, int dg) {
  if(dg == 0 && vs[y][x] != '.') return;
  int cnt = 0;
  FOR(i,0,8) {
    int tmp = 0;
    FOR(j,1,8) {
      int ny = y + dy[i] * j;
      int nx = x + dx[i] * j;
      if(!contain(ny,nx) || vs[ny][nx] == '.') break;
      if(vs[ny][nx] == t[op]) tmp++;
      else {
        if(dg == 1) {
          FOR(k,1,j+1) {
            vs[y+dy[i]*k][x+dx[i]*k] = t[my];
          }
        }
        cnt += tmp;
        break;
      }
    }
  }
  if(MAX < cnt) {
    MAXy = y;
    MAXx = x;
    MAX = cnt;
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  FOR(i,0,8) cin >> vs[i];
  int g = 0;
  for(int i = 0;;i++) {
    my = i % 2;
    op = (i + 1) % 2;
    MAX = 0;
    MAXy = 0;
    MAXx = 0;
    if(my == 0) {
      FOR(j,0,8) FOR(k,0,8) check(j,k,0);
    } else {
      for(int j = 7; j >= 0; j--) for(int k = 7; k >= 0; k--) check(j,k,0);
    }
    if(MAX == 0) g++;
    else g = 0;
    if(g == 2) break;
    if(MAX != 0) {
      vs[MAXy][MAXx] = t[my];
      check(MAXy,MAXx,1);
    }
  }
  FOR(i,0,8) cout << vs[i] << endl;;
  return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=100010;
const ll mod=1e9+7;

int n,m;
bool done[10];
vector<int> v[10];
int ans=0;

void dfs(int x, int cnt){
  if(cnt==n){ans++;}
  for(auto to:v[x]){
    if(!done[to]){
      done[to]=true;
      dfs(to,cnt+1);
      done[to]=false;
    }
  }
}

int main(){
  cin >> n >> m;
  for(int i=0; i<m; i++){
    int a,b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  done[1] = true;
  dfs(1,1);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long N, sum=0;
long long a[11];
int main(){
	cin>>N;
	a[1]=N/1000000000;
	a[2]=N/100000000%10;
	a[3]=N/10000000%10;
	a[4]=N/1000000%10;
	a[5]=N/100000%10;
	a[6]=N/10000%10;
	a[7]=N/1000%10;
	a[8]=N/100%10;
	a[9]=N/10%10;
	a[10]=N%10;
	for(int i=1;i<=10;++i){
		sum+=a[i];
	}
	if(N%sum == 0){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];

vector<int> v;
int L[200009], R[200009];
int C[510][510], X[510][510];
double calc_d(double a, double b){
    return sqrt(a*a+b*b);
}
int main(void) {
    int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
    int x2_d= x2-x1, y2_d=y2-y1;
    int x4= -1*y2_d+x1, y4=x2_d+y1;
    int x1_d = x1-x2, y1_d=y1-y2;
    int x3 = y1_d+x2, y3=-x1_d+y2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 6912
n,x,y = map(int, input().split())

from heapq import heappush, heappop
def dks(g,start,num_v):
    INF=10**10
    visited = set()
    hq = []
    heappush(hq, (0,start))
    cost = [INF] * num_v
    while hq:
        shortest, i = heappop(hq)
        if i in visited:
            continue
        visited.add(i)
        cost[i] = shortest
        for j, t in g[i]:
            if j in visited:
                continue
            heappush(hq, (shortest + t, j))
    return cost

link = [[] for _ in range(n)]
for i in range(n-1):
    link[i].append([i+1,1])
    link[i+1].append([i,1])
link[x-1].append([y-1,1])
link[y-1].append([x-1,1])

ans=[0]*(n-1)
for i in range(n):
    res = dks(link,i,n)
    for r in res:
        ans[r]+=1
for i in range(1,len(ans)):
    print(ans[i]//2)

print(0)

Measured memory_bytes: 119260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

const long long mod = 1e9 + 7;

long long mod_pow(long long a, long long b, long long mod)
{
    if(b == 0) return 1;
    if(b & 1) return (a * mod_pow(a, b-1, mod)) % mod; 
    else 
    {
        long long x = mod_pow(a, b/2, mod);
        return (x * x) % mod;
    }
}

long long mod_comb(long long a, long long b, long long mod)
{
    b = min(a - b, b);
    long long faca = 1, facb = 1;
    for(int i=0; i<b; ++i)
    {
        faca = (faca * (a - i)) % mod;
        facb = (facb * (b - i)) % mod; 
    }

    return (faca * mod_pow(facb, mod-2, mod)) % mod;
}

int main()
{
    long long X, Y; cin >> X >> Y;

    int step = 0;
    while(true)
    {
        ++step;
        if(step > Y || step > X)
        {
            cout << 0 << endl;
            return 0;
        }
        if(Y - step + X - step == step)
            break;
    }

    long long X2 = X - step, X1 = step - X2;

    cout << mod_comb(X1 + X2, X1, mod) << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = max(k + 1 - a[i], 0);
  }
  V<> idx(n);
  iota(begin(idx), end(idx), 0);
  int m = n * (k + 1) - k;
  V<> res(m, -1);
  for (int i = 1; i <= k; ++i) {
    sort(begin(idx), end(idx), [&](int i, int j) { return b[i] > b[j]; });
    if (res[(i - 1) * (n - 1)] != idx[0]) {
      res[i * (n - 1)] = idx[0];
      --b[idx[0]];
    } else {
      res[i * (n - 1)] = idx[1];
      --b[idx[1]];
    }
  }
  for (int i = 0; i <= k; ++i) {
    V<> js;
    for (int j = 0; j < n; ++j) if (j != res[i * (n - 1)] and j != res[(i + 1) * (n - 1)]) {
      js.push_back(j);
    }
    int p = i * (n - 1);
    for (int j : js) {
      while (res[p] != -1) ++p;
      res[p++] = j;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (count(begin(res), end(res), i) > a[i]) return cout << -1 << '\n', 0;
  }
  cout << m << '\n';
  for (int i = 0; i < m; ++i) {
    cout << res[i] + 1 << " \n"[i == m - 1];
  }
}

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

int main()
{
    string s;
    const string ans = "CODEFESTIVAL2016";
    cin >> s;
    int out = 0;
    for (int i = 0; i < ans.length(); ++i)
    {
        if (s[i] != ans[i])
        {
            out++;
        }
    }
    cout << out << endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

int main() {
  int N, D;
  cin >> N >> D;
  vector<int> cor[N];
  int X;
  rep(i, 0, N) {
    rep(j, 0, D) {
      cin >> X;
      cor[i].pb(X);
    }
  }
  int ans = 0;
  rep(i, 0, N - 1) {
    vector<int> p1 = cor[i];
    rep(j, i+1, N) {
      int sqdis = 0;
      vector<int> p2 = cor[j];
      rep(k, 0, D) {
        sqdis += (p1[k] - p2[k]) * (p1[k] - p2[k]);
      }
      int dis = sqrt(sqdis);
      if (dis * dis == sqdis) {
        ans++;
      }
    }
  }

  cout << ans << endl;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>

using namespace std;

const int INF = 1e9 + 5;

int main(){

    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for(int &x : h){
        scanf("%d", &x);
    }

    vector<int> dp(n, INF); 
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j : {i+1, i+2}){
            if(j < n){
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    printf("%d\n", dp[n-1]);

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
const ull B = 1000000007ULL;

int main(){
    int N,M;
    string s;
    cin >> N >> M >> s;
    vector<ull> pow(N+1),hash(N+1);
    pow[0] = 1; hash[0] = 0;
    for(int i = 0 ; i < N ; i++){
        hash[i+1] = hash[i]*B + s[i];
        pow[i+1] = pow[i]*B;
    }
    int L = 0, R = 0;
    set<ull> st;
    while(M--){
        cin >> s;
        if(s == "L++"){
            L++;
        }else if(s == "L--"){
            L--;
        }else if(s == "R++"){
            R++;
        }else{
            R--;
        }
        st.insert(hash[R+1]-hash[L]*pow[R-L+1]);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 20024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] px = new int[90001];
    int[] py = new int[90001];
    int H = sc.nextInt();
    int W = sc.nextInt();
    int D = sc.nextInt();
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int A = sc.nextInt();
          px[A] = i;
          py[A] = j;
      }
    }
    int[] d = new int[90001];
    for (int i=D+1; i<=H*W; i++) {
      d[i] = d[i-D] + Math.abs(px[i]-px[i-D]) + Math.abs(py[i]-py[i-D]);
    }
    int Q = sc.nextInt();
    for (int i = 0; i < Q; i++) {
      int L = sc.nextInt();
      int R = sc.nextInt();
      System.out.println(d[R]-d[L]);
    }
  }
}


Measured memory_bytes: 96252
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()

typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> Array;
typedef vector<int> LArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

int itiv;
inline int getInt() { return (cin >> itiv, itiv); }
void readAll(Array& vec, int n) { for (int i = 0; i < n; i++) cin >> vec[i]; }
inline bool between(int first, int last, int n) { return first <= n && n <= last; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int m, n;
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

const int MOD = 10007;

int toBit(char c)
{
	switch (c)
	{
	case 'J':
		return 1;
	case 'O':
		return 2;
	case 'I':
		return 4;
	default:
		return 0;
	}
}
//day, people
int dp[1001][8];
int main(void)
{
	while(cin >> n && n)
	{
		memset(dp, 0, sizeof(dp));
		dp[0][1] = 1;
		for (int i = 1; i <= n; i++)//日付
		{
			char c; cin >> c;
			int master = toBit(c);
			for (int j = 0; j < 8; j++)//前日出た人
			{
				for (int k = 0; k < 8; k++)//今日出た人
				{
					if(!(master & k) || !(j & k)) continue;
					dp[i][k] = (dp[i][k] + dp[i - 1][j]) % MOD;
				}
			}
		}

		cout << accumulate(dp[n], dp[n] + 8, 0) % MOD << endl;
	}
	return 0;
}

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

typedef long long int ll;

int main(void) {
    string S, T;
    
    cin >> S;
    cin >> T;

    if (T.substr(0, S.length()) == S) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 222222


vll edge[MAX];
ll color[MAX];

bool dfs(ll cur, ll col) {
	color[cur] = col;
	rep(i, edge[cur].size()) {
		if (color[edge[cur][i]] == col) return false;
		if (!color[edge[cur][i]]) if (!dfs(edge[cur][i], -col)) return false;
	}
	return true;
}

bool Bipartite() {
	bool ret = true;
	FOR(i, 1, n + 1) {
		if (!color[i]) {
			if (!dfs(i, 1)) ret = false;
		}
	}
	return ret;
}


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

	cin >> n >> m;
	ll a, b;
	rep(i, m) {
		cin >> a >> b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	if (Bipartite()) {
		a = b = 0;
		FOR(i, 1, n + 1) {
			if (color[i] == 1) a++;
			else b++;
		}
		cout << a * b - m << endl;
	}
	else {
		cout << n * (n - 1) / 2 - m << endl;
	}





	return 0;
}


Measured memory_bytes: 10368
#include<iostream>

using namespace std;

int main() {
	int K, S, X, Y, Z, A = 0;

	cin >> K >> S;

	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			X = i;
			Y = j;
			Z = S - X - Y;
			if (Z >= 0 && Z <= K) {
				if (X + Y + Z == S) {
					A++;
				}
			}
		}
	}
	cout << A << endl;

	return 0;
}

Measured memory_bytes: 256
# Problem C - Forbidden List
# input
X, N = map(int, input().split())

# check
if N==0:
    print(X)
else:
    p_nums = list(map(int, input().split()))
    nums = [i for i in range(-1000, 1001)]
    # remove process
    for p in p_nums:
        nums.remove(p)
    point = 0
    # greedy
    kyori = float('INF')
    for n in nums:
        tmp = min(abs(X-n), abs(n-X))
        if tmp<kyori:
            point = n
            kyori = tmp

    # output
    print(point)


Measured memory_bytes: 9220
#include <iostream>
#include <string>
using namespace std;
int main(){
	bool first = true;
		
	    string s;
		int t=0,u=0;
		
		cin>>s;
		for(int i=0;i<s.size();i++){
			
			if(s[i]=='A' && first){
				
				t=i;
				
				first = false;
		    }
			if(s[i]=='Z'  ){
				u=i;
				
			}
				
		}
		cout<<u+1-t;
		return 0;
	}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);

		String s=sc.next();		//sは3文字からなる文字列
		
		int n=s.length();		//文字の長さを取得
		
		if(s.substring(0,(n-1)/2).equals(s.substring((n+1)/2,n))) {
		System.out.println("Yes");
		}else {
		System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}


// End of template code!
int main() 
{
    buff();
    long long val;
    cin >> val;
    if(val == 1)
    {
        cout << "0\n";
        return 0;
    }
    vector<long long> fact;
    for(ll x = 2; x * x <= val; ++x)
    {
        if(val % x == 0)
        {
            ll pot = 0;
            while(val % x == 0)
            {
                ++pot;
                val /= x;
            }
            fact.emplace_back(pot);
        }
    }
    if(val > 1ll) fact.emplace_back(1ll);

    long long ans = 0ll;
    auto contrib = [&] (ll v) {
        ll max_dist = 0ll;
        ll rem = 1ll;
        while(v > 0) {
            if(rem <= v) {
                v -= rem;
                rem++;
                max_dist++;
            }
            else break;
        }
        return max_dist;
    };
    
    for(const auto& f : fact)
    {
        ans += contrib(f);
    }


    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = int(a); i <= int(b); i++)
using namespace std;
typedef long long llong;
const int N = 100005;

int x[N], y[N], a[N], b[N], w, h, n;

llong get(int x, int y) {
    llong sum = 0LL, maxx = 0LL;
    foru(i, 1, n) {
        sum += 2LL * llong(abs(a[i] - x) + abs(b[i] - y));
        maxx = max(maxx, llong(abs(a[i] - x) + abs(b[i] - y)));
    }
    return sum - maxx;
}

int main() {
    //freopen("a.txt", "r", stdin);
    scanf("%d%d%d", &w, &h, &n);
    foru(i, 1, n) {
        scanf("%d%d", &x[i], &y[i]);
        a[i] = x[i], b[i] = y[i];
    }
    sort(x+1, x+n+1);
    sort(y+1, y+n+1);
    int nn = n/2;
    llong res = LONG_LONG_MAX;  int xx, yy;
    foru(i, max(nn - 10, 1), min(nn + 10, n))
        foru(j, max(nn - 10, 1), min(nn + 10, n)) {
            llong sum = get(x[i], y[j]);
            if (sum < res) {
                res = sum;
                xx = x[i], yy = y[j];
            }
        }
    cout << res << endl << xx << ' ' << yy << endl;
}

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

int main() {
  int N,K,num;
  cin >> N >> K;
  num = 1;
  for (int i = 0 ; i < N ; i++){
    if (num < K) num *=2;
    else num += K;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N, K; cin >> N >> K;
  int P[N];
  for (int i = 0; i < N; i++) cin >> P[i];

  vector <bool> now(N);
  priority_queue <int> Mque;
  priority_queue <int, vector<int>, greater<int> > mque;

  for (int i = 0; i < K; i++){
    now[P[i]] = true;
    Mque.push(P[i]); mque.push(P[i]);
  }
  
  int ans = 1;
  for (int i = K; i < N; i++){
    if (mque.top() == P[i - K] && Mque.top() < P[i]){

    }else{
      ans++;
    }
    now[P[i]] = true; now[P[i - K]] = false;
    mque.push(P[i]); Mque.push(P[i]);

    while (now[mque.top()] == false){
      mque.pop();
    }
    while (now[Mque.top()] == false){
      Mque.pop();
    }
  }

  int cnt = 1, C = 0;
  for (int i = 0; i < N - 1; i++){
    if (P[i] < P[i + 1]){
      cnt++;
    }else{
      if (cnt >= K) C++;
      cnt = 1;
    }
  }
  if (cnt >= K) C++;

  ans -= max(0, C - 1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2804
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main() {
  char S[4];
  cin>>S;
  if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0]){
    cout<<"Yes";
  }else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const double pi=acos(-1.0);
const int N=3000+5;
int n,L,a[N];
signed main(){
	cin>>n>>L;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	long double x=0,y=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i!=j){
				int l=a[i],r=(a[i]<a[j])?a[j]:a[j]+L;
				int tmp=(j-i+n)%n+1;
				x+=(long double)(n-tmp)*cos(pi*(l+r)/L);
				y+=(long double)(n-tmp)*sin(pi*(l+r)/L);
			}
	long long c=1ll*n*(n-1)*(n-2)/6;
	//cout<<x<<" "<<y<<endl;
	printf("%.9lf %.9lf",(double)x/c,(double)y/c);
	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


int n;
int v[100000];

signed main(){
    map<int, int> even, odd;
    cin >> n;
    REP(i, n){
        cin >> v[i];
    }
    REP(i, n){
        if(i % 2 == 0) even[v[i]]++; 
        else odd[v[i]]++;
    }
    vector<pint> E, O;
    for(auto p : even){
        E.push_back(pint(p.second, p.first));
    }
    for(auto p : odd){
        O.push_back(pint(p.second, p.first));
    }
    E.push_back(pint(0, -1)), O.push_back(pint(0, -1));
    sort(ALL(E), greater<pint>());
    sort(ALL(O), greater<pint>());
    if(E[0].second == O[0].second){
        PRINT(n - max(E[0].first + O[1].first, E[1].first + O[0].first));
    }else{
        PRINT(n - E[0].first - O[0].first);
    }
    return 0;
}

Measured memory_bytes: 6520
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    vector<ll> data(n);
    rep(i,0,n){
        cin >> data[i];
    }
    ll ans = 0;
    sort(data.begin(),data.end());
    rep(i,0,n){
        
        rep(j,i+1,n){

            rep(k,j+1,n){
                //cout<<data[i]<<data[j]<<data[k];
                if(data[i]==data[j]||data[i]==data[k]||data[j]==data[k]){
                    continue;
                }
                //ans++;
                if(data[i]+data[j]>data[k]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    for (int i = A; i < max(C, D) - 2; i++) {
        if (S[i] == '#' && S[i + 1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (C < D) {
        cout << "Yes" << endl;
    }
    else {
        for (int i = B - 2; i < D - 1; i++) {
            if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
    int n, l;
    cin >> n >> l;

    vector<int> x(n);
    for (int i = 0; i < n; i++)
    {
        x[i] = l + (i + 1) - 1;
    }

    vector<int> s(n);
    for (int j = 0; j < n; j++)
    {
        s[j] = abs(l + (j + 1) - 1);
    }

    vector<int>::iterator iter = min_element(s.begin(), s.end());
    size_t min = distance(s.begin(), iter);

    cout << accumulate(x.begin(), x.end(), 0) - x[min] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int main(){
  int A[MAX], H, i, n;
  scanf("%d",&H);
  for(i=1; i<=H; i++)scanf("%d",&A[i]);

  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i != 1){
      if(i % 2 == 0)n = i / 2;
      else n = (i - 1) / 2;
      printf("parent key = %d, ",A[n]);
    }
    if(i * 2 <= H)printf("left key = %d, ",A[i*2]);
    if(i * 2 + 1 <= H)printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
n = input()
#n = '0007'
ops_list = ['+++', '++-', '+-+', '-++', '+--', '-+-', '--+', '---']

for ops in ops_list:
    expression = '{}{}{}{}{}{}{}'.format(n[0], ops[0], n[1], ops[1], n[2], ops[2], n[3])
    if eval(expression) == 7:
        print('{}=7'.format(expression))
        break

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

using namespace std;

#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
    int a;cin>>a;
    ld b[a]; ld sum=0;
    for(int i=0;i<a;i++)cin>>b[i];
    for(int i=0;i<a;i++){
        sum+=(1/b[i]);
    }
    cout << 1/sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }


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

    int N;
    cin >> N;

    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
        int s = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) s++;
        }
        if (s == 8) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def eprint(s):
    sys.stderr.write('DEBUG: {}\n'.format(s))
    return

def main():
    x, y = map(int, input().split())
    cnt = 1
    
    a = x
    while True:
        eprint(a)
        if a*2 > y:
            print(cnt)
            return
        else:
            a *= 2
            cnt += 1

    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


int main(void){
    vector<ll> inv(100005);
    inv.at(1) = 1;
    for(int i = 2; i < 100005; i++){
        inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
    }
    
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N+1); for(ll i = 1; i < N+1; i++) cin >> a.at(i);
    
    sort(a.begin() + 1, a.end(), greater<ll> ());
    
    ll ans = 0;
    ll bi = 1;
    ll tmp;
    for(ll i = 1; i <= N - K + 1; i++){
        tmp = ((a.at( N - K + 2 - i ) - a.at( K + i - 1 )) + 2*MOD) % MOD;
        tmp = tmp * bi % MOD;
        ans = (ans + tmp + MOD) % MOD;
        bi = bi * ( K + i - 1 ) % MOD;
        bi = bi * inv.at( i ) % MOD;
    }
    
    printf("%lld\n", ans);
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	ll a; string s; cin >> a >> s;

	int b = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
	
	cout << a * b / 100 << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
typedef long long int ll;
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<l;j++) 
#define pb push_back 
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<"\n" 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
const ll MOD = 1e9 + 7;
const int N = 100005;
const ll INF = 1e9;
using namespace std;
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int arr[17][17];
	forn for(int j=0;j<n;j++) cin >> arr[i][j];
	ll cnt = 0;
	ll ans = 0;
	ll max_mask = 1 << n;
	vector<ll> dp(max_mask,0);
	for (ll k = 0; k < (1 << n); k++)
	{
		for (int x = 0; x < n; x++)
		{
			if (k&(1 << x)) {
				for (int j = x + 1; j < n; j++)
				{
					if (k&(1 << j)) dp[k] += arr[x][j];
				}
			}
		}
	}
	for (int mask = 1; mask < max_mask; mask++)
	{
		for (int ss = mask; ss > 0; ss = (ss - 1)& mask)
		{
			dp[mask] = max(dp[mask], dp[ss] + dp[ss ^ mask]);
		}
	}
	cout << dp[max_mask - 1];
	return 0;
	
}

Measured memory_bytes: 768