akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
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;}
int main(){
  vvll c(3,vll(3));
  ll cu=0;
  rep(i,3)rep(j,3) cin>>c[i][j];
  vll a(3);
  vll b(3);
  rep(i,101)rep(j,101)rep(u,101){
    ll q=1;
    
    a[0]=i;a[1]=j;a[2]=u;
    b[0]=c[0][0]-i;
    b[1]=c[0][1]-i;
    b[2]=c[0][2]-i;
    
    rep(e,3){
      if(b[e]<0){
        q=0;
        break;
      }
    }
    if(!q) continue;
    for(int h=1;h<3;h++){
      rep(g,3){
        if(a[h]+b[g]!=c[h][g]){
          q=0;
        }
      }
    }
    if(q){
      COUT("Yes");
      return 0;
    }
  }
  COUT("No");
}
           



Measured memory_bytes: 256
a,b,c = map(int, input().split())
 
flag = 0
for i in range(10000):
  if a*(i+1) <= a*b:
    aa = a*(i+1)
    if aa % b == c:
      print("YES")
      flag = 1
      break
if flag == 0:
  print("NO")

Measured memory_bytes: 3060
#include <stdio.h>          // printf(), scanf()

#define N 1000000
#define N2 1000

int
main(int argc, char** argv)
{
	int t[N + 1];
	int n;
	int i, j;

	for (i = 0; i <= N; ++i)
		t[i] = 1;

	t[0] = t[1] = 0;
	int count = 0;
	for (i = 2; i <= N; ++i)
	{
		if (t[i] == 1)
		{
			count++;
			if (i <= N2)
			{
				for(j = i + i; j <= N; j += i)
					t[j] = 0;
			}
		}

		t[i] = count;
	}

	while (scanf("%d", &n) != EOF)
		printf("%d\n", t[n]);

	return 0;
}

Measured memory_bytes: 4500
import itertools


num_vertex, target = map(int, input().split(' '))

target_max = num_vertex - 1

# ensure num_vertex >= 3
if num_vertex == 2:
    if target == 0:
        print("1")
        print("1 2")
    else:
        print("-1")

    exit(0)

edges = [(1, i) for i in range(2, num_vertex+1)]
appendable_edges = list(itertools.combinations(range(2, num_vertex+1), 2))

num_removal = len(appendable_edges) - target

if num_removal < 0:
    print("-1")
    exit(0)

edges.extend(appendable_edges[:num_removal])

print(len(edges))
for edge in edges:
    src, dest = edge
    print(src, dest)

exit(0)


Measured memory_bytes: 4084
n, m = gets.chomp.split.map(&:to_i)
A = Array.new(n).map{Array.new(gets.chomp.split.map(&:to_i))}
B = Array.new()
m.times do
    B << gets.to_i
end

A.each do |a| 
    c = 0
    a.each_with_index do |aa, idx|
        c += aa*B[idx]
    end
    puts c
end


Measured memory_bytes: 7016
#include <iostream>
        using namespace std;
         
        int main()
        {
          int N,X,T,n;
          cin>>N>>X>>T;
          if (N%X==0)
          {
            n=(N/X);
          }
          else
          {
             n = (N/X)+1;
          }
          cout<<n*T;
          
          return 0;
        }

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 998244353;



