akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
    vector<vector<int>> to(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    for (int x: to[0]) {
        for (int y: to[x]) {
            if(y==n-1) {
                cout << "POSSIBLE" << "\n";
                return 0;
            }
        }
    }
	cout << "IMPOSSIBLE" << "\n";
	return 0;
}


Measured memory_bytes: 14884
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
int n;
scanf("%d",&n);
int a[2][n];
int tmp,i,j,tmp1;
for(i=0;i<2;i++)
	{
		for(j=0;j<n;j++)	
			{	
				scanf("%d",&a[i][j]);	
			}
	}
	tmp1=a[0][0];
		for(j=0;j<n;j++)	
			{	
				tmp1+=	a[1][j];
			}
	int m = 0;
	int p = n;
	while(p){
	i=0;
	tmp = 0;
	for(j=0;j<n;j++){
		if(j==m)
		{
			i=1;	
			tmp+=a[0][j];
		}
		tmp+=a[i][j];
	} 
	if(tmp>=tmp1) tmp1=tmp;
	p--;m++;
	}
	if(i==0) tmp+=a[1][n-1];
	printf("%d\n",tmp1);
	
}

Measured memory_bytes: 128
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll a, p; cin >> a >> p;
  p += a * 3;
  fin(p / 2);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <ll> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	ll ans1 = 0;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += A[i];
		if (i % 2 == 0) {
			if (sum <= 0) {
				ans1 += (1 - sum);
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				ans1 += (sum + 1);
				sum = -1;
			}
		}
	}
	ll ans2 = 0;
	sum = 0;
	for (int i = 0; i < n; i++) {
		sum += A[i];
		if (i % 2 == 1) {
			if (sum <= 0) {
				ans2 += (1 - sum);
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				ans2 += (sum + 1);
				sum = -1;
			}
		}
	} 
	cout << min(ans1, ans2);
}



Measured memory_bytes: 1024
#include <iostream>

typedef long long ll;

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

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

bool prime[100001];
void Eratosthenes(int n){ 
  for(int p=2; p*p<=n; p++){
    if(prime[p]){
      for(int i=p*2; i<=n; i += p)
          prime[i] = false;
      }
  }
}

int dp[100001];

