akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;


int main()
{
	string s;
	cin >> s;
	map <char,int> count;
	int count2=0;
	for(char x : s){
		count[x]++;
	}
	for (auto it=count.begin(); it != count.end();it++){
		if(it->second==2){
			count2++;
		}
	}
	if(count2 == 2){
		cout << "Yes";
	}
	else
		cout << "No";

	
}	


Measured memory_bytes: 3596
#include<stdio.h>
int main(){

    int N=0;
    int d[51]={};
    int sum=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&d[i]);
    }

    for (int i=0;i<N;i++) {
        for (int j=i+1;j<N;j++) {
            sum+=d[i]*d[j];
      }
    }

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

    return 0;
}

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


int main(void){
    // Your code here!
    int N,M,ans;
    ans=0;
    cin>>N>>M;
    int H[N],C[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
        C[i]=i;
    }
    int A[M],B[M];
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        if(H[A[i]-1]==H[B[i]-1]){
            C[A[i]-1]=C[B[i]-1]=-1;
        }
        if(H[A[i]-1]>H[B[i]-1]){
            C[B[i]-1]=-1;
        }
        else{
            C[A[i]-1]=-1;
        }
    }
    for(int i=0;i<N;i++){
        if(C[i]>-1){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t; cin>>s>>t;
    int ans=0;
    REP(i,3)
    {
        if(s[i]==t[i]) ++ans;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct dice {
	int num[6];
}dice;

//dice???1?????¢?????????.
void mov(dice *d, char c);

//dice??????????¨??????????1?????¢?????????.
void spin(dice *d);

//dice??????????????????????????§??????.
int check(dice d1, dice d2);

int main(void) {

	//dice?????£?¨???¨???????????????.
	dice dice1;
	dice dice2;
	int i = 0;
	int j = 0;
	int k = 0;
	for (i = 0; i < 6; i++) {
		dice1.num[i] = 0;
		dice2.num[i] = 0;
	}

	int judge = 1;

	//??¢???????????????.
	for(i = 0; i < 6; i++)
		scanf("%d", &dice1.num[i]);
	for (i = 0; i < 6; i++)
		scanf("%d", &dice2.num[i]);

	//dice2????????¢?????????dice1??¨??§?????????.
	for (i = 0; i < 4; i++) {
		mov(&dice2, 'E');

		for (j = 0; j < 4; j++) {
			spin(&dice2);
			judge = check(dice1, dice2);

			if (judge)
				break;
		}
		if (judge)
			break;
	}

	if (!judge) {
		for (i = 0; i < 4; i++) {
			mov(&dice2, 'N');

			for (j = 0; j < 4; j++) {
				spin(&dice2);
				judge = check(dice1, dice2);

				if (judge)
					break;
			}
			if (judge)
				break;
		}
	}

	//??????.
	if (judge)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

void mov(dice *d, char c) {
	int tmp = 0;

	if ('E' == c) {
		tmp = (*d).num[0];
		(*d).num[0] = (*d).num[3];
		(*d).num[3] = (*d).num[5];
		(*d).num[5] = (*d).num[2];
		(*d).num[2] = tmp;
	}
	else if ('N' == c) {
		tmp = (*d).num[0];
		(*d).num[0] = (*d).num[1];
		(*d).num[1] = (*d).num[5];
		(*d).num[5] = (*d).num[4];
		(*d).num[4] = tmp;
	}
	else if ('S' == c) {
		tmp = (*d).num[0];
		(*d).num[0] = (*d).num[4];
		(*d).num[4] = (*d).num[5];
		(*d).num[5] = (*d).num[1];
		(*d).num[1] = tmp;
	}
	else if ('W' == c) {
		tmp = (*d).num[0];
		(*d).num[0] = (*d).num[2];
		(*d).num[2] = (*d).num[5];
		(*d).num[5] = (*d).num[3];
		(*d).num[3] = tmp;
	}
}

void spin(dice *d) {
	int tmp = 0;

	tmp = (*d).num[1];
	(*d).num[1] = (*d).num[3];
	(*d).num[3] = (*d).num[4];
	(*d).num[4] = (*d).num[2];
	(*d).num[2] = tmp;
}

int check(dice d1, dice d2) {
	int i = 0;
	int judge = 1;

	for (i = 0; i < 6; i++) {
		if (d1.num[i] != d2.num[i])
			judge = 0;
	}

	return judge;
}

Measured memory_bytes: 580
from collections import deque

n = int(input())                #エッジの個数
edge = [[] for _ in range(n)]   #エッジの隣接リスト（お隣さんを格納する）

for _ in range(n):
  u, _, *v = map(lambda x: int(x)-1, input().split())
  edge[u] = sorted(v)           #入力された隣接頂点をお隣さんリストに格納

dist = [-1] * n                #始点から各頂点iまでの距離を測るリスト
dist[0] = 0                    #0番目のエッジの距離
Q = deque([0])                 #次に訪問すべきエッジを記録するキュー

while len(Q):
  v = Q.popleft()             #vに次に訪問するエッジを代入（v=自分）
  for c in edge[v]:           #v(自分)のお隣さんの数分だけイテレーション
    if dist[c] == -1:         #もしお隣さんお距離が-1になっていたら
      dist[c] = dist[v] + 1   #お隣さんの距離=自分の距離+1にする
      Q.append(c)             #次に訪問すべきキューにお隣さんを代入

for i, d in enumerate(dist):
  print(i+1, d)



Measured memory_bytes: 6028
#include <iostream>
#include <vector>
#include <algorithm>
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)

const int MOD = 1e+9 + 7;

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

    vector<long long> factorial(100001, 1);
    FOR(i, 1, 100001){
        factorial[i] *= i*factorial[i-1];
        factorial[i] %= MOD;
    }

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

    long long ans = 1;
    REP(i, N){
        int pos = lower_bound(a.begin(), a.end(), b[i]) - a.begin(), n;
        if(a[i] < b[i]) n = pos-i;
        else n = i-pos+1;
        ans *= n;
        ans %= MOD;
        // i += n-1;
        // cout << i << " " << ans << endl;
    } 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
if N == 0:
  print(0); exit()
ans = []
while N !=0:
  #print(ans,N)
  if N%2 == 0:
    ans.append(0)
  else:
    N -= 1
    ans.append(1)
  N//=-2
#print(ans)
ans = reversed(ans)
print(''.join([str(n) for n in ans]))

Measured memory_bytes: 61716
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

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

vector<ll> memo(n_max);
bitset<n_max> flag(0);
ll dfs(vvl &graph, ll pos){
    if(flag[pos]) return memo[pos];
    flag[pos] = 1;
    ll ans = 0;
    for(auto &to : graph[pos]){
        chmax(ans, dfs(graph, to) + 1);
    }

    return memo[pos] = ans;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    vector<vector<ll>> graph(n);
    rep(i,m) {
        ll a,b;cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        // graph[b].emplace_back(a);
    }
    ll ans = 0;
    rep(i,n){
        chmax(ans, dfs(graph, i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 41856
N, C, K = map(int, input().split(" "))
T = [int(input()) for _ in range(N)]

T.sort(reverse=True)

count = 0
while T:
    limit = T[-1]+K
    count += 1
    for i in range(C):
        if T and T[-1] <= limit:
            T.pop()
        else:
            break

print(count)

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

using namespace std;

int main(void){
    unsigned long long N, M;
    cin >> N >> M;
    unsigned long long n = min(N, M);
    unsigned long long m = max(N, M);
    unsigned long long ans = 0;
    if(n == 1 && m == 1) {
        ans = 1;
    } else if(n == 1){
        ans = m-2;
    } else if(n >= 2){
        ans = (n-2) * (m-2);
    }
    cout << ans << endl;
    return 0;
}

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


int main() {

	int n;
	cin >> n;

	vector<int> num(4);
	for(int i=0; i<4; i++){
		num.at(3-i) = n%10;
		n /= 10;
	}

	bitset<3> ans;

	for(int tmp=0; tmp < (1 << 3); tmp++){
		bitset<3> s(tmp);

		int sum = num.at(0);
		for(int i=0; i<3; i++){
			if(s.test(i)){
				sum += num.at(i+1);
			}else{
				sum -= num.at(i+1);
			}
		}
		if(sum == 7) ans = s;
	}

	cout << num.at(0);
	for(int i=0; i<3; i++){
		if(ans.test(i)){
			cout << "+" << num.at(i+1);
		}else{
			cout << "-" << num.at(i+1);
		}
	}
	cout << "=7" << endl;

	return 0;
}


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

int main() {
	// your code goes here
	int i,j,n;
	cin >> n;
	int a[n+1];
	for(i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	int ans[n+1];
	ans[n] = a[n];
	for(i=n-1;i>=1;i--)
	{
		int cnt = 0;
		for(j=2*(i);j<=n;j+=i)
		{
			cnt += ans[j];
		}
		if(cnt%2==0&&a[i]==0)
		{
			ans[i] = 0;
		}
		else if(cnt%2==0&&a[i]==1)
		{
			ans[i] = 1;
		}
		else if(cnt%2==1&&a[i]==0)
		{
			ans[i] = 1;
		}
		else
		{
			ans[i] = 0;
		}
	}
	int m=0;
	for(i=1;i<=n;i++)
	{
		m+=ans[i];
	}
	cout << m << endl;
	for(i=1;i<=n;i++)
	{
		if(ans[i])
		{
			cout << i << " "; 
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  std::string s;
  std::map<char, bool> mp;

  cin >> s;

  for (int i = 0; i < s.size(); ++i) {
    mp[s[i]] = true;
  }

  if (s.size() == 26) {
    std::string min_str = "zzzzzzzzzzzzzzzzzzzzzzzzzzz";
    bool flag = false;

    for (int i = s.size() - 1; i >= 0; --i) {
      char c = s[i];
      std::map<char, bool> mp2;

      for (int j = 0; j < i; ++j) {
        mp2[s[j]] = true;
      }

      for (char c = 'a'; c <= 'z'; ++c) {
        if (mp2[c]) {
          continue;
        }
        std::string tmp_str = s.substr(0, i) + c;

        if (min_str > tmp_str && tmp_str > s) {
          min_str = tmp_str;
          flag = true;
        }
      }
    }

    if (flag) {
      cout << min_str << endl;
      return 0;
    }
  }
  else {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (!mp[c]) {
        cout << s << c << endl;
        return 0;
      }
    }
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#define ll long long
using  namespace std;
template <class T>
inline void read(T &x)
{
   x=0; char c=getchar(); int f=1;
   while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
   while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
set<int> s[N];
int n,m,tot;
int main()
{
	int x,y; read(n),read(m),read(tot);
	for(int i=1;i<=tot;i++) read(x),read(y),s[x].insert(y);
//	for(int i=1;i<=n;i++,puts(""))
//		for(int j=1;j<=m;j++) putchar(s[i].count(j)?'0':'1');
	
	for(int i=1;i<=n;i++) s[i].insert(m+1);
	int p=1,ans=n;
	for(int i=1;i<n;i++)
	{
		if(s[i+1].upper_bound(p)!=s[i+1].begin()) {ans=i; break;}
		if(!s[i+1].count(p+1)) p++;
//		printf("%d %d\n",i,p);
	}
	printf("%d",ans);
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    int mn = INT_MAX;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }
    for (int i = 0; i < n - 1; i++) {
        int sum = 0;
        for (int j = 0; j <= i; j++) {
            sum += a[j];
        }
        int sum2 = 0;
        for (int j = i + 1; j < n; j++) {
            sum2 += a[j];
        }
        mn = min(mn, abs(sum - sum2));
    }
    cout << mn << "\n";
}


Measured memory_bytes: 256
//changing a character
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,k;
	string s;
	cin>>n>>k>>s;
	s[k-1]+=32;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = list(input().rstrip())
S = deque(S)
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if not rev:
                S.append(c)
            else:
                S.appendleft(c)

print(''.join(S) if not rev else ''.join(S)[::-1])


Measured memory_bytes: 25888
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int N,K;
	cin>>N>>K;
	if(N%2==0){
		if(K<=N/2){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	else{
		if(K<=N/2+1){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,p,num,ans[N];
struct xx{
	int x,i;
}z[N];
bool cmp(xx a,xx b){
	return (a.x==b.x)?a.i<b.i:a.x>b.x;
}
signed main(){
	n=read();
	F(i,1,n){
		z[i].i=i;z[i].x=read();
	}
	sort(z+1,z+n+1,cmp);
	p=z[1].i;num=z[1].x;
	F(i,2,n){
		if (z[i].i<p){
			ans[p]=num-(i-1)*z[i].x;
			num-=ans[p];p=z[i].i;
		}
		num+=z[i].x;
	}
	ans[p]=num;
	F(i,1,n) wrn(ans[i]);
	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define F first
#define S second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
ll HRX=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 ll n;
 cin>>n;
 ll res=0;
 for(ll i=1;i<=n;i++)
 {
  if(i<=9)
    res++;
  else if(i>99 && i<1000)
    res++;
  else if(i>9999 && i<100000)
    res++;
 }
 cout<<res<<endl;
 return 0;
}


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

int main(){
  int a,b,c;
  int nokori, ans;
  
  cin >> a >> b >> c;
  
  nokori = a - b;
  ans = c - nokori;
  
  if(ans < 0)
    cout << 0 << endl;
  else
    cout << ans << endl;
}

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

typedef long long LL;

LL read(){LL x; scanf("%lld", &x); return x;}
void read(char *s){scanf("%s", s);}
void no(){printf("No"); exit(0);}

#define maxn 120
int a[maxn];
int main(){
	LL N = read(), x = read();
	for(int i = 0; i < N; i += 1) scanf("%d", a + i);
	sort(a, a + N);
	LL S = 0;
	for(int i = 0; i < N; i += 1){
		S += a[i];
		if(S > x){
			printf("%d", i);
			return 0;
		}
	}
	printf("%lld", S == x ? N : N - 1);
	
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int H, W, M;
    cin >> H >> W >> M;
    map<int, int> hbomb;
    map<int, int> wbomb;
    vector<pair<int, int>> bombs(M);
    for(int i=0; i<M; i++){
        int h, w;
        cin >> h >> w;
        hbomb[h-1]++;
        wbomb[w-1]++;
        bombs[i] = make_pair(h-1, w-1);
    }
    sort(bombs.begin(), bombs.end());

    vector<int> hmax;
    vector<int> wmax;
    int valmaxh = 0, valmaxw = 0;
    for(int i=0; i<H; i++){
        if(valmaxh < hbomb[i]){
            hmax.resize(1);
            hmax[0] = i;
            valmaxh = hbomb[i];
        }
        else if(valmaxh == hbomb[i]){
            hmax.push_back(i);
        }
    }
    for(int j=0; j<W; j++){
        if(valmaxw < wbomb[j]){
            wmax.resize(1);
            wmax[0] = j;
            valmaxw = wbomb[j];
        }
        else if(valmaxw == wbomb[j]){
            wmax.push_back(j);
        }
    }

    int cross = 1;
    #if PIGEON
    if(hmax.size() * wmax.size() > M){
        cross = 0;
    }
    else{
        for(int i=0; i<hmax.size(); i++){
            for(int j=0; j<wmax.size(); j++){
                if(!binary_search(bombs.begin(), bombs.end(), make_pair(hmax[i], wmax[j]))){
                    cross = 0;
                    cout << valmaxh + valmaxw - cross << endl;
                    return 0;
                }
            }
        }
    }
    #else
    sort(hmax.begin(), hmax.end());
    sort(wmax.begin(), wmax.end());
    int cnt = 0;
    for(int i=0; i<M; i++){
        if(binary_search(hmax.begin(), hmax.end(), bombs[i].first) && binary_search(wmax.begin(), wmax.end(), bombs[i].second)){
            cnt++;
        }
    }
    if(cnt != hmax.size() * wmax.size()){
        cross = 0;
    }
    #endif

    cout << valmaxh + valmaxw - cross << endl;

    return 0;
}

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N, A, B; cin >> N >> A >> B;

	ll res = 0LL;
	if (N == 1){
		if (A != B){
			res = 0LL;
		}else{
			res = 1LL;
		} // end if
	}else{
		if (A <= B){
			res = (B - A)*(N-2LL) + 1;
		}else{
			res = 0;
		} // end if
	} // end if
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]

x, y = map(int, input().split())
if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

ll heap[MAX_N];
void heapinit(){
    rep(i,0,MAX_N){
        heap[i]=-1;
    }
}

void pushHeap(ll val, ll len){
    ll i = len;
    heap[i]=val;
    while(i!=0){
        if( heap[i]>heap[(i-1)/2] ){
            swap(&heap[i],&heap[(i-1)/2]);
        }    
        i--;i/=2;
    }
}

void popHeap(ll *val, ll len){
    ll i=0;
    *val=heap[0]; heap[0]=-1;
    swap(&heap[0],&heap[len-1]);
    while(len-1>=i*2+1){
        if(i*2+2<=len && heap[i]< heap[i*2+2] && heap[i*2+1]<heap[i*2+2] ){
            swap(&heap[i],&heap[i*2+2]);
            i*=2;i+=2;
        }else{
            if(heap[i]<heap[i*2+1]){
                swap(&heap[i],&heap[i*2+1]);
                i*=2;i++;
            }else break;
        }
    }
}

int main(void){
    // char ;
    ll n,m,ans=0;
    scanf("%lld%lld",&n,&m);
    ll a[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
    }
    
    rep(i,0,n){
        pushHeap(a[i],i);
    }
    rep(i,0,m){
        ll val;
        popHeap(&val,n);
        val/=2;
        pushHeap(val,n-1);
    }
    rep(i,0,n){
        // printf("%lld ",heap[i]);
        ans+=heap[i];
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;

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

	bool check = false;

	for(int i=0;i<n/4+1;i++) {
		for(int j=0;j<n/7+1;j++) {
			if(i*4 + j*7 == n) check = true;
		}
	}

	if(check) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  ll q;
  cin >> q;
  rep(i, q) {
    ll a0, b0;
    cin >> a0 >> b0;
    ll a = min(a0, b0);
    ll b = max(a0, b0);
    if (a == b) {
      cout << 2 * a - 2 << endl;
    } else if (a + 1 == b) {
      cout << 2 * a - 2 << endl;
    } else {
      ll c = sqrt(a * b);
      if (c * c == a * b) c--;
      if (c * (c + 1) >= a * b) {
        cout << 2 * c - 2 << endl;
      } else {
        cout << 2 * c - 1 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w,a,b=map(int,input().split())

lst=[[""]*w for i in range(h)]
# print(lst)

l,r=0,a

for i in range(h):
    for j in range(w):
        if l<=j<r:
            if i<b:
                lst[i][j]="0"
            else:
                lst[i][j]="1"
        else:
            if i<b:
                lst[i][j]="1"
            else:
                lst[i][j]="0"

for i in range(h):
    print("".join(lst[i]))

Measured memory_bytes: 49264
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

using ll = long long int;
using vi = vector<ll>;
using vvi = vector<vi>;

ll n, m, v, p;
vi a(n);

bool func(ll x)
{
    vi b = a;
    b.erase(b.begin() + x);
    
    ll g = lower_bound(b.begin(), b.end(), a[x]+m+1) - b.begin();
    b.erase(min<ll>(g, b.size()-p+1) + b.begin(), b.end());
    reverse(b.begin(), b.end());
    
    if(a.size()-b.size()-1 >= p) return false;
    ll q = p - (a.size() - b.size());
    
    ll w = v - (a.size() - b.size());
    if(w <= 0) return true;
    
    //cout << "w = " << w << endl;
    
    vi sum(b.size()+1, 0);
    rep(i, b.size()) sum[i+1] = sum[i] + (a[x] + m - b[i]);
    
    /*
    cout << "b = ";
    rep(i, b.size()) cout << b[i] << ' ';
    cout << endl;
    cout << "sum = ";
    rep(i, b.size()+1) cout << sum[i] << ' ';
    cout << endl;
    */
    
    reps(i, b.size()-w, b.size()){
        //cout << "i = " << i << ", lhs = " << sum[i+1] << ", rhs = " << (i-(b.size()-w)+1)*m << endl;
        if(sum[i+1] < (i-(b.size()-w)+1)*m) return false;
    }
    
    return true;
}

void solve()
{
    cin >> n >> m >> v >> p;
    a.resize(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    
    if(func(0)){
        cout << n << endl;
        return;
    }
    
    ll l=0, r=n; // l=false, r=true
    while(r-l > 1){
        ll m = (r+l)/2;
        if(func(m)) r = m;
        else l = m;
    }
    
    cout << n-r << endl;
}

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


Measured memory_bytes: 2660
n = int(input())
lst = [int(i) for i in input().split()]
for i in range(n):
    s1=0
    for j in range(i):
        s1+=lst[j]
    s2=sum(lst)-s1
    if i==0:
        ans=abs(s1-s2)
    elif abs(s1-s2)<ans:
        ans=abs(s1-s2)
print(ans)

Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%d %d", $n, $l);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $s[$i]);
}
sort($s);
$ans = "";
for ($i = 0; $i < $n; $i++) {
    $ans = $ans.$s[$i];
}
echo $ans."\n";


Measured memory_bytes: 3832
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
A = list(map(int, input().split()))
Query = [int(input()) for _ in range(Q)]
INF = 10**14

E = [0]
O = [0]
e = 0
o = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        e += a
    else:
        o += a
    E.append(e)
    O.append(o)

S = [0]
s = 0
for a in reversed(A):
    s += a
    S.append(s)

for X in Query:
    ind = N
    if X > A[-1]:
        l = 0
    else:
        l = 0
        r = N+1
        while r-l > 1:
            m = (r+l)//2
            in_left = A[-m]
            in_right = A[-m+m//2-1]
            out_left = A[-m-1] if m < N else -INF
            out_right = A[-m+m//2] if m > 0 else INF
            if X <= out_left:
                l = m
            elif out_right <= X:
                r = m
            else:
                if abs(X-out_left) <= abs(in_right-X):
                    l = m
                elif abs(X-in_left) > abs(out_right - X):
                    r = m
                else:
                    l = m
                    break
    
    ans = S[l-l//2]
    if l%2 != (N-l)%2:
        ans += E[N-l]
    else:
        ans += O[N-l]
    
    print(ans)



Measured memory_bytes: 81388
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = array[0], b = array[1];
            int ans = Enumerable.Range(a, b - a + 1).Count(x => x.ToString() == new string(x.ToString().Reverse().ToArray()));
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 15428
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
int INF = 1LL << 60;

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


signed main(){
    int H,N;
    cin >> H >> N;
    
    vector<pair<int,int>> p(N);
    for(int i=0;i<N;i++){
        cin >> p[i].first >> p[i].second;
    }
    int dp[H+100000];
    for(int i = 0;i<H+100000;i++){
        dp[i] = INF;
    }
    
    dp[0] = 0;
    
    for (int i = 0; i <= H; ++i) {
        for (int j = 0; j < N; ++j) {
            dp[i+p[j].first] = min(dp[i]+p[j].second,dp[i+p[j].first]);
        }
    }
    
    int ans = INF;
    for(int i=H;i<=H+10000;i++){
        ans = min(ans,dp[i]);
    }
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int N, K;
int X[10000], Y[10000];

void beet() {
  cin >> K;
  vector< int > vs;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
    vs.push_back(Y[i]);
  }
  double sq3 = sqrt(3);
  vector< int > latte(N), malta(N);
  iota(begin(latte), end(latte), 0);
  iota(begin(malta), end(malta), 0);
  sort(begin(latte), end(latte), [&](int a, int b) {
    return X[a] - Y[a] / sq3 < X[b] - Y[b] / sq3;
  });
  sort(begin(malta), end(malta), [&](int a, int b) {
    return X[a] + Y[a] / sq3 < X[b] + Y[b] / sq3;
  });

  int need1 = N - K;
  sort(begin(vs), end(vs));
  vs.erase(unique(begin(vs), end(vs)), end(vs));
  double ret = 1e30;
  for(int y_0 : vs) {
    vector< pair< double, int > > hidari;
    vector< pair< double, int > > migi;
    for(auto &i : latte) {
      if(y_0 > Y[i]) {}
      else if(Y[i] == y_0) {
        hidari.emplace_back(X[i], i);
      } else {
        double dist = Y[i] - y_0;
        hidari.emplace_back(X[i] - dist / sq3, i);
      }
    }
    for(auto &i : malta) {
      if(y_0 > Y[i]) {}
      else if(Y[i] == y_0) {
        migi.emplace_back(X[i], i);
      } else {
        double dist = Y[i] - y_0;
        migi.emplace_back(X[i] + dist / sq3, i);
      }
    }

    vector< int > st(N), inner(N);
    int ptr = 0;
    double last = -1e9;
    int add = 0;
    for(int i = 0; i < hidari.size(); i++) {
      st[hidari[i].second] = true;
    }

    for(int i = 0; i < hidari.size(); i++) {

      while(ptr < migi.size() && add < need1) {
        if(st[migi[ptr].second]) {
          inner[migi[ptr].second] = true;
          last = migi[ptr].first;
          ++add;
        }
        ++ptr;
      }


      if(add >= need1) {
        ret = min(ret, last - hidari[i].first);
      }

      if(inner[hidari[i].second]) {
        inner[hidari[i].second] = false;
        --add;
      }
      st[hidari[i].second] = false;
    }
  }
  cout << fixed << setprecision(15) << ret * 3 << endl;
}

int main() {
  while(cin >> N, N) beet();
}


Measured memory_bytes: 3856
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    if P[i] == i + 1:
        P[i],P[i+1] = P[i+1],P[i]
        ans += 1
if P[-1] == N:
    ans += 1
print(ans)

Measured memory_bytes: 14008
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {
	string a;
	cin >> a;

	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'A'&&i!=a.size()-1) {
			if (a[i + 1] == 'C') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;


	return 0;
}

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

using namespace std;

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
		cout << "\n";
	}

	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}
void solve()
{
	int n;
	cin >> n;
	int x = ceil((float)n / 1000);

	cout << (x * 1000 - n);
}


Measured memory_bytes: 3812
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	
	double r;
	cin >> r;
	cout << r * 6.283185307 << '\n';
}

Measured memory_bytes: 3812
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int a = 0;
    for (int p = 0; p <= X; p++){
      for (int q = X; 0 <= q; q--){
        if ((p*2 + q*4 == Y) && (p+q == X)) {
          a++;
          break;
        }
      }
    }
    if (a == 0){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 35852
#include <stdio.h>
int main(void){
int a, b, c, d, flag = 0;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
if(a==1||a==4||a==7||a==9){
    if((b==1||b==4||b==7||b==9)&&(b!=a)){
        if((c==1||c==4||c==7||c==9)&&(c!=a)&&(c!=b)){
            if((d==1||d==4||d==7||d==9)&&(d!=a)&&(d!=b)&&(d!=c)){
                flag = 1;
            }
        }
    }
}
if(flag==1){
    printf("YES\n");
}else{
    printf("NO\n");
}
return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll n,x,t;
    cin>>n>>x>>t;
    ll d = n/x;
    if(n%x)
        d++;
    cout << d*t <<"\n";
}
int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	i64 a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
	
	i64 ans = b + std::min(a + b, c);
	if(a + b < c) ans++;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import copy
n = int(input())
a = [int(i) for i in input().split()]
b=a.copy()
s0p = a[0]
s0n = b[0]
countp = 0
countn = 0

if a.count(0)==n:
  print(2*n-1)
  exit()

if s0p<=0:
  s0p+=(abs(a[0])+1)
  countp+=(abs(a[0])+1)
  
if s0n>=0:
  s0n-=(abs(b[0])+1)
  countn+=(abs(b[0])+1)

for i in range(1,n):
  s1 = s0p+a[i]
  if s0p*s1>=0:
    if s1>0:
      a[i]-=(abs(s1)+1)
      countp+=(abs(s1)+1)
    elif s1<0:
      a[i]+=(abs(s1)+1)
      countp+=(abs(s1)+1)
    elif s1==0:
      if s0p>0:
        a[i]-=1
        countp+=1
      elif s0p<0:
        a[i]+=1
        countp+=1
  s0p += a[i]

for i in range(1,n):
  s1 = s0n+b[i]
  if s0n*s1>=0:
    if s1>0:
      b[i]-=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1<0:
      b[i]+=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1==0:
      if s0n>0:
        b[i]-=1
        countn+=1
      elif s0n<0:
        b[i]+=1
        countn+=1
  s0n += b[i]
  
print(countp if countp<=countn else(countn))







Measured memory_bytes: 15164
n = int(input())
A = list(map(int, input().split()))

c = 0

def dividable(A):
    for a in A:
        if a % 2 != 0:
            return False
    return True

def divide(A):
    return [a // 2 for a in A]

while dividable(A):
    A = divide(A)
    c += 1

print(c)

Measured memory_bytes: 3060
/* Longest Common Subsequence */

#include<stdio.h>
#include<string.h>

int lx, ly; /*lx is length of X. ly is length of Y. */
int c[1001][1001];

void LCS_Length(char X[], char Y[]);

int main(){
  char X[1001],Y[1001];
  int n,i,j,k;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",X);
    scanf("%s",Y);
    
    lx=strlen(X);
    ly=strlen(Y);

    LCS_Length(X,Y);

    printf("%d\n",c[lx][ly]);
  }
  return 0;
}

void LCS_Length(char X[], char Y[]){
  int m, n;
  int i,j;
  m=lx;
  n=ly;

  for(i=1;i<=m;i++){
    c[i][0]=0;
  }
  for(j=0;j<=n;j++){
    c[0][j]=0;
  }
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(X[i-1]==Y[j-1]){ /*X and Y use indent from 0*/
	c[i][j]=c[i-1][j-1]+1;
      }else if(c[i-1][j]>=c[i][j-1]){
	c[i][j]=c[i-1][j];
      }else{
	c[i][j]=c[i][j-1];
      }
    }
  }
}

Measured memory_bytes: 4328
use std::io; 

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let row: usize = s.trim().parse().unwrap_or(0);
    s.clear();
    let mut array = Vec::new();

    for _ in 0..row {
        io::stdin().read_line(&mut s).ok();
        let v: Vec<isize> = s.trim().split_whitespace()
        .map(|e| e.parse().unwrap_or(0)).collect();

        match v[0] {
            0 => {
                array.push(v[1]);
            },
            1 => {
                println!("{}", array[v[1] as usize]);
            },
            2 => {
                array.pop();
            },
            _ => println!("error 0 or 1 or 2"),
        }
        s.clear();
    }
}


Measured memory_bytes: 7084
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define L first
#define R second
typedef long long ll;

const int maxn=1e5+10;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    ll n, x;
    cin>>n>>x;
    cout<<3*(n-__gcd(n,x))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
int main() {
	int N, M, C;
	cin >> N >> M >> C;

	vector<int>vecb(M);
	rep(i, M) {
		cin >> vecb[i];
	}

	vector<vector<int>> veca(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> veca[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sex = 0;
		for (int j = 0; j < M; j++) {
			sex = veca[i][j] * vecb[j] + sex;
		}
		if (sex + C > 0) {
			ans++;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
	int n;
	ll d;
	cin >> n >> d;
	d *= d;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x * x + y * y <= d) cnt++;
	}
	cout << cnt;
	return 0;
}

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

int main() {
  string s;
  int n;
  cin >> s >> n;
  string ring[n];
  int i, j, k;
  for (i = 0; i < n; i++) {
    cin >> ring[i];
  }
  int count = 0;
  bool do_break = false;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 10; j++) {
      if (ring[i].at(j) == s.at(0)) {
        for (k = 0; k < s.length(); k++) {
          if (s.at(k) != ring[i].at((j + k) % 10)) {
            break;
          }
          if (k == s.length() - 1) {
            count++;
            do_break = true;
          }
        }
        if (do_break) {
          do_break = false;
          break;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll N,ans;
  cin >> N;
  if(N<10){
    ans = N;
  }else{
    if(N<100){
      ans = 9;
    }else{
      if(N<1000){
        ans = 9+N-99;
      }else{
        if(N<10000){
          ans = 909;
        }else{
          if(N<100000){
            ans = 909+N-9999;
          }else{
            ans = 90909;
          }
        }
      }
    }
  }
  cout << ans<< endl;
  return 0;
}

Measured memory_bytes: 256
using System; 
using System.Text; 
using System.Collections.Generic;
using System.Linq; 
using E = System.Linq.Enumerable; 

class Program { 
     static void Main(string[] args) {
     //入力を受け取る 
     var NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
     var N = NM[0];
     var M = NM[1];
     
     //電球の情報を初期化
     int[][] bulbs = new int[M][];
     for(int i = 0;i < M ;i++){
         var KS = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
         var K = KS[0];
         //Console.WriteLine(K);
         bulbs[i] = new int[K];
         for(int j = 0;j < K;j++){
             bulbs[i][j] = (int) Math.Pow(2,KS[j+1]-1);
         }
     }
     
     //スイッチが点く条件を設定
     var P = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
     //条件を満たす個数
     var res = 0;
     //スイッチのパターンに対して
     for(int i = 0;i < Math.Pow(2,N) ;i++){
         //Console.WriteLine("i:"+i);
         var ans = true;
         //電球が点くかどうか
         for(int j = 0;j < M ;j++){
             //繋がってるスイッチが押されてる個数
             var count = 0;
             for(int k = 0;k < bulbs[j].Length;k++){
                 //Console.WriteLine("i:"+i+"bulb:"+bulbs[j][k]);
                 if((i&bulbs[j][k]) != 0){
                     count++;
                 }
                 
             }
             
             if(count%2 != P[j]){
                 ans = false;
                 break;
             }
             
             
         }
         if(ans){
             //Console.WriteLine(i);
             res++;
         }
     
       }
      Console.WriteLine(res);
     }
     }


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(void){
    int N, M;
    int ans = 1;
    
    cin >> N >> M;
    
    for(int i = M / N; i >= 2; i--){
        if(M % i == 0){
            ans = i;
            break;
        }
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AGC013
{
    public class A
    {
        private int F(int[] A)
        {
            int result = 1;
            bool first = true;
            bool flag = true;
            bool up = true;
            int last = 0;
            foreach (var a in A)
            {
                if (first)
                {
                    first = false;
                }
                else if (flag)
                {
                    if (last < a)
                    {
                        up = true;
                        flag = false;
                    }
                    else if (last > a)
                    {
                        up = false;
                        flag = false;
                    }
                }
                else
                {
                    if (up && (last > a) || !up && (last < a))
                    {
                        result++;
                        flag = true;
                    }
                }
                last = a;
            }
            return result;
        }
        private void Run()
        {
            Console.ReadLine();
            var A = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            Console.WriteLine(F(A));
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new A().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 19680