int main(){
    ll N; cin >> N;
    ll ans = 0;
    for(ll A = 1; A < N; A++){
        for(ll B = 1; A*B < N; B++){
            ans++;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

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

int main()
{
    int N, M, S, T;
    cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i, M){
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].push_back(v);
    }
    cin >> S >> T;
    --S, --T;

    // dist[i][j]: i にホップ、ステップ、ジャンプの各状態が行ける距離
    vector<vector<int>> dist(N, vector<int>(3, -1));

    // 幅優先探索; 最短距離から埋めていきたいので
    queue<pair<int,int>> q;
    q.push({S, 0});
    while(!q.empty()){
        auto tmp = q.front();
        q.pop();
        int pos = tmp.first;
        int d = tmp.second;
        if(dist[pos][d%3] >= 0) continue;
        dist[pos][d%3] = d;
        for(int v: G[pos]) q.push({v, d+1});
    }

    if(dist[T][0]%3 == 0) cout << dist[T][0]/3 << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) {
 if (a < b) { a = b; return true; } return false; 
 }
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll n;
vector<vector<vector<double>>> dp(310,vector<vector<double>>(310,vector<double>(310,-1.0)));
double rec(ll i,ll j,ll k){
  if(dp[i][j][k]>=0) return dp[i][j][k];
  if(i==0&&j==0&&k==0)return 0.0;
  double res=0.0;
  if(i>0) res+=rec(i-1,j,k)*i;
  if(j>0) res+=rec(i+1,j-1,k)*j;
  if(k>0) res+=rec(i,j+1,k-1)*k;
  res+=(double)n;
  res*=1.0/(i+j+k);
  return dp[i][j][k]=res;
}
int main(){
  cout << fixed << setprecision(10);
  cin>>n;
  ll i=0;
  ll j=0;
  ll k=0;
  rep(o,n){
    ll a;
    cin>>a;
    if(a==1) i++;
    else if(a==2) j++;
    else k++;
  }
  COUT(rec(i,j,k));
}


Measured memory_bytes: 237568
#include<bits/stdc++.h>
using namespace std;
int N;
int calc(int from, int to){
	if(from == 0)from = 1;
	if(from > N)return 0;
	if(to > N)to = N;
	if(from > to)return 0;
	return to - from + 1;
}
int main(){
	int K;
	scanf("%d%d",&N,&K);
	long long int res = 0;
	for(int B = K+1; B <= N; B++)
		for(int C = 0; B * C <= N; C++)
			res += calc(B*C+K, B*C+B-1);
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
int n,maxn,minn=1e9+5,k;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&k);
		maxn=max(maxn,k);
		minn=min(minn,k);
	}
	printf("%d",maxn-minn);
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

const int N = 3e5 + 50;

long long n;

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

    cin >> n;
    long long cnt = 1, ans = 0;
    while (n)
    {
        ans += cnt;
        n /= 2;
        cnt *= 2;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >> a >> b;
    
    int seki = a*b;
    if(seki % 2 == 0){
        cout << "Even" <<endl;
    }
    else{
        cout << "Odd" << endl;
    }
    
}

Measured memory_bytes: 3048
x,y = map(int,input().split())
if x == 1 and y == 1:
  print(1000000)
elif x < 4 and y > 3:
  print(100000*(4-x))
elif x > 3 and y < 4:
  print(100000*(4-y))
elif x < 4 and y < 4:
  print(100000*(8-x-y))