int main(void){

  fill(&prime[0],&prime[100001],true);
  prime[0] = false;
  prime[1] = false;
  int Q;
  cin >> Q;
  int l[Q],r[Q];
  int M = 0;
  REP(i,Q){
    cin >> l[i] >> r[i];
    M = max(M,r[i]);
  }
  Eratosthenes(M);
  dp[3] = 1;
  for(int i = 5; i<=M;i+=2){
    if(prime[i] && prime[(i+1)/2]){
      dp[i] += dp[i-2]+1;
    }else{
      dp[i] += dp[i-2];
    }
  }
  REP(i,Q){
    cout << dp[r[i]] - dp[l[i]-2] << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
## 题意:
给出A,B
求有多少个数对(x,y)满足x*y<A*B
并且x各不相等 y各不相等

*/
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	int q;
	ll a,b,res,k;
	read(q);
	for (;q--;){
		read(a); read(b);
        k=sqrtl(a*b-1);
        res=2*k-1;
        if(k*(k+1)>a*b-1)res--;
        if(a==b)res++;
    	printf("%lld\n",res);
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================
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() {
  int N, M, K;
  ins(N, M, K);

  vi A(N), B(M);
  vector<ll> sumA(N+1, 0), sumB(M+1, 0);
  rep(i, N) {
    cin >> A[i];
    sumA[i+1] = sumA[i] + A[i];
  }
  rep(i, M) {
    cin >> B[i];
    sumB[i+1] = sumB[i] + B[i];
  }
  debug(sumB);
  int ans = 0;
  rep(i, N+1) {
    if (sumA[i] > K)
      break;
    int tmp = all(lower_bound, sumB, K - sumA[i]) - sumB.begin();
    if (!all(binary_search, sumB, K - sumA[i]))
      --tmp;
    if (chmax(ans, tmp + i)) {
      debug(ans, i);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8012
#include <iostream>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdio.h>
using namespace std;
typedef long long ll;

ll euclid(ll a, ll b)
{
    int nr = 0;
    while (b != 0)
    {
        int c = b;
        b = a % b;
        a = c;
        nr++;
    }
    return a;
}


int main()
{
    ll a, b, c ,d;
    cin >> a >> b >> c >> d;
    ll numbers = b - a + 1;
    ll nr1 = (b / c) - ((a-1)/ c);
    ll nr2 = (b / d) - ((a-1)/ d);
    ll nrr = (c * d) / euclid(c, d);
    ll nr3 = (b / (nrr)) - ((a-1)/ (nrr));
    cout << numbers - nr1 - nr2 + nr3;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n, m, x;
int a[120];
int t[120];

int main() {
	while(~scanf("%d %d %d", &n, &m, &x)) {
		memset(t, 0, sizeof(t));
		for(int i = 0; i < m; i++) scanf("%d", &a[i]);
		for(int i = 0; i < n; i++) t[a[i]] = 1;
		int c1 = 0, c2 = 0;
		for(int i = x; i < n; i++) {
			if(t[i] == 1) c1++;
		}
		for(int i = x; i > 0; i--) {
			if(t[i] == 1) c2++;
		}
		printf("%d\n", min(c1, c2));
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MAX 1e9 + 7
#define ll long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    int t;
//    cin>>t;
//    int x=1;
//    while(t--) {

      int k;
      cin>>k;
      int a,b;
      cin>>a>>b;
      int flg=0;
      for(int i=a;i<=b;i++){
          if(i%k==0){
              flg=1;
              break;
          }
      }
      if(flg){
          cout<<"OK"<<endl;
      }
      else{
          cout<<"NG"<<endl;
      }

//    }
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define INF 0x7FFFFFFF
const double EPS = 1e-10;


inline bool eq(double a, double b) { return fabs(b - a) < EPS;}

struct p_t{
  double x;
  double y;
};


int main(){
  int n;
  cin>>n;
  vector<p_t> a;
  p_t z;
  for(int i=0;i<n;i++){
    cin>>z.x>>z.y;
    a.push_back(z);
  }
  if((n&1)==0){
    z.x=(a[0].x+a[n/2].x)/2;
    z.y=(a[0].y+a[n/2].y)/2;
    int i;
    for(i=2;i<n/2;i++){
      if(eq(z.x,(a[i].x+a[i+n/2].x)/2)==0) break;
      if(eq(z.y,(a[i].y+a[i+n/2].y)/2)==0) break;
    }
    if(i==n/2){
      cout<<fixed<<z.x<<" "<<fixed<<z.y<<endl;
      return 0;
    }
  }
  cout<<"NA"<<endl;
  return 0;
}




Measured memory_bytes: 3304
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int h = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());

            double rect_l = m * 360.0 / 60.0; //長針
            double rect_s = (h * 60.0 + m) * 360.0 / (12.0 * 60.0); //短針
            double diff = rect_s - rect_l;
            if (diff > 180) diff = 360 - diff;
            double ans = Math.sqrt((a * a) + (b * b) - 2 * a * b * Math.cos(diff * (Math.PI / 180.0)));
            // 出力
            out.printf("%.13f\n", ans);

        }

    }
}



Measured memory_bytes: 36048
import sys
input = sys.stdin.readline
from typing import List

class DSU:
    def __init__(self, n: int) -> None:
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n
        stack = []
        while self.parent_or_size[a] >= 0:
            stack.append(a)
            a = self.parent_or_size[a]
        for i in stack:
            self.parent_or_size[i] = a
        return a

    def size(self, a: int) -> int:
        assert 0 <= a <= self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> List[List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]
        group_size = [0] * self._n
        for i in leader_buf:
            group_size[i] += 1
        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        result = [i for i in result if i]
        return result


n, q = map(int, input().split())
dsu = DSU(n)

for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        dsu.merge(u, v)
    else:
        print(1 if dsu.same(u, v) else 0)


Measured memory_bytes: 77108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll H,N;
    cin >>H>>N;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N){
        cin >>A[i]>>B[i];
    }
    vector<vector<ll>> dp(N+1,vector<ll>(20015,INF));
    rep(i,N){
        dp[i][0] =0;
    }
    rep2(i,N){
        rep(j,20010){
            if(j-A[i-1] >= 0){
                dp[i][j] = min({dp[i-1][j], dp[i-1][j-A[i-1]]+B[i-1], dp[i][j-A[i-1]]+B[i-1]});
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    ll ans = INF;
    rep3(i,H,20010){
        chmin(ans,dp[N][i]);
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 163536
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int X, Y;
	cin >> X >> Y;
	for (int i = 0; i <= X; i++) {
		int r = i * 2 + (X - i) * 4;
		if (r == Y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,c; cin >> n >> c;
    vvl r(3,vl(c,0));
    ll tab[c][c];
    rep(i,c) rep(j,c) cin >> tab[i][j];
    rep(i,n){
        rep(j,n){
            ll d; cin >> d; d--;
            r[(i+j+2)%3][d]++;
        }
    }
    ll ans = INF;
    rep(i,c){
        rep(j,c){
            rep(k,c){
                if(i==j || j==k || k==i) continue;
                ll sum = 0;
                rep(l,c){
                    sum += r[0][l] * tab[l][i];
                    sum += r[1][l] * tab[l][j];
                    sum += r[2][l] * tab[l][k];
                }
                ans = min(ans, sum);
                //if(ans == sum) cout << i << j << k << endl;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    cin >> n;
    rep(i,0,n){
	rep(j,0,n){
	    if(n == i*4 + j*7){
		Yes;
		ret 0;
	    }
	}
    }
    No;
    return  0;
}


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

int main()
{

    //cinの高速化
    cin.tie(0);
    ios::sync_with_stdio(false);

    double A, B;
    cin >> A;
    cin >> B;

    double C = (A + B) / 2;
    if (ceil(C) == floor(C))
    {
        cout << fixed;
        cout << setprecision(0) << C << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val in = io.StdIn.readLine.split(' ').map(_.toInt)

  val x1 = in(0)
  val y1 = in(1)
  val x2 = in(2)
  val y2 = in(3)

  def next(xx1: Int, yy1: Int, xx2: Int, yy2: Int) = {
    (xx2 - (yy2-yy1), yy2 + (xx2 - xx1))
  }

  val (x3, y3) = next(x1,y1,x2,y2)
  val (x4, y4) = next(x2,y2,x3,y3)

  val out = s"$x3 $y3 $x4 $y4"

  println(out)
}


Measured memory_bytes: 25412
H, W = [int(i) for i in input().split()]
S = [[i for i in input()] for j in range(H)]

T = [[0 if S[j][i] == '#' else 1 for i in range(W)] for j in range(H)]

for h in range(H):
    s = 0
    for w in range(W):
        if S[h][w] == '#':
            s = 0
            continue
        T[h][w] += s
        s += 1

for h in range(H):
    s = 0
    for w in range(W - 1, -1, -1):
        if S[h][w] == '#':
            s = 0
            continue
        T[h][w] += s
        s += 1

for w in range(W):
    s = 0
    for h in range(H):
        if S[h][w] == '#':
            s = 0
            continue
        T[h][w] += s
        s += 1

for w in range(W):
    s = 0
    for h in range(H - 1, -1, -1):
        if S[h][w] == '#':
            s = 0
            continue
        T[h][w] += s
        s += 1

print(max(max(t) for t in T))

Measured memory_bytes: 218632
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int k;
    cin>>k;

    int dp[11][10];
    memset(dp,0,sizeof(dp));

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

    for ( int i = 1 ; i <= 10 ; i++ )
    {
        for ( int j = 0 ; j < 10 ; j++ )
        {
            if ( i == 1 )
            {
                dp[i][j] = 1;
            } 
            else
            {
                dp[i][j] = ((j-1>=0)?dp[i-1][j-1]:0) + dp[i-1][j] + ((j+1<10)?dp[i-1][j+1]:0);
            }
        }
    }

    // for ( int i = 1 ; i <= 10 ; i++ )
    // {
    //     for ( int j = 0 ; j < 10 ; j++ )
    //     {
    //         out1(dp[i][j]);
    //     }
    // }
    int sum = 0;
    vector<int> ans;
    int pos = 1;
    for ( int i = 1 ; i <= 10 ; i++ )
    {
        for ( int j = pos ; j < 10 ; j++ )
        {
            if ( sum == k )
            {
                i = i-2;
                ans.pb(j);
                pos = (j+1>=10)?j:j+1;
                break;
            }
            sum += dp[i][j];
            if ( sum >= k )
            {
                sum -= dp[i][j];
                i = i-2;
                ans.pb(j);
                pos = (j-1>=0)?j-1:j;
                break;
            }
        }

        if ( i < 0 )
        {
            break;
        }
    }

    rep(i,0,ans.size())
    {
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

N = int(input())

B = [int(i) for i in input().split()]

ans = []

while (len(B) > 0):
  for _ in range(len(B)):
    for i in list(range(len(B)))[::-1]:
      if B[i] == i+1:
        ans.append(i+1)
        B.pop(i)
        break
  break

if len(ans) != N:
  print(-1)
else:
  for i in ans[::-1]:
    print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int K; cin >> K;
    const int D = 256;
    vec b(8);
    REP(i, 8){
        b[i] = K % D;
        K /= D;
    }
    string F = "FESTIVAL";

    string ans = "FESTIVA";
    //vec v(8, 1);
    //v[0] = 1;

    REP(d, 8){
        REP(i, b[d]) ans += 'L';
        if(d != 7){
            REP(i, 8){
                IFOR(j, d + 2, 8){
                    //v[j] += v[j - 1];
                    ans += F[j - 1];;
                }
                REP(j, bit(i)) {
                    //v[d + 1] += v[d];
                    ans += F[d];
                }
            }
        }
        //vdebug(v);
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
n,d=map(int,input().split())
r=[]
for _ in range(n):r.append(input().split(" "))

count=0
i=0
while i<n-1:
  j=i+1
  while j<n:
    temp=0
    k=0
    while k<d:
      temp+=(int(r[i][k])-int(r[j][k]))**2
      k+=1
    if temp**(1/2)==temp**(1/2)//1:
      count+=1
    j+=1
  i+=1
  
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n, m, t, a[100005];
bool b[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}

int main(){
	ll ai, bi, ans = 0, Q;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> m;
		a[m]++;
		b[m] = true;
	}
	cin >> Q;
	for(int i = 1 ; i <= 100000 ; i++)
		if( b[i] )
			ans += i * a[i];
	for(int i = 0 ; i < Q ; i++){
		cin >> ai >> bi;
		ans += (bi - ai) * a[ai];
		b[ai] = false;
		a[bi] += a[ai];
		a[ai] = 0;
	cout << ans << endl;
	}
	return(0);
}

Measured memory_bytes: 6840
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}

int highestPowerOf2(int n) 
{ 
    return (n & (~(n - 1))); 
} 

//--main function
int main(){
	string s;
	cin>>s;
	cout<<s[0];
	cout<<s.length()-2;
	cout<<s[s.length()-1];
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 256
def main():
	s = input()
	for i in range(len(s)-1):
		if s[i] == s[i+1]:
			print("{} {}".format(i+1,i+2))
			return
		elif i+2<len(s) and s[i] == s[i+2]:
			print("{} {}".format(i+1, i+3))
			return
	print("-1 -1")
	return

main()

Measured memory_bytes: 3188
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    map<ll,ll> P;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        P[a]++;
    }
    ll ans=0;
    for(auto x:P){
        if(x.second>=x.first){
            ans+=x.second-x.first;
        }
        else ans+=x.second;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6272
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
string s,t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s>>t;
	s+=t[t.size()-1];
	if(s==t)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3652
[x,y]=[int(i) for i in input().split()]
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if (a.count(x)==1 and a.count(y)==1) or (b.count(x)==1 and b.count(y)==1):
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 2940
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val s = Scanner.next

	pw.println(if (s == "RSR") 1 else s.count(_ == 'R'))
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54488
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}


int main() {
  int N ; cin >> N;
  int t[N+1]; t[0] = 0; 
  int x[N+1]; x[0] = 0; 
  int y[N+1]; y[0] = 0; 
  rep(i,N){
    cin >> t[i+1];
    cin >> x[i+1];
    cin >> y[i+1];
  }
  bool can = true;
  
  rep(i,N){
    int time = t[i+1]-t[i];
    int ew = abs(x[i+1]-x[i]);
    int ns = abs(y[i+1]-y[i]);
    if (time < ew+ns || time%2 != (ew+ns)%2){
      can = false;
      break;
    }
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

  



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
  int x,a;
  cin>>x>>a;
  if(x<a)
  {
    cout<<0<<endl;
  }
  else
  {
    cout<<10<<endl;
  }
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#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++)
const long long INF =  999999999;

int main(){
  string s;
  cin>>s;
  int n=s.length()/2;
  int ans=0;
  REP(i,n){
    if(s[i]!=s[s.length()-1-i])ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;

const int N = 21;
const int T = (1 << N);
const int mod = 1e9 + 7;

int dp[N][T];
int n;
bool arr[N][N];

inline int add(int a, int b, int mod = mod) {
  a += b;
  if(a >= mod) a -= mod;
  if(a < 0) a += mod;
  return a;
}

int rec(int cur, int mask) {
  if(cur == n) return 1;
  int& cm = dp[cur][mask];
  if(cm != -1) return cm;
  cm = 0;
  for(int i = 0; i < n; ++i) {
    if(arr[cur][i] && !(mask & (1 << i))) {
      cm = add(cm, rec(cur + 1, mask ^ (1 << i)));
    }
  }
  return cm;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  memset(dp, -1, sizeof dp);
  cin >> n;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < n; ++j) {
      cin >> arr[i][j];
    }
  }
  cout << rec(0, 0) << "\n";
}

Measured memory_bytes: 172288
#include <stdio.h>

int main() {
  int h1, m1, h2, m2, k, minute;
  scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
  m2 = m2 + h2 * 60;
  m1 = m1 + h1 * 60;

  if(m2 >= m1) minute = m2  - m1;
  else minute = m1 - m2;
  printf("%d\n", minute - k);
  return 0;
}


Measured memory_bytes: 1704
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x+mo_num)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;

int32_t main()
{
    IOS
    cin>>n>>m;
    fu(i,max((int)-1000000,m-n+1),min((int)1000000,m+n-1))cout<<i<<" ";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(n)]

def countingsort(A, B, k):
    """リストAの0からk以下の各要素の数（計n）をカウントするリストCを作成（初期値0）"""
    C = [0 for i in range(k)]
    """リストAの各要素の数をリストCに記録（Cのインデックス=Aの値）"""
    for i in range(n):
        C[A[i]] += 1
    """C[i]にi以下の値の出現数を記録"""
    for i in range(1, k):
        C[i] += C[i-1]
    """リストBに値をソートしつつ格納"""
    for i in reversed(range(n)):
        B[C[A[i]] - 1] = A[i]
        C[A[i]] -= 1

countingsort(A, B, max(A)+1)
print(*B)


Measured memory_bytes: 224396
N,A,B,C,D =map(int,input().split())
S = input()[min(A,B):max(C,D) + 1]

if C < D:
  if not "##" in S[B:D] and not "##" in S[A:C]:
    print("Yes")
  else:
    print("No")
else:
  if not "##" in S[B:D] and not "##" in S[A:C]:
    if "..." in S[B - 3:D]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
#define MAX 1000000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
    int i,key[MAX],n;
    
    cin >> n;
    
    for( i = 1;i <= n;i++)cin >> key[i];
    for( i = 1;i <= n;i++){
        cout << "node " << i << ": key = " << key[i] << ", ";
        if(parent(i) >= 1)cout << "parent key = " << key[i/2] << ", ";
        if(left(i) <= n)cout << "left key = " << key[2*i] << ", ";
        if(right(i) <= n)cout << "right key = " << key[2*i+1] << ", ";
        cout << endl;
    }
}


Measured memory_bytes: 3088
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

int f(int x) { return (x / 2) * 7 + (even(x) ? 1 : 6); }

bool isPrime(int x) {
  for (int i = 1; f(i) * f(i) <= x; i++) {
    if (x % f(i) == 0) return false;
  }
  return true;
}

main {
  vector<int> primes;
  for (int x = 1; f(x) <= 300000; x++) {
    if (isPrime(f(x))) primes.emplace_back(f(x));
  }
  while (true) {
    int n = in();
    if (n == 1) break;
    vector<int> ans;
    for (auto &x : primes) {
      if (n % x == 0) ans.emplace_back(x);
    }
    cout << n << ": " << ans << endl;
  }
}



Measured memory_bytes: 3248
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

ll H,W,D;
ll x[100000];
ll y[100000];
ll Q;
ll L[100000];
ll R[100000];
ll score[100000];

int main(){
    cin >> H >> W >> D;
    int n;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> n;
            x[n] = i+1;
            y[n] = j+1;
        }
    }
    cin >> Q;
    for(int i=0;i<Q;i++) cin >> L[i] >> R[i];
    for(int i=0;i<=D;i++) score[i] = 0;
    for(int i=D+1;i<=H*W;i++){
        score[i] = score[i-D] + abs(x[i]-x[i-D]) + abs(y[i]-y[i-D]);
    }
    for(int i=0;i<Q;i++){
        cout << score[R[i]] - score[L[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, n;
  cin >> x >> n;
  
  vector<int> p(n);
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  
  set<int> s;
  for(int k=0; k<n; k++){
    s.insert(p[k]);
  }
 
  int j=x;
  for(int m=1; m<101; m++){
    if(s.count(j)){
      if(m%2==0){
        j = j + m;
      }
      else{
        j = j - m;
      }
    }
    else{
      break;
    }
  }
  
  cout << j << endl;
}
 

Measured memory_bytes: 3640
#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=5e18;

int main() {
  ll n,W;
  cin >> n >> W;
  vec dp(W+1);
  vec v(n),w(n);
  for(ll i=0;i<n;i++) cin >> v[i] >> w[i];
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<W+1;j++) {
      if(j-w[i]>=0) {
        dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[W] << endl;
}


Measured memory_bytes: 3180
direct = ((0, -1), (0, 1), (-1, 0), (1, 0))

def comb(color, mp, pos):
  next_pos = pos[:]
  end = len(next_pos)
  ind = 0
  while ind < end:
    x, y = next_pos[ind]
    for dx, dy in direct:
      nx, ny = x + dx, y + dy
      if (nx, ny) not in next_pos and mp[ny][nx] == color:
        next_pos.append((nx, ny))
        end += 1
    ind += 1
  return next_pos

def search(rest, now_color, goal_color, pos, mp):
  if rest == 1:
    if now_color != goal_color:
      next_pos = comb(goal_color, mp, pos)
      return len(next_pos)
    return 0

  ret = 0
  for next_color in range(1, 7):
    if next_color != now_color:
      next_pos = comb(next_color, mp, pos)
      ret = max(ret, search(rest - 1, next_color, goal_color, next_pos, mp))
  return ret

def main():
  while True:
    h, w, c = map(int, input().split())
    if h == 0:
      break
    mp = [[-1] + list(map(int, input().split())) + [-1] for _ in range(h)]
    mp.insert(0, [-1] * (w + 2))
    mp.append([-1] * (w + 2))
    init_pos = [(1, 1)]
    init_color = mp[1][1]
    init_pos = comb(init_color, mp, init_pos)
    print(search(5, init_color, c, init_pos, mp))
main()


Measured memory_bytes: 5624
/**
 *    author:  tourist
 *    created: 23.03.2019 14:11:40       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b;
  while (!a.empty()) {
    int found = 0;
    for (int i = (int) a.size() - 1; i >= 0; i--) {
      if (a[i] == i + 1) {
        b.push_back(i + 1);
        a.erase(a.begin() + i);
        found = 1;
        break;
      }
    }
    if (!found) {
      cout << -1 << '\n';
      return 0;
    }
  }
  reverse(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    cout << b[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N=int(input())
a=[int(i) for i in input().split()]
c = [[0 for i in range(W)]for j in range(H)]
n=0
k=0
for i in range(H):
    for j in range(W):
        if i%2==0:
            c[i][j]=n+1
        else:
            c[i][W-1-j]=n+1
        k+=1
        if k==a[n]:
            k=0
            n+=1
for i in range(H):
    st=""
    for j in range(W):
        st+=str(c[i][j])+" "
    print(st)


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

using namespace std;

int main() {
    int N; cin>>N;

    vector<int> an(N);
    for (int i=0;i<N;i++) {
        int a; cin>>an[i];
    }

    vector<int> L(N+2), R(N+2);
    L[0]=R[0]=0;
    L[N+1]=R[N+1]=0;

    for (int i=0;i<N;i++){
        L[i+1]=__gcd(L[i],an[i]);
    }
    for (int i=N;i>=0;i--){
        R[i]=__gcd(R[i+1],an[i-1]);
    }




    int m=0;
    for (int i=1;i<=N;i++) {
        m=max(m, __gcd(L[i-1],R[i+1]));
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 1408
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, k = map(int, readline().split())
if a + b < k:
    print(0, 0)
elif a < k:
    print(0, b - (k - a))
else:
    print(a - k, b)


Measured memory_bytes: 2940