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

int main(void)
{
  int n;
  double v,y;
  while(scanf("%lf",&v)!=EOF){
    y=v*v/19.6;
    n=(int)y/5+2;
    printf("%d\n",n);
  }

  return 0;
}

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

int main( )
{
  string s;
  int count = 0;
  cin >> s;
  
  if(s[0]=='1') count++;
  if(s[1]=='1') count++;
  if(s[2]=='1') count++;
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long a[100010],b[100010];
int main()
{
	long long n,i,sum,t,t1,t2,p;
	while(scanf("%lld",&n)!=EOF)
	{
		sum=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
			sum=sum+a[i];
		}
		t1=n*(n+1)/2;
		if(sum%t1!=0)
		{
			printf("NO\n");
			continue;
		}
		t2=sum/t1;
		for(i=1;i<n;i++)
		b[i]=a[i+1]-a[i];
		b[n]=a[1]-a[n];
		p=0;
		for(i=1;i<=n;i++)
		{
			t=t2-b[i];
			if(t<0)
			break;
			if(t%n!=0)
			break;
			p=p+t/n;
		}
		if(i!=n+1||p!=t2)
		printf("NO\n");
		else
		printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 1664
/*Author-Ayush Tiwari
JAI_SHREE_RAM         */

#include <bits/stdc++.h>
#include <cmath>
#include <regex>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ba back
#define ppb pop_back
#define debug(x) cout<<"debug--->>"<<" "<<x<<endl
#define eb emplace_back
#define eps 1e-6
# define M_PI  3.14159265358979323846
#define vll vector<long long int>
#define sz(x) (int((x.size())))
#define all(x) (x).begin(),(x).end()
#define FAST ios_base :: sync_with_stdio (false); cin.tie (NULL)
using namespace std;
typedef long long int ll;

// some fantestic operations
  
 
 //----------------------------------------------------------------------------------------------------------
   ll M=1e9+7;
    ll mod(ll x){
        return ((x%M + M)%M);
    }
    ll add(ll a, ll b){
        return mod(mod(a)+mod(b));
    }
    ll mul(ll a, ll b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }

//---------------------------------------------------------------------------------------------
vll a(100002);
vll dp(100002,-1);
//ll n;

void solve()
{
	ll n;
	cin>>n;
	ll i;
	for(i=0;i<n;i++)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);

	for(i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}

  // solve2(n);
cout<<dp[n-1];


}
int main(){
    FAST;
        #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
ll t;
//cin>>t;
//while(t--){
	
	solve();
//}
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    if(x==w/2&&y==h/2){
        printf("%.9f 1\n",w*h/2);
    }else{
        printf("%.9f 0\n",w*h/2);
    }

}


Measured memory_bytes: 256
import math

S = input()
n = int(S)

def create357(length):
    if length == 1:
        return [["3",2],["5",3],["7",5]]
    else:
        ans = []
        for s in create357(length-1):
            ans.append([s[0]+"3",s[1]*2])
            ans.append([s[0]+"5",s[1]*3])
            ans.append([s[0]+"7",s[1]*5])
        return ans

if n < 1000:
    ans = 0
    for st,i in create357(3):
        if i%30 == 0 and n >= int(st):
            ans += 1
    print(ans)

else:
    ans = 0
    digit = len(S)
    for d in range(2,digit-1):
        length = d+1
        ans += 3**length+3-3*2**length
    for st,i in create357(digit):
        if i%30 == 0 and n >= int(st):
            ans += 1
    print(int(ans))
            

    
        


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

using namespace std;

int main(void)
{
	long long a,b,c; cin>>a>>b>>c;
	if(a % 2 == 0 || b%2 == 0 || c % 2 == 0){
		cout<<0<<endl;
	}
	else{
		if(a >= b && a >= c){
			cout<<b*c<<endl;
		}
		else if(b >= a && b >= c){
			cout<<a*c<<endl;
		}
		else cout<<a*b<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 152944
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;




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

	if (n < k)
	{
		cout << 1 << "\n";
		return 0;
	}
	if (n%k)
	{
		cout << 1 << "\n";
		return 0;
	}
	cout << 0 << "\n";

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int b[27];
	for(int i=0;i<27;i++)
	{
		b[i]=0;
	}
	for(int i=0;i<a.size();i++)
	{
		if(a[i]>=65&&a[i]<=90)
		{
			b[a[i]-65]++;
		}
		if(a[i]>=97&&a[i]<=122)
		{
			b[a[i]-97]++;
		}
	}
	int ans=0;
	for(int i=0;i<27;i++)
	{
		if(b[i]>=2)
		{
			ans++;
		}
	}
	if(ans==2)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define N 5005
int n,m;
LL s1[N],ans,f[N];
int a[N][205],lg[N],mx[205][N][20];
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
inline int Max(int i,int l,int r)
{
	int l1=lg[r-l+1];
	return max(mx[i][l][l1],mx[i][r-(1<<l1)+1][l1]);
}
inline void dfs(int l,int r,int L,int R)
{
	if(l>r)
		return;
	int mid=(l+r)/2,x1;
	for(int i=L;i<=min(mid,R);i++)
	{
		LL ml=s1[i]-s1[mid];
		for(int j=1;j<=m;j++)
			ml+=Max(j,i,mid);
		if(ml>f[mid])
			f[mid]=ml,x1=i;
	}
	dfs(l,mid-1,L,x1);
	dfs(mid+1,r,x1,R);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=2;i<=n;i++)
		scanf("%lld",&s1[i]),s1[i]+=s1[i-1],lg[i]=lg[i>>1]+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			mx[j][i][0]=read();
	for(int i=1;i<=m;i++)
		for(int k=1;k<20;k++)
			for(int j=1;j+(1<<(k-1))<=n;j++)
				mx[i][j][k]=max(mx[i][j][k-1],mx[i][j+(1<<(k-1))][k-1]);
	dfs(1,n,1,n);
	for(int i=1;i<=n;i++)
		ans=max(ans,f[i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 81920
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.11 02:49:45
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;cin >> n;
    vector<int> b(n,0);
    int nax = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        nax = max(nax,a);
        b[a]++;
    }
    if (b[nax] < 2) {
        puts("Impossible");
    }
    else if (nax % 2 == 0) {
        int k = nax / 2;
        if (b[k] != 1) puts("Impossible");
        else {
            for(int i = k + 1; i < nax; i++) {
                if (b[i] < 2) {
                    puts("Impossible");
                    return 0;
                }
            }
            puts("Possible");
        }
    }
    else {
        int k = nax / 2 + 1;
        if (b[k] != 2) puts("Impossible");
        else {
            for(int i = k + 1; i < nax; i++) {
                if (b[i] < 2) {
                    puts("Impossible");
                    return 0;
                }
            }
            puts("Possible");
        }
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int dp[100005], h[100005], n, k;
int solve(int idx) {
	if (idx >= n)
		return 1e9;
	if (idx == n - 1)
		return 0;
	if (dp[idx] != -1)
		return dp[idx];

	dp[idx] = 1e9;
	for (int i = 1; i <= k; i++) {
		//if (idx - i >= 0)
		dp[idx] = min(abs(h[idx] - h[idx + i]) + solve(idx + i), dp[idx]);
	}
	return dp[idx];
}
int main() {
	IO
	cin >> n >> k;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++){
		cin >> h[i];
	}
	cout << solve(0);
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const int MOD = 998244353;

ll pw(ll x, ll e)
{
    if(e == 0)
        return 1;
    if(e == 1)
        return x;

    ll res = pw(x, e / 2);
    res = (res * res) % MOD;
    if(e & 1) res = (res * x) % MOD;

    return res;
}

int n;
int d[N], cnt[N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int max_d = 0;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> d[i];
        max_d = max(max_d, d[i]);
        cnt[d[i]]++;
    }

    if(d[1] != 0 || cnt[0] != 1)
    {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for(int i = 1; i <= max_d; i++)
        ans = (ans * pw(cnt[i - 1], cnt[i])) % MOD;

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long gcd(long long a,long long b)
{
	if(a%b==0)
	return b;
	else	
	return gcd(b,a%b);
}
int main()
{
	scanf("%lld%lld",&n,&x);
	long long k=gcd(n,x);
	printf("%lld",(n-k)*3);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
//#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, int>
#define vi vector <int>
const ll nmax=1e5+2;
const ll mod = 998244353;
int n, m;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    int ctrl=0;
    for(int i=1; i<=n; i++){
        int x;
        cin>>x;
        if(x!=i) ctrl++;
    }
    if(ctrl>2) cout<<"NO";
    else cout<<"YES";
}


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

using namespace std;

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

	vector<string> s;
	s.resize(3);
	
	for(int i = 0; i < 3; ++i) {
		cin >> s[i];
	}

	int n = 0;

	for(int i = 0; i < 3; ++i) {
		n = max(n, (int)s[i].size());
	}

	vector<vector<vector<bool> > > can;
	can.resize(3);
	for(int i = 0; i < 3; ++i) {
		can[i].resize(3);
		for(int j = 0; j < 3; ++j) {
			can[i][j].assign(n + 1, true);
		}
	}

	for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			if(i != j) {
				for(int k = 0; k < s[i].size(); ++k) {
					for(int p = 0; p < s[j].size() && k + p < s[i].size(); ++p) {
						if(s[i][k + p] != '?' && s[j][p] != '?' && s[i][k + p] != s[j][p]) {
							can[i][j][k] = false;
							break;
						}
					}
				}
			}
		}
	}

	int ans = s[0].size() + s[1].size() + s[2].size();

	function<void(int, int, int)> solve = [&] (int x, int y, int z) {
		for(int i = 0; i <= s[x].size(); ++i) {
			if(can[x][y][i]) {
				for(int j = i; j <= max(i + s[y].size(), s[x].size()); ++j) {
					if(j < s[x].size()) {
						if(can[x][z][j] && (j >= i + s[y].size() || can[y][z][j - i])) {
							ans = min(ans, max((int)s[x].size(), max(i + (int)s[y].size(), j + (int)s[z].size())));
						}
					} else if(can[y][z][j - i]) {
						ans = min(ans, max(i + (int)s[y].size(), j + (int)s[z].size()));
					}
				}			
			}
		}
	};

	solve(0, 1, 2);
	solve(0, 2, 1);
	solve(1, 0, 2);
	solve(1, 2, 0);
	solve(2, 0, 1);
	solve(2, 1, 0);

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

Measured memory_bytes: 256
// not finished triangles triangles triangles triangles triangles triangles 

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

int n, m, a, b;

int main(){

    cin >> n >> m;

    vector< vector<int> > v(n+1); 

    for(int i = 0; i < m; i++){
        cin >> a >> b;
        v[a-1].push_back(b);
        v[b-1].push_back(a);
    }

    for(int i = 0; i < v.size()-1; i++){
        cout << v[i].size() << nl;
    }


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 384
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
#include <set>
//#include <string.h>
using namespace std;
using Graph = vector<vector<int>>;
queue<long>que;

int main(){
    int n,k,c;
    string s;
    cin>>n>>k>>c;
    cin>>s;
    vector<int>day1(n,0);
    vector<int>day2(n,0);
    rep(i,n){
        if(s.at(i)=='x'){
            day1[i]=-1;
            day2[i]=-1;}
    }
    int cnt = 1;
    rep(i,n){
        if(day1[i]==-1)continue;
        day1[i] = cnt;
        cnt++;
        i+=c;
        if(cnt == k+1)
            break;
    }
    cnt = k;
    for(int i = n-1;i>=0;i--){
        if(day2[i]==-1)continue;
        day2[i] = cnt;
        cnt--;
        i-=c;
    }
    rep(i, n){
        if(day1[i]>0 && day1[i]==day2[i])
            cout<<i+1<<endl;
    }
    
    

}


Measured memory_bytes: 3332
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;

int N, M;
int target[110];
int choice[110];
int score[110];

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

    fill(score, score+N, 0);

    for (int j = 0; j < M; ++j) {
        int miss = 0;
        for (int k = 0; k < N; ++k) {
            cin >> choice[k];
            --choice[k];
            if (choice[k] == target[j]) {
                ++score[k];
            } else {
                ++miss;
            }
        }
        score[target[j]] += miss;
    }

    for (int j = 0; j < N; ++j) {
        cout << score[j] << endl;
    }

    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(void) {
	int sharp = 0;
	int obtuse = 0;
	int right = 0;
	int i;
	vector<int> a(3);

	while (1) {
		for (i = 0; i < 3; i++) {
			cin >> a[i];
		}

		sort(a.begin(), a.end());

		if (a[0] + a[1] <= a[2] || a[1] + a[2] <= a[0] || a[2] + a[0] <= a[1]) {
			break;
		}

		if (pow(a[0], 2) + pow(a[1], 2) < pow(a[2], 2)) {
			obtuse++;
		}
		else if (pow(a[0], 2) + pow(a[1], 2) == pow(a[2], 2)) {
			right++;
		}
		else {
			sharp++;
		}
	}

	printf("%d %d %d %d\n", right+sharp+obtuse, right, sharp, obtuse);
	return 0;

}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int n,res=0; cin>>n;
 FOR(i,1,n+1){
    int k=i,c=1;
    while(k>=10){
        k/=10;
        c++;
    }
    if(c%2==1)res++;
}

 cout<<res<<endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    REP(i, m) cin >> b[i];
    
    int ans = 0;
    REP(i, n){
        vector<int> a(m);
        REP(i, m) cin >> a[i];
        int sum = c;
        REP(i, m) sum += a[i] * b[i];
        if(sum > 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
ll pow3(ll x){
	return x * x * x;
}

int main(){
	ll N,K,ans;
	cin >> N >> K;
	if (K % 2 == 1){
		ans = pow3(N / K);
	}
	else{
		ans = pow3(N / K) + pow3((N + (K/2))  / K );
	}
	cout << ans <<endl;
	return 0;
}


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

using namespace std;
const int inf = 1e9;

vector<vector<int>> T(2, vector<int> (2 * 1000 * 1000, inf));

vector<pair<int, int>> v;
vector<int> p, poz;
int n;

void update(vector<int> &T, int node, int lf, int rt, int poz, int val) {
    if(lf == rt) {
        T[node] = min(T[node], val);
        return;
    }

    int mid = (lf + rt) / 2;

    if(poz <= mid)
        update(T, 2 * node, lf, mid, poz, val);
    else
        update(T, 2 * node + 1, mid + 1, rt, poz, val);

    T[node] = min(T[2 * node], T[2 * node + 1]);
}

int query(vector<int> &T, int node, int lf, int rt, int st, int dr) {
    if(lf >= st and rt <= dr) {
        return T[node];
    }

    int mid = (lf + rt) / 2;
    int ans = 1e8;

    if(st <= mid)
        ans = min(ans, query(T, 2 * node, lf, mid, st, dr));
    if(dr > mid)
        ans = min(ans, query(T, 2 * node + 1, mid + 1, rt, st, dr));

    return ans;
}

int label;
vector<int> f;

void solve(int lf, int rt, int parity, int dad) {
    //cerr << lf << " " << rt << " " << parity << " " << depth << "\n";
    int first = poz[query(T[parity], 1, 0, n - 1, lf, rt)];
    //cerr << first << "\n";
    int second = poz[query(T[1 - parity], 1, 0, n - 1, first + 1, rt)];
    //cerr << second << "\n";
    
    int now = label++;
    f[now] = dad;
    v[now] = (make_pair(p[first], p[second]));
    
    if(first > lf) {
        solve(lf, first - 1, parity, now);
    }

    if(second < rt) {
        solve(second + 1, rt, parity, now);
    }

    if(second > first + 1) {
        solve(first + 1, second - 1, 1 - parity, now);
    }
}

int main() {
    //ifstream cin("c.in");
    ios_base :: sync_with_stdio(false);

    cin >> n;
    p = vector<int> (n, 0);
    poz = vector<int> (n + 1, 0);
    f = vector<int> (n, -1);
    v = vector<pair<int, int>> (n);

    for(int i = 0; i < n; ++i) {
        cin >> p[i];
        poz[p[i]] = i;
        update(T[i % 2], 1, 0, n - 1, i, p[i]);
    }

    solve(0, n - 1, 0, -1);
        
    vector<int> ans;
    set<pair<pair<int, int>, int>> s;
        
    vector<vector<int>> g(n);

    for(int i = 0; i < n / 2; ++i)
        if(f[i] >= 0) {
            g[f[i]].push_back(i);
        }
    
    s.insert(make_pair(v[0], 0));

    while(int(ans.size()) < n) {
        auto node = *(s.begin());
        auto elem = node.first;
        ans.push_back(elem.first);
        ans.push_back(elem.second);
        s.erase(s.begin());

        for(auto e : g[node.second]) {
            s.insert(make_pair(v[e], e));
        }
    }

    for(auto val : ans)
        cout << val << " ";
    cout << "\n";
}

Measured memory_bytes: 38520
#include <bits/stdc++.h>
using namespace std;
int n,bisa;
int main () {
cin >> n;
for (int i=1;i<=9;i++) {
	for (int j=1;j<=9;j++) {
		if (i*j==n) {
			bisa=1;
		}
	}
}
if (bisa==1) {
	cout <<"Yes"<<endl;
} else {
	cout << "No" << endl;
}
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005], b[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (i = 0; i < n; i++)
		scanf("%d", &b[i]);
	for (i = 0; i < n / 2; i++)
	{
		b[i] ^= b[n - i - 1];
		b[n - i - 1] ^= b[i];
		b[i] ^= b[n - i - 1];
	}
	int left = n;
	for (i = 0; i < n; i++)
	{
		if (a[i] == b[i])
		{
			left = i;
			break;
		}
	}
	a[n] = -1;
	i = 0;
	while (left < n)
	{
		if (a[left] != b[left])
			break;
		while ((a[i] == b[left] || b[i] == a[left]) && i < n)
			i++;
		if (i < n)
		{
			b[i] ^= b[left];
			b[left] ^= b[i];
			b[i] ^= b[left];
			left++;
		}
		else
			break;
	}
	left = 0;
	for (i = 0; i < n; i++)
		if (a[i] == b[i])
			left++;
	if (left > 0)
		printf("No\n");
	else
	{
		printf("Yes\n");
		for (i = 0; i < n - 1; i++)
			printf("%d ", b[i]);
		printf("%d\n", b[n - 1]);
	}
	return 0;
}

Measured memory_bytes: 3292
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);

	const int num = s[0];

	AtCoder::Ans* ans = new AtCoder::Ans();

	ans->increment(num * num);

	ans->showResult();

	delete(ans);

	return 0;
}


Measured memory_bytes: 256
const main = (val) => {
  const aray = val.split(" ");
  console.log(calc(parseInt(aray[0]), parseInt(aray[1])));
}
const calc = (a, b) => {
  if ((a % 2) === 0 || (b % 2) === 0) {
    return "Even";
  } else {
    return "Odd";
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()
print(min(N * A, B))


Measured memory_bytes: 26876
#include <iostream>

int main() {
  int a, b;

  std::cin >> a >> b;

  int ans;

  if (a == b) {
    ans = a + b;
  } else {
    ans = std::max(a, b);
    ans += ans - 1;
  }

  std::cout << ans << std::endl;

  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printVerdict(verdict) cout << (verdict ? "YES": "NO") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const ll inf = 0x3f3f3f3f;

template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) { cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n'; }
template <class T1, class T2>
void printPair(pair<T1, T2> p) { cout << p.first << " " << p.second << '\n'; }
template <class T>
void printArray(vector<T> arr) { for (int i = 0; i<size(arr); i++) {cout << arr[i] << " ";} cout << '\n'; } 

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	int ret = 0;
	for (int c = 1; c < n; c++) {
		int curr = n-c;
		for (int i = 1; i * i <= curr; i++) {
			if (curr%i == 0) ret += 1 + (curr/i != i);
		}
	}
	cout << ret << '\n';
	
}



Measured memory_bytes: 3648
#include<iostream>
#include<vector>
using namespace std;
int main() {
	double n, t, a;
	cin >> n >> t >> a;
	vector<double> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}
	double ht = 1000, lt = -1000;
	int hn = 0, ln = 0;
	for (int i = 0; i < n; i++) {
		if (a < t - h.at(i) * 0.006) {
			if (ht > t - h.at(i) * 0.006) {
				ht = t - h.at(i) * 0.006;
				hn = i + 1;
			}
		}
		else if (a > t - h.at(i) * 0.006) {
			if (lt < t - h.at(i) * 0.006) {
				lt = t - h.at(i) * 0.006;
				ln = i + 1;
			}
		}
		else {
			ht = a;
			hn = i + 1;
			break;
		}
	}
	if (ht - a <= a - lt && hn != 0) {
		cout << hn << endl;
	}
	else if (ht - a >= a - lt && ln != 0) {
		cout << ln << 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 L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();

        int result = 0;
        for (int i = L; i <= R; i++) {
            if (i%d == 0) result++;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 27052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> vi(N);
  for(int i=0;i<N;i++){
    cin>>vi.at(i);
  }
  int ave=0;
  for(int i=0;i<N;i++){
    ave+=vi.at(i);
  }
  vector<int> va(N);
  for(int i=0;i<N;i++){
    va.at(i)=N*vi.at(i)-ave;
    if(va.at(i)<0) va.at(i)=(-1)*va.at(i);
  }
  int n=0; int min=va.at(0);
  for(int i=0;i<N;i++){
    if(min>va.at(i)){
      min = va.at(i);
      n=i;
    }
  }
  cout<<n<<endl;
}

Measured memory_bytes: 256
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (float)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
list($N) = sscanf(trim(fgets(STDIN)), "%d");

$sc = new Scanner();
$cnt = 0;
for ($i = 1; $i <= $N; $i++) {
    $n = $sc->nextInt();
    if(($i % 2 == 1) && ($n % 2 == 1)){
        $cnt++;
    }
}
print($cnt);


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

const long long INF = 1LL << 60;

int main() {
  int n,cnt=1;
  long long a,b;
  bool u=false, d=false;
  
  cin >> n;
  
  cin >> a;
  
  rep(i,n-1){
    cin >> b;
    if(a<b)
      u=true;
    if(a>b)
    d=true;
    if(u==true && d==true){
      u=false;
      d=false;
      cnt++;
    }
    a=b;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(10);
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll x=min(a,k);
	k=k-a;
	if(k<0)
	k=0;
	ll y=min(b,k);
	k-=b;
	if(k<0)
	k=0;
	ll z=min(c,k);
	cout<<x-z;
	return 0;
}

Measured memory_bytes: 3640
N, M, K = map(int, input().split())
MOD = 998244353
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)

comb = [M] * (K + 1)
for i in range(1, K + 1):
    comb[i] = comb[i - 1] * (N - i) % MOD
    comb[i] = comb[i] * modinv(i) % MOD

ans = 0
for i in range(K + 1):
    ans = (ans + comb[i] * pow(M - 1, N - i - 1, MOD)) % MOD
print(ans)


Measured memory_bytes: 16792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,cnt=0;
  cin >> n >> m;
  if(n>=m) cout << 0 << endl;
  else{
  int x[m];
  for(int i=0;i<m;i++) cin >> x[i];
  sort(x,x+m);
  int b[m-1];
  for(int i=0;i<m-1;i++) b[i]=x[i+1]-x[i];
  sort(b,b+m-1);
  for(int i=0;i<m-n;i++) cnt += b[i];
  cout << cnt << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

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;
    }
};

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

  ll A[N];
  ll B[N];
  pair<ll ,ll> p;
  vector<pair<ll ,ll>> vec;

  FOR(i,0,N-1){
  cin>>A[i]>>B[i];

  p.first=A[i];
  p.second=B[i];

vec.push_back(p);

  }
  sort(vec.begin(),vec.end());

  ll tmp=0;
  ll ans=0;
  FOR(i,0,N-1){
    if(tmp+vec[i].second<=M){
      ans= ans+vec[i].first*vec[i].second;
      tmp=tmp+vec[i].second;
    }else if(tmp<M){
      ans=ans+vec[i].first*(M-tmp);
      tmp=M;
    }

  }


  cout<<ans<<endl;



  return 0;
}
 


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,K,h[100000];
  cin>>N>>K;
  for (int i(0);i<N;i++) cin>>h[i];
  int cnt(0);
  for (int i(0);i<N;i++){
    if (h[i]>=K) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//typedef long long ll;
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define debug() cout << "Hi" << endl	// write debug(); in main()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;
	else if(p1.ff == p2.ff){
		if(p1.ss < p2.ss)return true;		// You should not be writing p1.ss <= p2.ss !!!
		return false;
	}
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	//debug();
	// int main  or  int32_t main ...
	int n,k;
	cin >> n >> k;
	int p = n%k;
	int ans = min(p,k-p);
	cout << ans << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(12); std::cout << std::fixed;
	int t;
	// cin >> t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x[100010],y[100010],z[100010];
int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  long long a,b,cnt=0,ans=0,c;
  string s,v;

  cin>>a>>b>>c;
  int n;
  n=a;
  a=a+b;
  b=n+c;
  if(n>c){
    cout<<"NO"<<'\n';
  }else if(a-c>=0){
    cout<<"YES"<<'\n';
  }else{
    cout<<"NO"<<'\n';
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

	public static void main(String args[])
	{

		int[] x = new int[5];

		Scanner sc = new Scanner(System.in);

		x[0] = sc.nextInt();
		x[1] = sc.nextInt();
		x[2] = sc.nextInt();
		x[3] = sc.nextInt();
		x[4] = sc.nextInt();

		sc.close();

		for(int i = 0; i < 5; i++)
		{
			if(x[i] != (i + 1))
			{
				System.out.println(i + 1);
			}
		}
	}

}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli k;
	cin>>k;
	vector<lli> a(k);
	REP(i,0,k)cin>>a[i];

	lli minA=2,maxA=2;
	if(a[k-1]!=2){
		cout<<-1<<endl;
		return 0;
	}

	for(lli i=k-1;i>=0;i--){
		if(DEBUG)cout<<minA<<" "<<maxA<<endl;
		if(minA>maxA){
			cout<<-1<<endl;
			return 0;
		}
		minA = ((minA-1)/a[i]+1)*a[i];
		maxA = ((maxA)/a[i]+1)*a[i]-1;
	}
	if(minA>maxA){
		cout<<-1<<endl;
		return 0;
	}
	cout<<minA<<" "<<maxA<<endl;

	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int b[] = new int[n - 1];

		String[] tmpArray = br.readLine().split(" ");
		for(int i = 0; i < n - 1; i++){
			b[i] = Integer.parseInt(tmpArray[i]);
		}

		int result = b[n - 2] + b[0];

		for(int i = 0; i < n - 2; i++){
			result += Math.min(b[i], b[i + 1]);
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 22612
#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

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

int n;
double r[500];
double dp[500];

double dis(double r1, double r2){
    return sqrt(pow(r1+r2, 2)-pow(r1-r2, 2));
}

int main(){
    cin >> n;

    REP(i, n){
        cin >> r[i];
    }

    int s = 0;
    double sd = 0;
    double tsd = 0;
    REP(i, n){
        if(i==0){
            sd = r[0];
            tsd = r[0];
        } else {
            if(dis(r[i-1], r[i])+tsd < r[i]){
                s = i;
                tsd = r[i];
                sd = r[i];
            } else {
                tsd = dis(r[i-1], r[i]) + tsd;
            }
        }
    }

    int g = n-1;
    double gd = 0;
    double tgd = 0;
    for(int i=n-1; i>=0; i--){
        if(i == n-1){
            gd = r[n-1];
            tgd = r[n-1];
        } else {
            if(dis(r[i+1], r[i])+tgd < r[i]){
                g = i;
                tgd = r[i];
                gd = r[i];
            } else {
                tgd = dis(r[i+1], r[i]) + tgd;
            }
        }
    }

    REP(i, g+1) dp[i] = 0;
    for(int i = s; i < g; i++){
        for(int j = s; j<=i; j++){
            if(dp[i+1] < dp[j] + dis(r[j], r[i+1])){
                dp[i+1] = dp[j] + dis(r[j], r[i+1]);
            }
        }
    }
    
    double output = sd + gd + dp[g];
    cout << fixed << setprecision(5) << output << endl;
}

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

int main(){
  int n; cin >> n;
  vector<int> res(n+1), a(n);
  int cnt = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    if(i >= n/2){
      res.at(i+1) = a.at(i);
      if(res.at(i+1) == 1) cnt++;
    }
  }
  for(int i = n/2; i > 0; i--){
    int cnt1 = 2;
    while(cnt1 * i <= n){
      res.at(i) += res.at(i*cnt1);
      cnt1++;
      res.at(i) %= 2;
    }
    if((a.at(i-1) + res.at(i))%2 == 0) res.at(i) = 0;
    else{
      res.at(i) = 1;
      cnt++;
    }
  }
  cout << cnt << endl;
  for(int i = 1; i <= n; i++){
    if(res.at(i)) cout << i << " ";
  }
}

Measured memory_bytes: 2432
from scipy.misc import comb
import collections
n = int(input())
c = list(map(int, input().split()))
collections.Counter(c)
cou = collections.Counter(c)
d = dict()
d2 = dict()
for i in cou:
    d[i] = comb(cou[i], 2, exact=True)
    d2[i] = comb(cou[i] - 1, 2, exact=True)

s = sum(d.values())
ans = [s - d[k] + d2[k] for k in c]
print(*ans, sep='\n')

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

int main() {
  int N;
  cin >> N;
  
  for(int i = 0; i < N; i++) {
    string C;
    cin >> C;
    if (C != "Y") {
      if (i == N - 1) {
        cout << "Three" << endl;
      }
      continue;
    }
    else {
      cout << "Four" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();  
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        char[] S = r.s().toCharArray();          
        int[] data = new int[N+2];
        int j = 0;
        int value = S[0]-'0';
        if(value == 0){
            data[j++] = 0;
        }
        for(int i = 0; i < N; value = 1-value){
            int count = 0;
            while(i < N && S[i]-'0' == value){
                count++;
                i++;
            }            
            data[j++] = count;
        }
        if(value == 1)
            data[j++] = 0;
            
        int size = j,
            sum = 0;
        for(int i = 0; i < Math.min(2*K+1, size); i++)
            sum += data[i];
        
        int max = sum;
        for(int i = 3; i+2*K-1 < size; i += 2){
            sum += -data[i-3] - data[i-2] + data[i+2*(K-1)]+data[i+2*K-1];
            if(max < sum)
                max = sum;    
        }
        System.out.println(max);    
    }

    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

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

  if (n % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  int m = n / 2;
  if (s.substr(0, m) == s.substr(m, m)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;

vector<pair<char, int> > data;
string in;

main(){
  int cnt = 1;
  cin >> in;
  char pre = in[0];
  for(int i=1;i<in.size();i++){
    if(in[i] != pre){
      data.push_back(pair<char, int>(pre, cnt));
      cnt = 0;
    }
    pre = in[i];
    cnt++;
  }
  data.push_back(pair<char, int>(pre, cnt));
  int ans = 0;
  for(int i=2;i<data.size();i++){
    if(data[i-2].first == 'J' && data[i-1].first == 'O' && data[i].first == 'I'){
      if(data[i-2].second >= data[i-1].second && data[i-1].second <= data[i].second){
        ans = max(ans, data[i-1].second);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, t: "List[int]", x: "List[int]", y: "List[int]"):
    ret = YES
    t = [0] + t
    x = [0] + x
    y = [0] + y
    for i in range(1, N + 1):
        #print(x[i], y[i], t[i])
        dis = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])
        time = t[i] - t[i - 1]
        if dis > time or dis % 2 != time % 2:
            #print(x[i], y[i], t[i])
            ret = NO
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, t, x, y)

if __name__ == '__main__':
    main()


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

int f(int n){
  int sum = 0;
  while(n>0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}
  

int main() {
  int n;
  cin >> n;
  int b, sum = 0;
  int ans = 1e6;
  for (int a = 1; a <= n-1; ++a){
    b = n-a;
    sum = f(a) + f(b);
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second
int main()
{
    ll n,m,k;cin >> n >> m >> k;
    ll ans = LLONG_MAX;
    ll cost[n];
    ll arr[n][m];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            if(j==0) cin >> cost[i];
            cin >> arr[i][j];
        }
    }
    for(ll i=0;i<pow(2,n);i++)
    {
        ll sum[m]={0};
        ll cos = 0;
        for(ll j=0;j<n;j++)
        {
            if( ((i)&((ll)pow(2,j)))   !=  0)
            {
                cos = cos + cost[j];
                for(ll kk=0;kk<m;kk++) sum[kk]+=arr[j][kk];
            }
        }
        ll fl = 0;
        for(ll j=0;j<m;j++)
        {
            if(sum[j]<k) fl = 1; 
        }
        if(fl==0) ans=min(ans,cos);
    }
    if(ans!=LLONG_MAX) cout << ans << endl;
    else cout << -1 << endl;
}
    

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

int main() {
  int A,B;
  cin >>A>>B;
  int socket=1;
  int tap=0;
  for(int i=0;socket<B;i++){
   socket--;
   socket+=A;
   tap++;
  }
  cout<<tap<<endl;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, X;
    cin >> N >> X;
    ll min = INF;
    REP(i, N)
    {
        ll m;
        cin >> m;
        X -= m;
        min = std::min(m, min);
    }
    cout << N + X / min << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
A = list(map(int, input().split()))

A.sort()
num = 1
B = list(itertools.accumulate(A))
for i, a in enumerate(A[1:]):
    if B[i]*2 < a:
        num = 1
    else:
        num += 1
print(num)


Measured memory_bytes: 14428