else:
  print(0)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int h, w, n, sr, sc;
    string s, t;
    cin >> h >> w >> n >> sr >> sc >> s >> t;
    //縦
    int top = 0, bottom = h + 1;
    for (int i = n - 1; i >= 0; i--) {
        if (t[i] == 'U') {
            bottom = min(bottom + 1, h + 1);
        } else if (t[i] == 'D') {
            top = max(top - 1, 0);
        }
        if (s[i] == 'U') {
            top++;
        } else if (s[i] == 'D') {
            bottom--;
        }
        if (top + 1 == bottom) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (sr <= top || sr >= bottom) {
        cout << "NO" << endl;
        return 0;
    }
    //横
    int left = 0, right = w + 1;
    for (int i = n - 1; i >= 0; i--) {
        if (t[i] == 'L') {
            right = min(right + 1, w + 1);
        } else if (t[i] == 'R') {
            left = max(left - 1, 0);
        }
        if (s[i] == 'L') {
            left++;
        } else if (s[i] == 'R') {
            right--;
        }
        if (left + 1 == right) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (sc <= left || sc >= right) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 776
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

void solve() {
	int N, R; cin >> N >> R;
	if (N < 10) {
		R += 100 * (10 - N);
	}
	print(R);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair<int, string> NODE;
typedef queue<NODE> QUEUE;
typedef set <string> SET;
const int SIZE = 11;

int n;
string A[SIZE];
string B[SIZE];

string ReplaceAll(string str, const string& from, const string& to)
{
    string::size_type pos = 0;
    while(pos = str.find(from, pos), pos != string::npos) {
        str.replace(pos, from.length( ), to);
        pos += to.length();
    }
    return str;
}

int solve( string a, string b ) {
    SET v;
    v.insert( a );
    NODE start( 0, a );
    QUEUE q;
    q.push( start );
    while ( ! q.empty() ) {
        NODE node = q.front();
        q.pop();

        int c = node.first;
        string s = node.second;

        if ( s == b ) {
            return c;
        }
            
        for ( int i = 0; i < n; ++ i ) {
            string ns = ReplaceAll( s, A[i], B[i] );
            int nc = c + 1;
            if ( ns.size() > b.size() ) continue;
            if ( v.count( ns ) ) continue;
            v.insert( ns );
            NODE next( nc, ns );
            q.push( next );
        }
    }
    return -1;
}

int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; ++ i ) {
            cin >> A[i] >> B[i];
        }
        
        string a, b;
        cin >> a >> b;
        cout << solve( a, b ) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
n=int(input())
a,b=map(int,input().split())
l=list(map(int,input().split()))
x=y=z=0
for i in l:
  if i<=a:
    x+=1
  elif a+1<=i and i<=b:
    y+=1
  else:
    z+=1
print(min(x,y,z))


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

int main(){
    int n,num,flg = 0;
    char ch;
    long long check = 0;
    
    cin >> n;
    while(n--){
        cin >> ch >> num;
        if(ch == '(') check += num;
        else check -= num;
        
        if(check < 0){
            flg = 1;
        }
    }
    if(check) flg = 1;
    
    if(flg) cout << "NO" << endl;
    else cout << "YES" << endl;
    
    return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 1e3 + 10, M = 1e2 + 30;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi aaos(-1)
#define mk make_pair

char mp[12][N];
int id[N];

int main()
{
    int n, m, w;
    cin >> n >> m >> w;
    for (int i = 0; i < n; i++)
    {
        scanf("%s", mp[i]);
    }
    int ans = n + m;
    for (int i = 0; i < 1 << n; i++)
    {
        int cnt = 0;
        for (int j = 1; j < n; j++)
        {
            if (i >> j & 1)
            {
                id[cnt++] = j;
            }
        }
        id[cnt++] = n;
        int ct1[12] = {0}, ct2[12] = {0};
        int flag = 1;
        int tot = 0;
        for (int j = 0; j < m; j++)
        {
            int l = 0;
            int num = 0;
            for (int k = 0; k < n; k++)
            {
                if (k < id[l])
                {
                    if (mp[k][j] == '1')
                        num++;
                }
                else
                {
                    if (num > w)
                    {
                        flag = 0;
                        break;
                    }
                    else
                    {
                        ct2[l] = num;
                        num = 0;
                    }
                    if (mp[k][j] == '1')
                        num++;
                    l++;
                }
                if (k == n - 1)
                {
                    if (num > w)
                    {
                        flag = 0;
                        break;
                    }
                    else
                    {
                        ct2[l] = num;
                    }
                }
            }
            if (!flag)
                break;
            int f = 1;
            for (int k = 0; k < cnt; k++)
            {
                if (ct1[k] + ct2[k] <= w)
                    ct1[k] += ct2[k];
                else
                {
                    f = 0;
                    break;
                }
            }
            if (!f)
            {
                tot++;
                for (int k = 0; k < cnt; k++)
                    ct1[k] = ct2[k];
            }
        }
        if (flag)
        {
            ans = min(ans, cnt - 1 + tot);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string S;
  cin>>S;
  string T="";
  int b=0;
  int c=0;
  while(b<S.size()){
      if(S.at(b)=='d'){
          if(b+4<S.size()){
              if(S.at(b)=='d'&&S.at(b+1)=='r'&&S.at(b+2)=='e'&&S.at(b+3)=='a'&&S.at(b+4)=='m'){
                b+=5;
                c=1;
              }
              else{
                  cout<<"NO"<<endl;
                  break;
              }
          }
          else{
            cout<<"NO"<<endl;
            break;
          }
      }
      else if (S.at(b)=='e'){
          if(b+5<S.size()){
              if (S.at(b)=='e'&&S.at(b+1)=='r'&&S.at(b+2)=='a'&&S.at(b+3)=='s'&&S.at(b+4)=='e'&&S.at(b+5)=='r'){
                b+=6;
                c=0;
                if(b==S.size()){
          cout<<"YES"<<endl;
      }
                continue;
              }
          }
          if(b+4<S.size()){
              if (S.at(b)=='e'&&S.at(b+1)=='r'&&S.at(b+2)=='a'&&S.at(b+3)=='s'&&S.at(b+4)=='e'){
                b+=5;
                c=0;
                if(b==S.size()){
          cout<<"YES"<<endl;
      }
                continue;
              }
          }
          if(b+1<S.size()){
              if (S.at(b)=='e'&&S.at(b+1)=='r'&&c==1){
                b+=2;
                c=0;
                if(b==S.size()){
          cout<<"YES"<<endl;
      }
                continue;
              }
          }
          if(true){
              cout<<"NO"<<endl;
              break;
          }
          
      }
      else{
          cout<<"NO"<<endl;
          break;
      }
      if(b==S.size()){
          cout<<"YES"<<endl;
      }
  }
}

Measured memory_bytes: 512
from collections import Counter 
n=int(input())
a=list(map(int,input().split()))
sm=sum(a)
a=Counter(a)
q=int(input())
for _ in range(q):
  b,c=map(int,input().split())
  i=a[b]
  if a[c]:
    a[c]+=i
  else:a[c]=i
  sm+=(c-b)*i
  print(sm)
  a[b]=0

Measured memory_bytes: 88932
S=input().strip()
T=input().strip()
ls = len(S)
lt = len(T)

x = lt
for i in range(0,ls-lt+1):
    m = 0
    for j in range(lt):
        if T[j] != S[i+j]:
            m += 1
    x = min(x,m)

print(x)


Measured memory_bytes: 9056
object Main {
	def main(args: Array[String]): Unit = {
		val sc = new java.util.Scanner(System.in)

    	val n: Int = sc.nextLine.toInt
    	val ax: Array[Int] = sc.nextLine.split(" ").map(_.toInt).sorted

    	var flag = true
    	for (i <- 0 until ax.length) {
    		if (ax(ax.length - (i+1)) != ax.length - (if (i%2 == 1) i else i+1) ) {
    			flag = false
    		}
    	}
    	if (flag) {
    		var c: Long = 1
    		val md: Long = math.pow(10, 9).toLong + 7
    		for (_ <- 0 until ax.length/2) {
    			c *= 2
    			if (c >= md) {
    				c -= md
    			}
    		}

    		println(c)
    	} else {
    		println(0)
    	}
	}
}

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

#define N 100

int a[N];

int main()
{
	int n;
	int alice = 0, bob = 0;
	int ans;

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

	sort( a, a + n, greater<int>() );

	for ( int i = 0; i < n; i += 2 ) {
		alice += a[i];
		if( i + 1 >= n ) {
			break;
		}
		bob += a[i+1];
	}
	ans = alice - bob;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N,M,K=map(int,input().split())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answers=[0]
As=[0]
Bs=[0]
wholeA=0
wholeB=0
bs = [M]
for a in range(N):
    wholeA+=A[a]
    As.append(wholeA)
for b in range(M):
    wholeB+=B[b]
    Bs.append(wholeB)
for a in range(N+1):
    for b in range(bs[-1],-1,-1):
        whole = As[a]
        whole+=Bs[b]
        if whole<=K:
            answers.append(a+b)
            bs.append(b)
            break
print(max(answers))


Measured memory_bytes: 133236
n = 50000
is_prime = [false, false] + [true] * (n-1)

(2..(n**0.5+1)).each do |i|
  next unless is_prime[i]
  (i**2).step(n,i).each do |j|
    is_prime[j] = false
  end
end

until (n=gets.to_i)==0
  m = n/2
  (m-=1) if m.even?

  cnt = 0
  while m >= 3
    if is_prime[m] && is_prime[n-m]
      cnt += 1
    end

    m -= 2
  end

  cnt += 1 if is_prime[n-2]

  puts cnt
end

Measured memory_bytes: 6860
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
	
ll n,k,c;

int main(){
   IOS

   cin>>n>>k>>c;

   string s = string(n+1,' ');
   vi L(n+1), R(n+1);

   for(int i = 1; i <= n ; i++)cin>>s[i];
	
	int r = 1;
   for(int i = 1; i <= n and r <= k; i++){
	   if(s[i] == 'o'){
		   L[r] = i, r++;
			i += c;
			if(i >= n)break;
	   }
   }
	r = k;
   for(int i = n; i >= 1 and r >= 1; --i){
	   if(s[i] == 'o'){
		   R[r] = i, r--;
		   i -= c;
		   if(i <= 1)break;
	   }
   }

   for(int i = 1; i <= k; i++){
	   if(L[i] == R[i]){
		   cout<<L[i]<<"\n";
	   }
   }


}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
	if(b&1)
		res = res * a % mod;
		a = a * a % mod;
	b >>= 1;
	}

	return res;
}



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

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

struct dice
{
    int top;
    int bottom;
    int left;
    int right;
    int front;
    int behind;
};

int main()
{
    int nums[6];

    rep(i, sizeof(nums) / sizeof(int))
    {
        cin >> nums[i];
    }

    dice x;
    x.top = nums[0];
    x.front = nums[1];
    x.right = nums[2];
    x.left = nums[3];
    x.behind = nums[4];
    x.bottom = nums[5];

    string commands;
    cin >> commands;

    for (char command : commands)
    {
        int pre_top = x.top;
        switch (command)
        {
        case 'N':
            x.top = x.front;
            x.front = x.bottom;
            x.bottom = x.behind;
            x.behind = pre_top;
            break;
        case 'E':
            x.top = x.left;
            x.left = x.bottom;
            x.bottom = x.right;
            x.right = pre_top;
            break;
        case 'W':
            x.top = x.right;
            x.right = x.bottom;
            x.bottom = x.left;
            x.left = pre_top;
            break;
        case 'S':
            x.top = x.behind;
            x.behind = x.bottom;
            x.bottom = x.front;
            x.front = pre_top;
        }
    }
    cout << x.top << endl;
}



Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {

	// first digit is 1
	private long getNum(long digit, long num) {
		num += 1;	// count number that is started 0
		long count = 0;
		long freq = 0x1L << digit;
		count += (num / freq) * (freq / 2);
		num = num % freq;
		num -= freq / 2;
		if (num > 0) {
			count += num;
		}
		return count % 2;
	}
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		in.close();
		long max = Math.max(A, B);
		
		long digit = 1;
		long num = 0x1;
		
		String result = "";
		
		while(num <= max) {
			long nowRet = getNum(digit, A-1) + getNum(digit, B);
			nowRet = nowRet % 2;
			result = nowRet + result;
			digit++;
			num = num << 1;
		}
		if (result == "") {
			System.out.println(0);
		} else {
			System.out.println(Long.valueOf(result, 2));
		}
		 
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
const int MM=3013;
double wyn[MM][MM];
int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    double p;
    cin>>n;
    wyn[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        cin>>p;
        wyn[i][0]=wyn[i-1][0]*((double)1-p);
        for(int j=1;j<=i;j++)
        {
            wyn[i][j]=(wyn[i-1][j-1]*p)+(wyn[i-1][j]*((double)1-p));
        }
    }
    double w=0;
    for(int i=n;i>(n>>1);i--)   w+=wyn[n][i];
    cout<<setprecision(10)<<w<<endl;
    return 0;
}


Measured memory_bytes: 69248
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m; cin >> n >> m;
  vector<int> x(m);
  for(int i=0;i<m;i++){
    cin >> x.at(i);
  }
  sort(x.begin(),x.end());
  if(n>=m){
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> d(m-1);
  for(int i=0;i<m-1;i++){
	d.at(i) = x.at(i+1)-x.at(i);
  }
  sort(d.begin(),d.end());
  int move = 0;
  for(int i=0;i<m-n;i++){
	move+=d.at(i);
  } 
  cout<< move << endl;
}

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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  string s;
  cin >> s;

  int ret = 0;
  REP(i, s.size()) FOR(j, i+1, s.size()) FOR(k, j+1, s.size()) {
    auto check = [&](string t) {
      // cout << t << " ";
      bool flag = true;
      if(t.size() == 0) return false;
      if(t.size() >= 2 && t[0]=='0') return false;
      int num = stol(t);
      if(num < 0 || num > 255) flag = false;
      return flag;
    };
    if(check(s.substr(0, i+1)) && check(s.substr(i+1, j-i)) 
      && check(s.substr(j+1, k-j)) && check(s.substr(k+1, s.size()-k-1))) 
    {
        ret++;
    }
    // cout << endl;
  }
  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  string s;
  cin >> s;

  long long ans = 1;
  vector<int> cnt(30);

  for (int i = 0; i < s.size(); ++i) {
    int index = s[i] - 'a';
    cnt[index]++;
  }

  for (int i = 0; i < s.size(); ++i) {
    int index = s[i] - 'a';
    cnt[index]--;

    int sum = accumulate(cnt.begin(), cnt.end(), -cnt[index]);
    ans += sum;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	int n,k,s;
	cin >> n >> k >> s;

	if(s!=(int)1e9)
	rep(i,n)
	{
		if(i<k)
		{
			cout<<s<<endl;
		}
		else
		{
			cout<<(int)1e9<<endl;
		}
		
	}
	else
	rep(i,n)
	{
		if(i<k)
		{
			cout<<s<<endl;
		}
		else
		{
			cout<<1<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
ll INF = 1e9;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)

ll n,ma,mb;

vector<ll> a,b,c;
ll dp[50][410][410];

ll gcd(ll a,ll b) {
  if (b == 0) 
    return a;

  return gcd(b,a % b);
}

int main(){
  cin >> n >> ma >> mb;

  a.resize(n);b.resize(n);c.resize(n);

  rep(i,n)cin >> a[i] >> b[i] >> c[i];

  ll sa = 0,sb = 0;

  rep (i,n) {
    sa += a[i];
    sb += b[i];
  }

  rep (i,sa+1) {
    rep (j,sb+1) {
      dp[n][i][j] = INF;
    }
  }
  dp[n][0][0] = 0;

  rrep(i,n) {
    rep(j,sa+1) {
      rep (k,sb+1) {
        if (j - a[i] >= 0 && k - b[i] >=0)
          dp[i][j][k] = min(dp[i+1][j][k],dp[i+1][j - a[i]][k - b[i]] + c[i]); 
        else 
          dp[i][j][k] = dp[i+1][j][k];
      }
    }
  }

  ll ans = INF;

  for (int i = 1;i <= sa;i++) {
    for (int j = 1;j <= sb;j++) {

      ll d = gcd(i,j);

      ll aa = i / d;
      ll bb = j / d;
     
      if(aa == ma && bb == mb) {
        ans = min(ans,dp[0][i][j]);
      }
    }
  }

  if (ans < INF)
    cout << ans << endl;
  else 
    cout << -1 << endl;
  
}



Measured memory_bytes: 55040
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n=int(input())
l=list(map(int,input().split()))
a=[0]*n

for i in l:
	a[i-1]+=1
	
for j in range(n):
	print(a[j])

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

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

    int a[n];

    int sum = 0;

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

    int select = 0;
    for(int i = 0; i < n; i++)
    {
        if(a[i] >= (double)sum / (4*m))
        {
            select += 1;
        }

        if(select >= m)
        {
            cout << "Yes";
            return 0;
        }
    }
    
    cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#include <map>
#include <string>

using namespace std;

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

    int r, d, x;
    cin >> r >> d >> x;

    for (size_t i = 0; i < 10; i++)
    {
        x = r * x - d;
        cout << x << "\n";
    }

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = pow(10, 9) + 7;
  ll N, K;
  cin >> N >> K;
  vector<vector<ll>> connection(N);
  for (ll i = 0; i < N - 1; ++i) {
    ll a, b;
    cin >> a >> b;
    a -= 1;b -= 1;
    connection.at(a).push_back(b);
    connection.at(b).push_back(a);
  }
  ll ans = K;
  queue<ll> q;
  q.push(0);
  vector<ll> already(N, false);
  already.at(0) = true;
  while (!q.empty()) {
    ll now = q.front();q.pop();
    ll cnt = 2;
    if (now == 0) {
      cnt = 1;
    }
    for (ll i = 0; i < connection.at(now).size(); ++i) {
      ll next = connection.at(now).at(i);
      if (already.at(next)) {
        continue;
      }
      already.at(next) = true;
      ll temp = max(0ll, (K - cnt));
      ans = (ans * (K - cnt)) % mod;
      cnt += 1;
      q.push(next);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 11164
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

const long long MOD = 998244353;

long long bipow(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  if (b%2 == 0) {
    long long t = bipow(a, b/2);
    return (t * t) % MOD;
  } else {
    long long t = bipow(a, b/2);
    return (((t * t) % MOD) * a) % MOD;
  }
}

void solve(long long N, std::vector<long long> D){
  vector<long long> c(N, 0);
  if (D[0] != 0) {
    std::cout << 0 << std::endl;
    return;
  }
  c[0] = 1;
  for (int i = 1; i < N; i++) {
    if (D[i] == 0) {
      std::cout << 0 << std::endl;
      return;
    }
    c[D[i]] += 1;
  }
  long long ans = 1;
  for (int i = 0; i < N-1; i++) {
    ans *= bipow(c[i], c[i+1]);
    ans %= MOD;
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> D(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&D[i]);
  }
  solve(N, std::move(D));
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n;
    bool flag = true;
    rep(i, n){
        int a; cin >> a;
        if (a % 2 != 0 || a % 3 == 0 || a % 5 == 0)continue;
        flag = false;
    }
    cout << (flag ? "APPROVED" : "DENIED") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i +1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;
			int t = values[a];
			values[a] = values[b];
			values[b] = t;
		}
		for (int j=0; j < w; j++) {
			System.out.println(values[j]);
		}
	}
}

Measured memory_bytes: 26224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AISing2020B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] ainput = Console.ReadLine().Split(' ');
            int[] a = new int[N + 1];
            for (int i = 1; i <= N; i++)
            {
                a[i] = int.Parse(ainput[i - 1]);
            }
            int count = 0;
            for (int i = 1; i <= N; i += 2)
            {
                if (a[i] % 2 != 0)
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 27228
#include <iostream>
using namespace std;
int main(){
    int x[4], y[4];
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    x[2] = x[1] + (y[0] - y[1]);
    y[2] = y[1] - (x[0] - x[1]);
    x[3] = x[2] + (x[0] - x[1]);
    y[3] = y[2] + (y[0] - y[1]);
    cout << x[2] << " " << y[2]  << " " << x[3] << " " << y[3] << endl;
    return 0;
}


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

using namespace std;

int r, c, q;

#define MAX_R 50000
#define MAX_C 50000

struct Q {
    int t;
    int index;
    int order;
    Q(int t, int index, int order) : t(t), index(index), order(order) {}
};
int main() {
    while (cin >> r >> c >> q) {
        if (r == 0 && c == 0 && q == 0) break;
        vector<Q> qs;
        for (int i = 0; i < q; i++) {
            int A, B, order;
            cin >> A >> B >> order;
            qs.push_back(Q(A, B, order));
        }

        bool dupR[MAX_R];
        bool dupC[MAX_C];
        memset(dupR, 0, sizeof(dupR));
        memset(dupC, 0, sizeof(dupC));
        int cnt = 0;
        vector<Q>::reverse_iterator ri;
        for (ri = qs.rbegin(); ri != qs.rend(); ri++) {
            if (ri->t == 1) {
                if (dupC[ri->index]) continue;
                if (ri->order == 1) {
                    cnt += r;
                    c--;
                } else {
                    c--;
                }
                dupC[ri->index] = true;
            } else {
                if (dupR[ri->index]) continue;
                if (ri->order == 1) {
                    cnt += c;
                    r--;
                } else {
                    r--;
                }
                dupR[ri->index] = true;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 2476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;  // 1e9+7
const int INF = 100100100;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ans = 0;
  int tmp = 0;
  int N;
  cin >> N;
  vector<int> H(N);
  REP(i, N) cin >> H[i];
  REP(i, N - 1) {
    if (H[i] >= H[i + 1]) {
      tmp++;
    }
    if (H[i] < H[i + 1]) {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);
  cout << ans << '\n';
}

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

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

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

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (a+b > c+d) {
        cout << "Left" << endl;
    }
    else if (a+b == c+d) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
    return 0;
}


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

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

#define INF 1e9

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  int sum = 0;
  REP(i, N){
    sum += A[i];
  }
  set<int> yakusu;
  for(int i = 1; i * i <= sum; i++){
    if(sum % i == 0){
      yakusu.insert(i);
      yakusu.insert(sum / i);
    }
  }
  int ans = 1;
  vector<int> d(N), minus(N+1, 0), plus(N+1, 0);
  for(auto y : yakusu){
    REP(i, N){
      d[i] = A[i] % y;
    }
    sort(d.begin(), d.end());
    REP(i, N){
      minus[i+1] = minus[i]+d[i];
    }
    for(int i = N; i > 0; i--){
      plus[i-1] = plus[i] + (y -d[i-1]);
    }
    FOR(i, 0, N+1){
      if(minus[i] == plus[i] && plus[i] <= K){
        ans = max(ans, y);
      }
    }
  }
  cout << ans <<endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;
const long double pi = acos(-1);

int main()
{
    long double a, b; int h, m;
    cin >> a >> b >> h >> m;
    long double kaku, kaku1;
    kaku = 6 * m;
    kaku1 = 30 * h + 0.5 * m;
    long double add = (kaku1 - kaku) / 180 * pi;
    cout << fixed <<setprecision(15) << sqrt(a * a + b * b - 2 * a * b * cos(add)) << endl; 
}

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

int main() {
  ll n, c = 1;
  cin >> n;
  while (true) {
    if (c * c > n) {
      cout << (c - 1) * (c - 1) << endl;
      return 0;
    }
    c++;
  }
  return 0;
}

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

using lnt = long long;
template <class T> using SET = unordered_set<T>;
template <class T, class S> using MAP = unordered_map<T, S>;

#define LOOP(n) for (lnt _ = 0; _ < (n); _++)
#define REP(i, n) for (lnt i = 0; i < (n); i++)          // 0, 1, ..., n-1
#define IREP(i, n) for (lnt i = (n)-1; i >= 0; i--)      // n-1, n-2, ..., 0
#define FOR(i, a, b) for (lnt i = (a); i < (b); i++)     // a, a+1, ..., b-1
#define IFOR(i, a, b) for (lnt i = (b)-1; i >= (a); i--) // b-1, b-2, ..., a
#define ALL(a) a.begin(), a.end()

#define MAXELM max_element
#define MINELM min_element
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define PB push_back

// 'int'を一切タイプしない
#define MAIN int main

lnt inline POW(const lnt x, const lnt y) {
  lnt init = 1;
  for (lnt i = 0; i < y; i++) {
    init *= x;
  }
  return init;
}

lnt inline BPOW(const lnt i) { return POW(2, i); }

// 非負整数valueのbase進数表示でのposition桁目を表示
lnt inline MASK(const lnt value, const lnt position, const lnt base = 10) {
  if (value >= 0 and base >= 2)
    return (value / POW(base, position)) % base;
  else {
    cout << "WARNING!" << endl;
    return 0;
  }
}

// ビットマスク
lnt inline BMASK(const lnt value, const lnt position) {
  return MASK(value, position, 2);
}

// MASKにおいて，position桁目に数字がない時0ではなくbaseを返す
lnt inline DIGIT(const lnt value, const lnt position, const lnt base = 10) {
  if (value >= 0 and base >= 2) {
    if (value == 0) {
      if (position == 0)
        return 0;
      else
        return base;
    } else {
      if (value < POW(base, position))
        return base;
      else
        return MASK(value, position, base);
    }
  } else {
    cout << "WARNING!" << endl;
    return 0;
  }
}

// base=2のDIGIT
lnt inline BDIGIT(const lnt value, const lnt position) {
  return DIGIT(value, position, 2);
}

const lnt INF = 2 * POW(10, 18); // cf. LLONG_MAX ≒ 9x10^18

template <class T, class S>
lnt inline CNT(const T &iteraterFirst, const T &iteraterLast, const S &value) {
  return (lnt)count(iteraterFirst, iteraterLast, value);
}

template <class T>
lnt inline DIST(const T &iteraterFirst, const T &iteraterLast) {
  return (lnt)distance(iteraterFirst, iteraterLast);
}

template <class T> lnt inline SIZE(const T &sequence) {
  return (lnt)(sequence.size());
}

template <class T> string inline STR(const T &value) {
  return to_string(value);
}

lnt inline ABS(const lnt &value) { return abs(value); }

lnt inline MAX(const lnt &value1, const lnt &value2) {
  return max(value1, value2);
}

lnt inline MIN(const lnt &value1, const lnt &value2) {
  return min(value1, value2);
}

MAIN() {
  lnt n, k;
  cin >> n >> k;
  vector<lnt> h;
  LOOP(n) {
    lnt x;
    cin >> x;
    h.PB(x);
  }
  sort(ALL(h));

  lnt ans = INF;
  REP(iBegin, n - k + 1) {
    ans = MIN(ans, h.at(iBegin + k - 1) - h.at(iBegin));
  }

  cout << ans << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	ll count=0;
	For(i,0,n){
		ll x;cin>>x;x--;
		if(x!=i) count++;
	}
	if(count==2 || count==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}






























	
}

Measured memory_bytes: 256
n = int(input())
xl = list(map(int, input().split()))
ans = 0
for x in xl:
  ans += (x-1)**2

for i in range(2, 101):
  tmp = 0
  for x in xl:
    tmp += (x-i)**2
  if tmp < ans:
    ans = tmp

print(ans)

Measured memory_bytes: 2940
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
H,W = inputlist()
pic = ['8']*H
for i in range(H):
    pic[i] = list(input())
dx = [1,0,-1,0]
dy = [0,1,0,-1]
ans = "Yes"
for x in range(H):
    for y in range(W):
        if pic[x][y] == "#":
            count = 0
            for i in range(4):
                nx = x+dx[i]
                ny = y+dy[i]
                if nx < 0 or ny <0 or nx >=H or ny >= W:
                    continue
                if pic[nx][ny] == "#":
                    count+=1
            if count == 0:
                ans = "No"
                print(ans)
                exit()
print(ans)

Measured memory_bytes: 3828
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int chukan,kimatsu,saishi;
	while(cin>>chukan>>kimatsu>>saishi){
		if(chukan==-1&&kimatsu==-1&&saishi==-1) break;
			if(chukan==-1||kimatsu==-1||chukan+kimatsu<30){
				cout<<"F"<<endl;
			}if(chukan==-1||kimatsu==-1){
				chukan+=1;
			}else if(chukan+kimatsu>=80){
				cout<<"A"<<endl;
			}else if(chukan+kimatsu>=65){
				cout<<"B"<<endl;
			}else if(chukan+kimatsu>=50){
				cout<<"C"<<endl;
			}else if(chukan+kimatsu>=30){
				if(saishi>=50){
					cout<<"C"<<endl;
				}else{
					cout<<"D"<<endl;
				}
			}
	}
	return 0;
}

Measured memory_bytes: 1156
from collections import deque
N = int(input())
A = list(map(int, input().split()))
#A=[1,1,1,1,1,1,1]
#N=7
A.sort(reverse=True)
dis=deque([A[0]])
num=0
for i in range(1,len(A)):
    num+=dis.popleft()
    #L.insert(ind+1,A[i])
    dis.append(A[i])
    dis.append(A[i])
print(num)
#print(L)
#print(dis)

Measured memory_bytes: 32328